Nightwatch测试通过了chrome,但没有通过phantomjs



我有一个简单的测试:

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"
      }
    },
    ...

PhantomJS提供了与Chrome不同的默认用户代理。您的问题可能是服务器根据其看到的用户代理返回不同的数据。

在您的PhantomJS desiredCabilities中,您可以尝试传递一个与浏览器的用户代理设置匹配的"PhantomJS.page.settings.userAgent"设置,看看它是否有什么不同。

点击此处查看更多详细信息:https://stackoverflow.com/a/33618363/3043369

祝你好运!

最新更新