Sometimes authentication is necessary before a test case can be executed. While HtmlUnit based tests can easily enter and confirm authentication requests, most browser based tests, cannot workaround the dialog. This is a browser security measure to prevent automated data capture and/or data entering. WebDriver for Firefox delivers a solution for that problem, but IE and Chrome rely on a manual interaction with the browser before the test automation can run.
The following steps describe a solution for the authentication problem and how to run a script test case as WebDriver based test. The key to this solution is the usage of Sikuli, an image based testing tool that directly interacts with the screen to find the right elements by using the screen.
Or in other words, the test automation controls the browser, not the operating system, while Sikuli controls the display of the operating system and uses the keyboard and mouse to control any program.
- Download Sikuli tool for your platform (http://sikuli.org)
- Extract the zip file
- Add the path to Sikuli lib directory to your environment settings
- Add sikuli-script.jar to your project
- Implement a Java class as shown below
- Take the necessary screenshots of the elements to use
public class TfoobarIE extends AbstractWebDriverScriptTestCase
* Constructor starts internet explorer
super(new InternetExplorerDriver(), “http://xlt.xceptance.com”);
* Main test method solves authentication problem and executes xlt script developer script
public void test() throws Throwable
// create Sikuli screen object
Screen s = new Screen();
// open page with xlt
// wait 5 seconds for the image with the username input field
// type username "demo" into the input field
// type password into the password field
// click ok button
// execute xlt script developer script
XlteniumScriptInterpreter interpreter = new XlteniumScriptInterpreter(getWebDriver());
Do not forget to make the appropriate screenshots of the buttons and input fields (see code) and of course, adjust the path and login data. Have fun and watch the magic happening. For more information how Sikuli works, please visit sikuli.org.