使用Selenium和AutoIt在加载网页时处理windows安全弹出窗口

使用Selenium和AutoIt在加载网页时处理windows安全弹出窗口,selenium,authentication,popup,selenium-rc,Selenium,Authentication,Popup,Selenium Rc,我有一个基于web的应用程序,当第一个网页开始加载并且只有在我们提供登录凭据后页面才完成加载时,就会显示windows安全弹出窗口 我已经编写了以下脚本,但它不会出现在selenium.open(“/faces/Main”)之后的下一个代码行中并最终失败,显示默认超时错误消息 结果控制台: Timeout 30000ms 硒M1代码: package first; import java.io.IOException; import com.thoughtworks.selenium.*;

我有一个基于web的应用程序,当第一个网页开始加载并且只有在我们提供登录凭据后页面才完成加载时,就会显示windows安全弹出窗口

我已经编写了以下脚本,但它不会出现在
selenium.open(“/faces/Main”)之后的下一个代码行中并最终失败,显示默认超时错误消息

结果控制台:

Timeout 30000ms
硒M1代码:

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");
先打包;
导入java.io.IOException;
导入com.thoughtworks.selenium。*;
导入org.testng.annotations.*;
导入静态org.testng.Assert.*;
公共类授权分配{
私人硒;
@课前
公共作废设置()
{             
selenium=new DefaultSelenium(“localhost”,4444,“*firefox C:/Program Files/FF 7.1/firefox.exe”,”http://qa02.mydomain.com");
selenium.start();
selenium.windowMaximize();
}
@后级(alwaysRun=true)
public void stopSelenium(){
//this.selenium.stop();
} 
@测试(description=“身份验证弹出窗口”)
public void Auth_popup()引发异常
{
System.out.print(“Unity page\n”);
尝试
{
selenium.open(“/faces/Main”);
睡眠(10000);
系统输出打印(“窗口”\n);
字符串[]对话框;
dialog=新字符串[]{“Login_dialog.exe”、“需要身份验证”、“test46#”、“test123”};
系统输出打印(对话框);
Runtime.getRuntime().exec(对话框);
selection(//选择[@id='qryId1::criteriaItems::content'],“客户名称”);
selenium.type(“//input[@id='qryId1:criterionValue::content']”,“搜索公司”);
selenium.click(“//a[@id='qryId1::search_icon']”);
selenium.waitForPageToLoad(“3000”);
selenium.click(“//a[@id='t1:0:gl1']”);
}捕获物(硒例外){
System.err.println(例如getMessage());
}捕获(例外e){
System.out.println(e.getMessage());
}
}      
Login.exe代码
;~ ------------------------------------------------------------
~Login_dialog.au3
;~以处理身份验证对话框
创建人:高朗·沙阿
~Usage:Login_dialog.au3“对话框标题”“用户名”“密码”
;~ ------------------------------------------------------------
自动选择(“WinTitleMatchMode”,“2”)
如果$CmdLine[0]<3,则
msgbox(0,“错误”,“提供所有参数、对话框标题、用户名、密码”)
出口
恩迪夫
WinWait($CmdLine[1]);将窗口与子字符串匹配
$title=wingtitle($CmdLine[1]);检索整个窗口标题
ControlSend($title,“,$Edit2,$CmdLine[2]);设置用户名
ControlSend($title,“,$Edit3,$CmdLine[3]);设置密码
ControlClick($title,“,“OK”);

您可以在授权标题中传递用户名和密码,这可能会有所帮助:

您可以在基本url中提供凭据。例如,如果您的基本url是 然后你可以提供它作为

在安全弹出窗口出现之前,尝试调用您的autoit脚本。否则您将永远无法恢复控制。我的意思是在您的主页面selenium.open(“/faces/main”)之前;

感谢user861594的回复。我尝试将基本url作为感谢user861594的回复。我尝试将基本url作为运行脚本时的url。我遇到以下错误。请检查
失败的配置:@BeforeClass setup java.lang.RuntimeException:无法启动Selenium会话:无法启动新浏览器会话:运行时出错首先在com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)启动浏览器。在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)启动Yahoo_assign.setup(Yahoo_assign.java:19)跳过:Auth_弹出身份验证弹出窗口
您需要将用户名和密码作为授权标题传递,而不是在url中,请尝试查看以下示例:。感谢thawa的回复!当我尝试在
selenium.open(“faces/Main”)之前调用脚本时
我没有收到身份验证弹出窗口,下面的错误显示在30000ms后超时
结尾,请建议。