0

I am automating a test on aws.amazon.com to check whether the resources that i created using aws cli were successfully created or not using selenium webdriver. As the site falls out of my company network, to access the site i need to provide domain user/password in modal pop up that comes before hitting the url for the site.

i am not sure , but solution to this problem is to set profile/capability in the browser settings through the code. before hitting the url. i have achieved that in firefox as follows

FirefoxProfile profile = new FirefoxProfile();  
                profile.addExtension(new File(Constants.FIREFOX_ADDON_PATH));
                profile.setPreference("extensions.enabledAddons", "FireXPath%40pierre.tholence.com:0.9.7.1,proxyauth%40lammersoft.com:0.1.2,%7B972ce4c6-7e08-4474-a285-3208198ce6fd%7D:37.0.1");
                profile.setPreference("extensions.proxyauth.authtoken","c3ViaGFtdDpub3YwNDIwMTQ=");

How to do the same in chrome and ie8 ?

i went through this but not able to comprehend anything.Also what does .xpi and .crx file has to do with all of this ?

This is pop up image for chrome

This is pop up image for IE8

This is pop up image for IE8

8
  • No. @LittlePanda, selenium will login for me. Apr 21, 2015 at 11:59
  • no my complete code does : hit home url - > login to aws console by giving user/pass - > click on a object -> nasvigate to othe page - > take snapshot -> close browser. All of this is happening for all the browser. Apr 21, 2015 at 12:05
  • And where is the issue? Apr 21, 2015 at 12:08
  • issue is in when the browser starts , browser asks for username and password as the site is outside my local network, after providing domain user passwd, the test can proceed, so what i want is to get away with this limitation of providing user name and passwd manually. Apr 21, 2015 at 12:10
  • Is the popup a windows Http Authentication or is it a Javascript modal popup? Apr 21, 2015 at 12:11

1 Answer 1

0

The popup is a Windows Http Authentication popup and cannot be handled by using Selenium Webdriver. You will have to use either Robot Class or AutoIT to handle it.

1. Using Robot Class:

Alert authenticationWindow = driver.switchTo().alert();
// Type the username/email.
authenticationWindow.sendKeys("<username/email address>");
// Shift cursor focus to password input text field.
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_TAB);
// Type the password in password field. [ Selenium does not know at this point that the cursor focus is shifted, so calling Alert class instance sendKeys() will cause password to be typed in username field. So, we are copying the password first to windows clipboard and then pasting it directly into the password field using  Robot class instance ]
StringSelection stringSelection = new StringSelection("<user password>");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection,null); robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);

// Accept the authentication window.
robot.keyPress(KeyEvent.VK_ENTER);

2. Using AutoIT:

This link provides good information on how to use AutoIT alongwith Selenium: http://www.toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/

Here is what you have to do:

Download/install AutoIT
You will be able to create .au3 scripts using AutoIT SciTe Editor Compiling the .au3 script will give you a .exe file Then you can invoke the .exe file from your Selenium script using

Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");

You can get the properties of a window using the AutoIT Window Info (x86) or (x64). Example, title / status bar of a window.

AutoIT also has Au3 Recorder so that you can record your actions that are related to the remote desktop.

Below is a sample script that automates Http authentication:

WinWaitActive("Web page title","","10")
If WinExists("Web page title") Then
Send("userid{TAB}")
Send("password{Enter}")
EndIf

3. Using AutoITx4Java:

Check this library AutoITx4Java - https://code.google.com/p/autoitx4java/

  1. Download Jacob, AutoIT (refer the above link)
  2. Add jacob.jar and autoitx4java.jar to your library path.
  3. Place the jacob-1.15-M4-x64.dll file in your library path.

Sample Code

File file = new File("lib", "jacob-1.15-M4-x64.dll"); //path to the jacob dll
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());

AutoItX x = new AutoItX();
String notepad = "Untitled - Notepad";
String testString = "this is a test.";
x.run("notepad.exe");
x.winActivate(notepad);
x.winWaitActive(notepad);
x.send(testString);
Assert.assertTrue(x.winExists(notepad, testString));
x.winClose(notepad, testString);
x.winWaitActive("Notepad");
x.send("{ALT}n");
Assert.assertFalse(x.winExists(notepad, testString));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.