我已经设置了一个网格环境,其中包含 4 个 Windows(IE8、IE9、IE10、IE11)VM 和一个带有 Chrome 和 Firefox 的 Ubuntu 12.04 VM。
Selenium Grid 和 Nodes 版本为 2.41.0 至于 ruby ,我正在使用 rvm,并使用 ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
我正在从 CentOs 虚拟机驱动测试。现在,当我尝试运行 IE8 测试时,我看到远程 Windows 机器启动了 IE8,但首先在浏览器中收到一条消息:
“这是 WebDriver 服务器的初始起始页。”
然后我得到另一个带有证书警告的页面。
证书错误:导航被阻止 错误: 本网站提供的安全证书不是由受信任的证书颁发机构颁发的。 安全证书问题可能表明有人企图欺骗您或拦截您发送到服务器的任何数据
我尝试对注册表进行破解,使 IE8 中的所有 4 个安全级别都相等,方法是 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
并均衡所有区域中 0x2500 位置的值。
但是好像不行。 这里有什么想法是 ruby/watir-webdriver 的工作解决方案
这是基类
#!/usr/bin/env ruby -W0
require "rubygems"
require "test/unit"
require 'rspec'
require 'watir-webdriver'
require 'headless'
require 'mysql2'
require_relative 'lib/basic_ops'
require_relative 'data/data'
require_relative 'main_class'
include GC
caps = Selenium::WebDriver::Remote::Capabilities.ie
caps.version = "8"
caps[:name] = "IE 8 on win7 , port 5560"
BROWSER = Watir::Browser.new(
:remote,
:url => "http://selenium-hub-vm:4444/wd/hub",
:desired_capabilities => caps)
URL = "https://target-vm/"
BROWSER.window.resize_to(950, 750)
BROWSER.window.move_to(0, 0)
main_class
所以 main_class.rb 是所有浏览器交互的地方。
最佳答案
您可以使用 javascript 来获得通过安全证书问题。我以前从未用 Ruby 编写过代码,因此语法可能有点偏差。
Python代码:
driver.get("javascript:document.getElementById('overridelink').click()")
Ruby 尝试:
driver.execute_script("document.getElementById('overridelink').click()")
driver.get "javascript:document.getElementById('overridelink').click()"
driver.get("javascript:document.getElementById('overridelink').click()");
您可能也希望在 if 语句中使用它来检查您需要的条件。
i.e. if "Certificate Error" in driver.find_element_by_xpath("//title").text
下面thread上有类似的解决办法如果我的建议都不起作用。
希望这对您有所帮助或接近您的需要。
关于ruby - 在 Selenium Grid 环境中使用 Watir-WebDriver 绕过证书错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26063212/