0

I am trying to automate my test cases using selenium webdriver in java. It involves Basic Authentication Dialogs. For making IE, Chrome, FF Compatible using kind of same approach I have to use AutoIT I am done with IE and FF but for Chrome it is not working. I am using AutoIT Window Info tool for finding out Class and Control Name. But Chrome is pretty different in that case can anyone help?

Here is code for working IE and FF

 $classForBasicAuthenticationWindow = "[CLASS:#32770]"
 $username = "XXXXXX"
 $password = "XXXXXX"

 WinWait($classForBasicAuthenticationWindow,"",120)
 If WinExists($classForBasicAuthenticationWindow) Then
    WinActivate($classForBasicAuthenticationWindow)
    Send($username)
    Send("{TAB}")
    Send($password & "{Enter}")   
  EndIf

It is similar for FF, The above is for IE

For Chrome I have written this so far if you consider the window info tool you will understand that the popup is not a different window in case of chrome. So it become a bit complicated. Anyways here is what I have tried :

$classForBasicAuthenticationWindow = "[CLASS:Chrome_WidgetWin_1]"
$username = "XXXXX"
$password = "XXXXX"

WinWait($classForBasicAuthenticationWindow,"",120)
If WinExists($classForBasicAuthenticationWindow) Then
WinActivate($classForBasicAuthenticationWindow)
While 1
   $isAuthenticationRequiredVisible = ControlGetHandle($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]")
  If $isAuthenticationRequiredVisible <> "" Then 
     MsgBox($isAuthenticationRequiredVisible)
     ExitLoop
  EndIf
WEnd
ControlSend($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]", $username)
EndIf
Dhruvenkumar Shah
  • 520
  • 2
  • 10
  • 26

3 Answers3

2

Why are you not opening your URL as so (by passing the login credentials in the URL)

@driver.get "#{username}:#{password}@#{URL}"

an example

@driver.get "user:pass@my.domain.com"
Amey
  • 8,470
  • 9
  • 44
  • 63
  • 1
    Hi. I think it does not work in chrome that way after version 19. and for IE you need registry hack for which anyways you need some kind of autoIT mechanism. So for chrome I have to do something which is not using password and username in url. One more thing suppose for e.g. this method works then for the subsequent requests do I have to do the same procedure or I can use it directly later? – Dhruvenkumar Shah Nov 20 '12 at 15:15
1

ControlSend method takes window Title not the class of the window. So try giving window Title as it appears in Autoit Window Info Tool.

The code given below worked for me.

$titleForBasicAuthenticationWindow = "Window Title As Given in Window Info Tool"
$username = "XXXXX"
$password = "XXXXX"

WinWait($classForBasicAuthenticationWindow,"",120)
If WinExists($classForBasicAuthenticationWindow) Then
 WinActivate($classForBasicAuthenticationWindow)
 ControlSend($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]", $username)
EndIf
Abhishek_Mishra
  • 4,551
  • 4
  • 25
  • 38
  • sorry for the late reply. but In case of chrome it is totally different case, as if you open the window using web driver it would be different then normal opening of the window.. but let me check on that thanks. +1 for your help. – Dhruvenkumar Shah Nov 20 '12 at 15:14
  • 1
    You should check it first rather than saying that in chrome it is different case.I too had tested it on chrome by opening window using webdriver only. – Abhishek_Mishra Nov 20 '12 at 15:19
0

For chrome i tried everything, the best way to enter credentials in basic http authentication popup is through AutoIT. you just need to add sleep(25000) in the beginning of the script. make sure that chrome is able to open that popup within 25 sec. if not then increase the sleep time.

SujJi
  • 13
  • 1
  • 5