我有简单的测试:
module.exports = {
'can view and click regions from dropdown': function(client) {
var home = client.page.home();
home.navigate().waitForElementVisible('body', 5000)
home.expect.element('@title').to.be.present;
home.expect.element('@title').text.to.contain('React Redux Example');
home.expect.element('@regionDropdown').to.be.present;
client.getText('.navbar-nav', function(result) {
console.log(result);
});
home.expect.element('@regionDropdown').text.to.contain('Explore');
home.moveToElement('@regionDropdown', 5, 5, function(response) {
home.expect.element('@popover').to.be.present;
home.moveToElement('@popover', 5, 5, function(response) {
home.expect.element('@popover').to.be.present;
});
client.expect.element('.navbar-brand').to.be.present;
client.moveToElement('.navbar-brand', 0, 0, function(response) {
home.waitForElementNotPresent('@popover', 1000);
});
});
client.end();
}
}
哪个传递了chrome就好了,但是在运行phantomjs 2.0时,它在navbar-nav li:first-child a
中找不到任何内容,更不用说整个.navbar-nav
了。它找到了元素,但没有测试。
思想?
我的配置:
{
"src_folders": ["tests/functional/specs"],
"page_objects_path": ["tests/functional/pages"],
"output_folder": "tests/functional/output",
"custom_commands_path": "tests/functional/commands",
"custom_assertions_path": "tests/functional/assertions",
"globals_path": "tests/functional/globals.js",
"selenium" : {
"start_process" : true,
"server_path" : "node_modules/selenium-server/lib/runner/selenium-server-standalone-2.48.2.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 5555,
"cli_args" : {
"webdriver.chrome.driver" : "node_modules/chromedriver/lib/chromedriver/chromedriver"
}
},
"test_settings" : {
"default" : {
"exclude": ["./pages", "./commands"],
"filter": "*.spec.js",
"launch_url" : "http://localhost",
"selenium_port" : 5555,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : true,
"path" : "tests/functional/screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"production" : {
"exclude": ["./pages", "./commands"],
"filter": "*.spec.js",
"launch_url" : "http://localhost",
"selenium_port" : 5555,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : true,
"path" : "tests/functional/screenshots"
},
"desiredCapabilities": {
"browserName" : "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"phantomjs.binary.path" : "/usr/local/phantomjs/bin/phantomjs"
}
},
...
答案 0 :(得分:2)
PhantomJS提供了与Chrome不同的默认用户代理。您的问题可能是您的服务器根据它看到的用户代理返回不同的数据。
在你的PhantomJS desiredCapabilities中,你可以尝试传入一个" phantomjs.page.settings.userAgent"设置与您的浏览器的用户代理设置相匹配,看看它是否有任何区别。
祝你好运!