I am trying to automate a webpage using Single Sign-On. When you try to access the web page it redirects you to different page of Identity Provider, where it asks you for Username and Password inside HTTP Basic Auth popup. After successful authentication, it will redirect you back to originally requested page. Now I am trying to automate this using selenium web driver version 2.45.0. I am first switching to the alert box and then using Robot and Clipboard to do Ctrl+c and Ctrl+v the credentials. The test case works fine on my laptop, where Browser pops up, credentials are keyed in and final page appears after authentication.
When I am trying to run the same code on a linux host command line using Maven after setting DISPLAY=:99 environment variable (headless mode), it is getting stuck. The screenshot statements put to capture the state are displaying blank window. Any idea what can go wrong?
Relevant code snippet:
Alert alert = driver.switchTo().alert();
alert.sendKeys(username);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
StringSelection pass = new StringSelection(pwd);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(pass, null);
if (System.getProperty("os.name").startsWith("Mac OS")) {
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_META);
} else {
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
}
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("/tmp/screenshot2.png"));
alert.accept();