gpt4 book ai didi

node.js - nightwatch phantomjs 浏览器上的基本测试失败

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:33 25 4
gpt4 key购买 nike

我正在使用 selenium 服务器、node.js 上的 nightwatch 以及用于 selenium 的 phantomjs。我仅将 phantomjs 用于 headless 浏览器(使用它,selenium 在运行测试时不会以可视方式打开浏览器)。

当我使用 Firefox 作为浏览器时,我的基本测试通过,但当我使用 phantomjs 浏览器时失败。

我设置了基本的谷歌测试:

module.exports = {
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};

并设置 phantomjs 服务器。这是我的 nightwatch.json:

{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",

"selenium" : {
"start_process" : false,
"server_path" : "selenium-server-standalone-2.53.1.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 3001,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},

"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 3001,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled": true,
"acceptSslCerts": true,
"phantomjs.binary.path" : "phantomjs.exe"
}
}
}
}

当我将 browserName 设置为“firefox”时,测试通过,“好的。3 个断言已通过。”。但是当它是“phantomjs”时,1个通过,1个失败,执行期间1个错误:“TEST FAILURE:执行期间1个错误,1个断言失败,1个通过。(3.511s)”。

有错误:

  1. 等待元素出现 1000 毫秒时超时。 - 预期“可见”但得到:“未找到”

  2. 错误:无法定位元素:“input[type=text]”,使用:css 选择器

我手动启动服务器。

我使用最新版本的 phantomjs (2.1.1) 和 1.9.8 进行了测试

编辑:

Selenium 服务器在使用 phantomjs 时也会报告此错误:

WebElementLocator - _handleLocateCommand - 未找到元素:放弃。

最佳答案

我过去遇到过类似的事情,并观察到 ​​phantomjs 浏览器的默认大小非常小。您能否尝试调整浏览器大小并检查会发生什么情况。

如下所示,

module.exports = {
'演示测试 Google' : function (browser) {
浏览器
.url('http://www.google.com')
.resizeWindow(1000, 800);
.waitForElementVisible('body', 1000)
.setValue('输入[类型=文本]', '夜巡')
.waitForElementVisible('按钮[名称=btnG]', 1000)
.click('按钮[名称=btnG]')
.暂停(1000)
.assert.containsText('#main', '夜巡')
。结尾();
}
};

关于node.js - nightwatch phantomjs 浏览器上的基本测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38768387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com