1

I have a web based application with windows security popup displayed as soon the first web page starts loading and the page completes loading only after we provide login credentials.

I have written following script, but it is not going to next code line after selenium.open("/faces/Main"); and finally fails with default timeout error message.

Result console:

Timeout 30000ms

Selenium1 code:

package first;

import java.io.IOException;

import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;



public class Auth_assign {

private Selenium selenium;

   @BeforeClass
   public void setup() 
   {             
          selenium = new DefaultSelenium("localhost",4444, "*firefox C:/Program Files/FF 7.1/firefox.exe", "http://qa02.mydomain.com");
          selenium.start();
          selenium.windowMaximize();

   }

   @AfterClass(alwaysRun=true) 
   public void stopSelenium() {  
   //this.selenium.stop(); 
   } 




   @Test (description="Authentication pop-up")     
          public void Auth_popup() throws Exception
          {


          System.out.print("Unity page\n ");
          try
          {
          selenium.open("/faces/Main");
          Thread.sleep(10000);

          System.out.print("Window \n ");


          String[] dialog;

          dialog = new String[] { "Login_Dialog.exe","Authentication Required","test46#", "test123"};
          System.out.print( dialog);
          Runtime.getRuntime().exec(dialog);


          selenium.select("//select[@id='qryId1::criteriaItems::content']", "Customer Name");
          selenium.type("//input[@id='qryId1:criterionValue::content']", "Search Company");
          selenium.click("//a[@id='qryId1::search_icon']");
          selenium.waitForPageToLoad("3000");

          selenium.click("//a[@id='t1:0:gl1']");


          } catch (SeleniumException ex) {
        System.err.println(ex.getMessage());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }


   }      

Login.exe code

;~ ------------------------------------------------------------
;~ Login_dialog.au3
;~ To handle the Authentication Dialogbox
;~ Create By: Gaurang Shah
;~ Usage: Login_dialog.au3 "Dialog Title" "User Name" "Password"
;~ ------------------------------------------------------------
AutoItSetOption("WinTitleMatchMode","2")

if $CmdLine[0] < 3 then
msgbox(0,"Error","Supply all the Arguments, Dialog title User Name, Password")
Exit
EndIf

WinWait($CmdLine[1]) ; match the window with substring
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title
ControlSend($title,"","Edit2",$CmdLine[2]);Sets User Name
ControlSend($title,"","Edit3",$CmdLine[3]);Sets Password
ControlClick($title,"","OK");

3 Answers 3

1

You can provide credential in base url. For example if your base url is http://www.mysite.com/ then you can provide it as http://user:[email protected]/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks user861594 for your reply. I tried giving base url as test64#:test123:qa02.mydomain.com
0

You could pass the username and password in a Authorization header, this may help: How can I send HTTP Basic Authentication headers in Android?

2 Comments

Thanks user861594 for your reply. I tried giving base url as test64#:test123:qa02.mydomain.com When i run the script. I got following error. Please check FAILED CONFIGURATION: @BeforeClass setup java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107) at first.Yahoo_assign.setup(Yahoo_assign.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) SKIPPED: Auth_popup Authentication pop-up
You need to pass the username and password as an Authorization header, not in the url, try looking at this example: java.happycodings.com/Java_Servlets/code36.html.
0

Try calling your autoit script before security popup comes. Else you never get your control back. I mean before your main page selenium.open("/faces/Main");

1 Comment

Thanks thawa for your reply! When I try to call my script before selenium.open("faces/Main") I'm not getting Authentication pop-up and following error is shown at the end Timed out after 30000ms Please suggest.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.