如何在nightwatch js中测试localhost url

时间:2016-05-06 23:37:12

标签: selenium webdriver nightwatch.js

我正在尝试针对本地项目运行UI回归测试。 我正在使用Browsersync运行该项目,最终在localhost:3000。

我已经尝试将url设置为我的分布式文件的目录,但这也不起作用。 Internet Explorer将打开,但无法连接到该页面。

这是我的nightwatch.json

{
  "src_folders" : ["nightwatch/tests"],
  "output_folder" : "nightwatch/reports",
  "custom_commands_path" : "nightwatch/commands",
  "custom_assertions_path" : "nightwatch/assertions",
  "page_objects_path" : "",
  "globals_path" : "",

  "selenium" : {
    "start_process" : true,
    "start_session" : true,
    "server_path" : "C:\\Selenium\\selenium-server-standalone-2.52.0.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.ie.driver" : "C:\\Selenium\\IEDriverServer.exe"
    }
  },

  "test_settings" : {

    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "on_failure" : false,
        "on_error" : false,
        "path" : "test/screenshots/"
      },
      "desiredCapabilities": {
        "browserName": "internet explorer",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },

    "chrome" : {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

这是我的测试

    module.exports = {
        before : function (browser) {
            browser.resizeWindow(1024, 800);
        },
        'OOBE Homepage': function(browser) {
            browser
            .url('http://localhost:3000/index.html')
            .waitForElementVisible('body', 5000)
            .compareScreenshot('desktop-index.png')
            .end();
        },
};

1 个答案:

答案 0 :(得分:2)

将launch_url更改为localhost:3000有效。

{
  "src_folders" : ["nightwatch/tests"],
  "output_folder" : "nightwatch/reports",
  "custom_commands_path" : "nightwatch/commands",
  "custom_assertions_path" : "nightwatch/assertions",
  "page_objects_path" : "",
  "globals_path" : "",

  "selenium" : {
    "start_process" : true,
    "start_session" : true,
    "server_path" : "C:\\Selenium\\selenium-server-standalone-2.52.0.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.ie.driver" : "C:\\Selenium\\IEDriverServer.exe"
    }
  },

  "test_settings" : {

    "default" : {
      "launch_url" : "http://localhost:3000",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "on_failure" : false,
        "on_error" : false,
        "path" : "test/screenshots/"
      },
      "desiredCapabilities": {
        "browserName": "internet explorer",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },

    "chrome" : {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}