【问题标题】:Setting profile/capabilities for chrome and ie8 through selenium通过 selenium 为 chrome 和 ie8 设置配置文件/功能
【发布时间】:2015-04-21 11:27:40
【问题描述】:

我正在对aws.amazon.com 进行自动化测试,以检查我使用aws cli 创建的资源是否使用selenium webdriver 创建成功。由于该网站脱离了我的公司网络,要访问该网站,我需要在点击该网站的 url 之前以模式弹出窗口提供域用户/密码。

我不确定,但解决此问题的方法是通过代码在浏览器设置中设置配置文件/功能。在点击网址之前。 我在Firefox中实现了如下

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=");

如何在 chrome 和 ie8 中做同样的事情?

我经历了this,但无法理解任何东西。还有.xpi.crx 文件与所有这些有什么关系?

这是 chrome 的弹出图像

这是 IE8 的弹出图像

【问题讨论】:

  • 没有。 @LittlePanda,selenium 将为我登录。
  • 没有我的完整代码:点击主页 url -> 通过提供用户/密码登录到 aws 控制台 -> 单击一个对象 -> 导航到其他页面 -> 拍摄快照 -> 关闭浏览器。所有这些都发生在所有浏览器上。
  • 问题出在哪里?
  • 问题出在浏览器启动时,浏览器要求输入用户名和密码,因为该站点在我的本地网络之外,提供域用户密码后,测试可以继续,所以我想要的是离开手动提供用户名和密码的限制。
  • 弹出窗口是 Windows Http 身份验证还是 Javascript 模式弹出窗口?

标签: google-chrome firefox selenium-webdriver internet-explorer-8


【解决方案1】:

弹出窗口是 Windows Http 身份验证弹出窗口,无法使用 Selenium Webdriver 处理。您将不得不使用 Robot Class AutoIT 来处理它。

1.使用机器人类:

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。使用 AutoIT:

此链接提供了有关如何将 AutoIT 与 Selenium 一起使用的详细信息:http://www.toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/

这是你必须做的:

下载/安装 AutoIT
您将能够使用 AutoIT SciTe Editor 创建 .au3 脚本 编译 .au3 脚本会给你一个 .exe 文件 然后你可以使用

从你的 Selenium 脚本中调用 .exe 文件
Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");

您可以使用 AutoIT Window Info (x86) 或 (x64) 获取窗口的属性。例如,窗口的标题/状态栏。

AutoIT 还具有 Au3 Recorder,以便您记录与远程桌面相关的操作。

以下是自动进行 Http 身份验证的示例脚本:

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

3.使用 AutoITx4Java:

检查这个库 AutoITx4Java - https://code.google.com/p/autoitx4java/

  1. 下载 Jacob, AutoIT(参考以上链接)
  2. 将 jacob.jar 和 autoitx4java.jar 添加到您的库路径中。
  3. 将 jacob-1.15-M4-x64.dll 文件放在您的库路径中。

示例代码

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));

【讨论】:

    猜你喜欢
    • 2020-06-14
    • 2022-10-14
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    相关资源
    最近更新 更多