# Testing Qt for WebAssembly Applications with Squish

Testing Qt for WebAssembly Applications with Squish

The Squish 6.6 release adds support for testing Qt for WebAssembly applications in Firefox and Chrome browsers. While we strive to make it as effortless as possible, the novel nature of this technology enforces some preparatory steps before WebAssembly content can be tested.

### Squish Built-in Hook

The shared libraries specification on the WebAssembly platform is not yet available, so the Qt library supports building static libraries only. Because of that, the Squish built-in hook needs to be integrated with the Application Under Test (AUT) in order to make it testable. You can achieve this by altering a small part of the AUT source code. First, add a call to the Squish::installBuiltinHook() API call directly after constructing the QApplication object:

#include <QApplication>
#ifdef HAVE_SQUISH
#include "qtbuiltinhook.h"
#endif

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
#ifdef HAVE_SQUISH
Squish::installBuiltinHook();
#endif
[...]
}


Second, add the following snippet to the end of the QMake project file (.pro) which defines the AUT:

[...]

!isEmpty(SQUISH_PREFIX) {
include(${SQUISH_PREFIX}/qtbuiltinhook.pri) }  In case the AUT contains any QtQuick content, the project file needs to enable linking the relevant Squish extensions, too: [...] !isEmpty(SQUISH_PREFIX) { SQUISH_WRAPPER_EXTENSIONS=squishqtquick squishqtquicktypes include(${SQUISH_PREFIX}/qtbuiltinhook.pri)
}


Finally, the QMake command used to configure the AUT building needs to specify the path to the Squish for Qt for WebAssembly package:

qmake -makefile <...> SQUISH_PREFIX=/path/to/squish/for/wasm_32

Squish for Qt for WebAssembly binary packages are available in our download area. The binary packages are compatible with the official Qt for WebAssembly binary distribution. Squish users who use a custom-built Qt for WebAssembly will need to build Squish against it using the Squish Embedded SDK source package.

In order to confirm whether the built-in hook was embedded correctly into the AUT, you can load it into a web browser and check the web console for Squish initialization messages:

The WebAssembly AUT prepared in such a manner should be ready for testing with Squish. Users of Squish for Web should notice an additional application context when opening a webpage with an embedded Qt AUT. By switching between the default web context and the Qt context (as described in our documentation), you can interact with both the WebAssembly content and surrounding HTML within a single test case.

### Testing Qt for WebAssembly without Squish for Web

If the tested web application consists entirely of Qt for WebAssembly widgets and does not require any browser interaction before it is shown (e.g., an HTML login form), then it should be possible to test such AUTs in supported desktop browsers using only Squish for Qt. In order to do so, the following preparatory steps must be taken:

1. Create an empty directory for a new browser profile.
2. Start the browser with the specified profile directory; you can specify the profile path using the --profile <path> flag for Firefox and --user-data-dir=<path> for Chrome. Install the appropriate browser extension in the new profile.
1. Install the native messaging host utility with your web browser. The lib/exec/nmshelper sub-directory of the Squish for Qt installation contains an installer script which registers the utility with the supported browsers.
2. Register the browser startup script as a Squish AUT using a built-in hook using the following commands:
# On UNIX systems
$bin/squishserver --config addAUT firefox /path/to$ bin/squishserver --config usesBuiltinHook firefox
# On Windows
> bin\squishserver --config addAUT firefox C:\path\to
> bin\squishserver --config usesBuiltinHook firefox
1. Create a new Qt test suite in the Squish IDE. Specify the browser as the AUT, and add the profile path and the AUT URL as arguments in the Test Suite Settings editor.

Now, Squish should be able to start the web browser and hook the WebAssembly Qt content within. You can record, replay and debug test cases just as you would with native Qt apps.

In order to make the tests easier to execute on different test systems, it may be advantageous to move the browser command into a wrapper script and register the script with squishserver instead. This way, each test system may use a different profile directory and other command line options.

### Troubleshooting

In case the web browser starts and the WebAssembly AUT is shown but fails to be recognized by Squish, please inspect the web console for any messages related to the Squish browser extension or native messaging host. You can find additional messages in the extension log.

In Firefox, the extension log is printed to the Browser Console, but in order to see all relevant messages, you may need to set the extensions.sdk.console.logLevel property to all on the about:config page and reload the AUT webpage with the browser console open.

In Chrome, the log is printed to a console which is a part of the background page for the extension. It is available by navigating to the Extensions page, enabling the developer mode and clicking the ‘background page’ link under the Squish extension.

If you are having any difficulties in starting WebAssembly applications with Squish, do not hesitate to contact our support team at support@froglogic.com. Please provide us with the web console log and the extension log to speed up troubleshooting.

### Conclusion

Despite the unusual nature of the Wasm platform, testing Qt/WebAssembly applications with Squish should not be any different from testing regular desktop Qt software – except the initial setup. If the AUT can be run as a native application, most tests should easily port between that version and its WebAssembly counterpart.

Testing WebAssembly applications is currently possible on a limited set of platforms and browsers. We are working on extending the set of supported browsers and platforms in future Squish releases. In case you are interested in testing Qt for WebAssembly applications in an unsupported web browser, on embedded or mobile platforms or environments like Electron, please contact us at support@froglogic.com.

Jaroslaw Kubik is a software developer who joined froglogic in 2016. Jaroslaw focuses on Qt-related features of the Squish GUI Tester, but occasionally dabbles with Java and Web technologies. He has also implemented toolkit-independent Squish features like Image-based search and the OCR integration.