Firefox selenium webdriver提供“不安全连接”

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

Mozilla错误

这是因为每次测试都要登录。 因此,当我想运行20个测试时,有时会出现错误而我无法继续测试,因此它会在Selenium Webdriver中返回“Failed test”。

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

非常感谢你的帮助!

以下是您的问题的答案:

真实问题:

  1. 如果它不安全,您使用的URL /连接,那么无论何时通过Mozilla Firefox 53.0访问URL,Firefox都会在地址栏中显示带有红色透视红色删除线图标的锁定图标。 现在,当URL被加载时,默认情况下,光标将位于“ Username字段上,弹出窗口将显示一条消息This connection is not secure. Logins entered here could be compromised. Learn More This connection is not secure. Logins entered here could be compromised. Learn More This connection is not secure. Logins entered here could be compromised. Learn More如下:

在此处输入图像描述

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

在此处输入图像描述

解:

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

  1. 创建一个新的Mozilla Firefox配置文件。 你会在这里找到文档 。 例如,我创建了一个名为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"); 

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