Squish is primarily designed to support the automation of operations on web pages' DOM, DHTML, and HTML elements. But to completely test a web application, it is often necessary to automate operations on other kinds of component, and also on dialogs—this section shows the techniques used to perform such testing.
Many web applications require a login using the browser's native authentication dialog, or the acceptance of certificates as part of the startup process. Squish makes it is possible to automate logins and the acceptance of certificates as described below.
Squish provides a custom function that you can call from your test scripts to automate a login with the browser's native authentication dialog. The key to using it is to start the login process (typically by clicking a button or link), then wait for the login dialog to appear, and then enter the username and password. Here's an example snippet that shows how it might be done:
clickLink(":Login_A")
waitFor("isBrowserDialogOpen()")
automateLogin(tester_username, tester_password)
clickLink(":Login_A");
waitFor("isBrowserDialogOpen()");
automateLogin(tester_username, tester_password);
clickLink(":Login_A");
waitFor("isBrowserDialogOpen()");
automateLogin($tester_username, $tester_password);
invoke clickLink ":Login_A" invoke waitFor "invoke isBrowserDialogOpen" invoke automateLogin $tester_username $tester_password
The snippet assumes that tester_username and
tester_password are variables that hold the tester's
username and password.
Squish's automateLogin function automates
the native browser authentication dialog for any of Squish's supported
browsers, so you don't have to make any allowances for browser
differences yourself.
![]() | Mac OS X-specific |
|---|---|
On Mac OS X you must turn on Universal Access in the System Preferences
when you use the
|
Automating the acceptance of a certificate depends on which web browser is used. This section explains what needs to be done for each of Squish's supported web browsers to automate this process.
The only step necessary to automate accepting a certificate when running a test in Internet Explorer is to accept it once, permanently. This must be done manually. After this, Squish will tell Internet Explorer to use the accepted certificate on each test run, and no further manual intervention is required.
To accept a certificate in Firefox, you must add some code to your script that will automate the browser dialogs for accepting the certificate. In addition it is necessary to work around an issue in Firefox would make the test case hang. To do this, first a temporary site must be loaded, and then the real site can be loaded.
Here is an example that shows how to automate connecting to an HTTPS site and accepting the certificate.
# Workaround: Load a temporary page first
loadUrl("http://www.froglogic.com")
# Now load the real page
loadUrl("https://the.real.site.you.want.to.load")
if Browser.type() == Browser.Firefox:
# Accept the certificate
waitFor("isBrowserDialogOpen()")
nativeType("<Return>")
snooze(1)
# Accept the second certificate dialog
nativeType("<Left>")
nativeType("<Return>")
waitFor("!isBrowserDialogOpen()")
rehook()
// Workaround: Load a temporary page first
loadUrl("http://www.froglogic.com");
// Now load the real page
loadUrl("https://the.real.site.you.want.to.load");
if (Browser.type() == Browser.Firefox) {
// Accept the certificate
waitFor("isBrowserDialogOpen()");
nativeType("<Return>");
snooze(1);
// Accept the second certificate dialog
nativeType("<Left>");
nativeType("<Return>");
waitFor("!isBrowserDialogOpen()");
rehook();
}
# Workaround: Load a temporary page first
loadUrl("http://www.froglogic.com");
# Now load the real page
loadUrl("https://the.real.site.you.want.to.load");
if (Browser.type() == Browser.Firefox) {
# Accept the certificate
waitFor("isBrowserDialogOpen()");
nativeType("<Return>");
snooze(1);
# Accept the second certificate dialog
nativeType("<Left>");
nativeType("<Return>");
waitFor("!isBrowserDialogOpen()");
rehook();
}
# Workaround: Load a temporary page first
loadUrl "http://www.froglogic.com"
# Now load the real page
loadUrl "https://the.real.site.you.want.to.load"
if {[[invoke Browser type] == Browser.Firefox]} {
# Accept the certificate
waitFor "[isBrowserDialogOpen]"
invoke nativeType "<Return>"
snooze 1
# Accept the second certificate dialog
invoke nativeType "<Left>"
invoke nativeType "<Return>"
waitFor "![isBrowserDialogOpen]"
rehook
}
Loading the temporary page is just an unfortunate—but hardly
noticable—necessity. Once the page has loaded, Firefox uses two
dialogs to complete the acceptance of a certificate, so we must
interact with both of them to complete the acceptance. We use the nativeType function to simulate the keyboard
interaction, where normally we'd use the type function. Also, after interacting with the
dialogs we must call the rehook function to
make Squish do some reloading and reinitialization to account for the
fact that the certificate has now been accepted and that as a result,
the web page is in a different state.
The only step necessary to automate accepting a certificate when running a test in Safari is to accept it once, permanently. This must be done manually: First, open the page with the certificate in Safari, then choose to view the details of the certificate in the sheet that pops up, then check the checkbox that tells Safari to always trust the certificate on reconnects. After this, Squish will tell Safari to use the accepted certificate on each test run, and no further manual intervention is required.
Squish for Web includes support for testing Java applets embedded in the web browser. This works because Squish for Web includes the necessary functionality from the Squish for Java edition, and means that Web testers can test web pages that include applets that have Java GUIs.
To test a Java applet that is embedded in a web page, simply record the test as normal—Squish for Web will handle all the web page interaction, and under the hood the functionality from the Squish for Java edition will be used when necessary for recording (and later playback) of any interactions with Java applets.
See Tutorial: Starting to Test Java™ AWT/Swing Applications (Chapter 5) for an introduction to Java GUI testing.
It is also possible to test java applets stand-alone as described in the Testing Java Applets (Section 15.3.5) section.
Squish supports automating interactions and testing non-HTML/DOM elements, that is, native objects, which are embedded in a web page. This is done at a fairly abstract level, which means that mouse and text input can be recorded and replayed. In addition it is possible to inspect embedded native objects with the Spy tool and to insert verifications for these native objects. All of a native object's public properties can be accessed in test scripts.