Selenium
Selenium is a portable software testing framework for web applications. Selenium runs on a variety of browsers (FireFox, Internet Explorer, Safari) on a variety of platforms (Windows, Linux, Macintosh). For more information on Selenium, please visit online Selenium documentation
All Selenium configurations can be made using the twist.properties file. The exceptions to this are the -log and -debug.
Supported Browsers
| Browser | Value |
|---|---|
| Firefox | *firefox |
| Internet Explorer | *iexplore |
| IEHTA | *iehta |
| Chrome | *chrome |
Twist Selenium
During test automation, flaky tests cause failure notifications that are not helpful and cause one to miss an actual failure condition. Unfortunately, a myriad of factors can make a test flaky. Some of these factors include undetermined delays during page transitions and heavy difficult-to-maintain test scripts. Such flaky tests would render automating the testing of AJAX applications nearly impossible.
Twist provides a wrapper to the Selenium API and adds further functionalities to create TwistSelenium. TwistSelenium API is essentially the Selenium API overridden to achieve implicit wait states during page transitions and AJAX requests, to ensure that a page is loaded and that there are no active web page requests pending.
TwistSelenium exposes the underlying Selenium through TwistSelenium#getUnderlyingSelenium();
TwistSelenium and Implicit Waits (for Proxy Injection Mode)
With TwistSelenium, all actions will wait implicitly when required in Proxy Injection mode and the TwistSelenium#startImplicitWait() is employed. The TwistSelenium driver makes it easier to test AJAX applications. It accomplishes this by removing the need for the 'waitFor...' API's. If your application uses AJAX, the TwistSelenium driver will automatically wait for asynchronous AJAX calls to complete. This makes Selenium tests simpler to write, improves the robustness of the Selenium code, and makes the tests more readable by eliminating the verbosity introduced by the wait statements.
There are cases when having implicit waits might not work well with certain applications, or users would like to turn them off explicitly. For those cases, you need to use these APIs.
- TwistSelenium#stopImplicitWait() - Works only with Proxy Injection mode - Once this is done, the user is required to insert the wait statements wherever required.
- TwistSelenium#startImplicitWait() - Works only with Proxy Injection mode - Once this is done, TwistSelenium handles all the implicit wait statements implicitly and ignores the wait statements added by the user.
Here are a few cases that require you to use the above mentioned APIs in Proxy Injection mode:
- Anchor tag or Form action that is bound to a javaScript function that does not change the current document in any way during a Selenium action (like click for example).
- Any HTML form element other than the anchor element (Ex: Button, image) that is bound to a javascript function that changes the current document on a Selenium action (like click for example).
Additionally, the following APIs can be used in Proxy Injection mode
- waitForAjaxRequests(String timeOut)- This method implicitly waits for the AJAX request(s) to complete. This method can be used in place of waitForCondition(String script, String timeout) to handle AJAX requests. This method does away with the JavaScript required to evaluate the condition.
- setWaitUntilPresentTimeout(String waitUntilPresentTimeout) - This is to reset the timeout for TwistSelenium driver which is by default set to 5 seconds.
Various modes of Selenium and TwistSelenium
Selenium specific modes
| Mode | Description | Application | Configurations in twist.properties |
|---|---|---|---|
| Non PI mode - Single window | In this non proxy-injection mode the application under test and Selenium test scripts would share the same browser window but will be loaded in separate frames. | This mode might be used when the application to test is more or less frame-free and requires no cross-domain testing. |
|
| Non PI Mode – Multi-window | In this kind of non proxy-injection mode the application under test and Selenium test scripts will be loaded in separate browser windows. | This mode might be used when the application to test is frame-heavy and requires no cross-domain testing. |
|
| PI Mode | In the proxy injection mode the Selenium test scripts are injected into every request (including AJAX requests) of the application under test. Certain requests like, requests for images, CSS will be excluded from the injection. | This mode might be used when the application requires cross-domain testing. This might not produce desirable results, as in specific cases, the Selenium scripts might be injected when not required (like for complex JSONs with HTML snippets) or omitted when needed (like when Javascripts generate DHTML). |
|
TwistSelenium specific modes
| Mode | Description | Application | Configurations in twist.properties |
|---|---|---|---|
| PI Mode with Implicit wait | Behaves like the PI mode but more to it, additionally (link to TwistSelenium and Proxy Injection Mode on Twist Help) | Same as PI mode, makes it easier to test AJAX applications. (left to user discretion) |
|
| PI Mode (with Explicit Wait) | Same as PI mode | Same as PI mode (left to user discretion) | Same as PI mode |