我目前有一个Rails应用程序试图让无头的chrome工作进行测试.
水豚版本:2.15.1
Selenium Webdriver:3.11.0
使用下面的docker图片:https: //github.com/SeleniumHQ/docker-selenium**
如果没有无头选项,我会看到浏览器启动并且测试运行没有问题.但是,当我向功能添加无头参数时,测试始终失败,无法找到元素.当我看截图/ html时,我看到的都是这样的空白网页,PNG屏幕截图是一个完全空白的白色屏幕.
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>
Run Code Online (Sandbox Code Playgroud)
这是我用来设置驱动程序的selenium帮助文件.
Capybara.register_driver :remote_browser do |app|
selenium = ENV.fetch('SELENIUM_ADDR', 'selenium')
WebMock.disable_net_connect!(
:allow => [
'api.knapsackpro.com',
selenium,
Capybara.server_host,
],
)
capabilities = {
"browserName" => "chrome",
"goog:chromeOptions" => {
args: %w[headless disable-gpu window-size=1920,1080 no-sandbox]
}
}
Capybara::Selenium::Driver.new(app, browser: :remote, url: "http://#{selenium}:4444/wd/hub", desired_capabilities: capabilities)
end
Capybara.javascript_driver = :remote_browser
Capybara::Screenshot.register_driver(:remote_browser) do |driver, path|
driver.browser.save_screenshot(File.join('..', path))
end
Run Code Online (Sandbox Code Playgroud) 我已经看了一个小时了,似乎看不出什么毛病。
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("JSON", "hi");
String myString = jsonResponse.getString("JSON");
assertEquals("hi", myString);
Run Code Online (Sandbox Code Playgroud)
结果...(整个方法抛出Throwable)。我也尝试了try / catch。结果相同...。
java.lang.AssertionError:
Expected :hi
Actual :null
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的课程
public class ECUserTests(){
@org.junit.Test
public void testUserExists(){
try{
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("JSON", "Hello, World!");
String myString = jsonResponse.getString("JSON");
assertEquals("hi", myString);
}catch(JSONException e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)