如何在 nightwatch js 中测试本地主机 url

How do I test a localhost url in 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();
        },
};

将 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
      }
    }
  }
}