java - Firefox selenium webdriver 给出 "Insecure Connection"

标签 java maven selenium firefox

我创建了一个 Maven 项目,其中包含使用 Selenium Webdriver (java) 进行的 20 个测试。现在,当我想执行 Maven 项目时,有时会出现以下错误:

Mozilla error

这是由于每次测试都要登录造成的。因此,当我想运行 20 个测试时,有时会出现该错误,并且我无法继续测试,因此它在 Selenium Webdriver 中返回“失败的测试”。

有人知道如何解决这个问题吗? 我尝试将“Thread.sleep(30000);”在每次测试结束时给他们一些时间“不要显得像机器人”,但这不起作用......

非常感谢大家的帮助!

最佳答案

这是您问题的答案:

真正的问题:

  1. 您正在使用的 URL/连接(如果是 Not Secure)那么每当您通过 Mozilla Firefox 53.0 访问该 URL 时,Firefox 都会在地址栏中显示带有红色删除线的锁定图标。现在,当加载 URL 时,默认情况下光标将位于 Username 上。字段,将会弹出显示一条消息 This connection is not secure. Logins entered here could be compromised. Learn More像这样:

enter image description here

  • 现在,您的脚本通过 Selenium 在 Username 中输入用户名输入字段和 Not Secure弹出窗口覆盖 Password输入字段。
  • 接下来,如果您尝试调用 click()sendKeys()操作于Password输入字段 Not Secure弹出窗口收到点击并 Insecure password warning in Firefox 页面将在下一个选项卡中打开,Selenium 将其焦点转移到新选项卡。因此测试用例开始失败
  • enter image description here

    解决方案:

    在这些情况下,最好的解决方案是:

    1. 创建新的 Mozilla Firefox 配置文件。您会发现documentation here 。例如,我创建了一个名为 debanjan 的 Firefox 配置文件
    2. 配置 Firefox 配置文件 debanjan忽略所有 UntrustedCertificate问题。
    3. 重新运行您的测试脚本,没有任何问题。
    4. 以下是禁用 insecure_field_warning 的示例代码块:

      System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
      ProfilesIni profile = new ProfilesIni();
      FirefoxProfile testprofile = profile.getProfile("debanjan");
      testprofile.setAcceptUntrustedCertificates(true);
      testprofile.setAssumeUntrustedCertificateIssuer(true);
      testprofile.setPreference("security.insecure_field_warning.contextual.enabled", false);
      DesiredCapabilities dc = DesiredCapabilities.firefox();
      dc.setCapability(FirefoxDriver.PROFILE, testprofile);
      dc.setCapability("marionette", true);
      WebDriver driver =  new FirefoxDriver(dc);
      driver.manage().window().maximize();
      driver.navigate().to("http://demosite.center/wordpress/wp-login.php");
      

    如果这能回答您的问题,请告诉我。

    关于java - Firefox selenium webdriver 给出 "Insecure Connection",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44716870/

    相关文章:

    java - 从 String 的 getchars() 方法创建的 char 数组的最后一个字符更改为不同的字符

    java - pub cookie 身份验证后从 apache Web 服务器获取用户 ID

    java - Maven 外部依赖

    python - session 未创建异常 : Message: session not created from disconnected: unable to connect to renderer using Chromedriver on Linux Centos 7 Server

    java - 环绕字符中的字符

    Java进程CPU使用率增加

    java - 如何在 Spring 中创建多 Web 模块应用程序?

    java - Maven 拒绝 Java 主目录

    java - SendKeys 不会填充 Internet Explorer 中相应组件中的值,但在 Chrome 中却可以

    javascript - 在 Selenium + NodeJS 中以字符串形式获取下拉列表中当前选定的选项