我是NightWatch的新手,所以我遵循了一些教程,做了他们所说的一切,但是现在我得到了一个空白页,标题为“ data;”,而不是我想看到的页面“ https://www.ghandi.com.mx”。

这是json文件。似乎此问题与json配置有关。有什么帮助吗?非常感谢!

  {
    "src_folders" : ["tests"],
    "output_folder" : "reports",

    "selenium": {
      "start_process": true,
      "start_session" :  true,
      "server_path": "C:\\Users\\Esau Alvarez\\Desktop\\selenium-server-standalone-3.13.0.jar",
      "port": 4444,
      "cli_args": {
        "webdriver.chrome.driver": "C:\\Users\\Esau Alvarez\\Desktop\\chromedriver.exe"
      }
    },

    "test_settings" : {
      "default": {
        "launch_url": "https://www.gandhi.com.mx/",
        "screenshots": {
          "enabled": false
        },
        "desiredCapabilities": {
          "browserName": "chrome",
          "marionette": true
        }
      },

      "chrome" : {
        "desiredCapabilities": {
          "browserName": "chrome",
          "webdriver": {
            "server_path": "C:\\Users\\Esau Alvarez\\Desktop\\NightWatch\\chromedriver.exe"
          }
        }
      }
    }
  }


这是我的测试文件

module.exports = {
    "Test": function (browser) {
        browser
            .windowMaximize()
            .url("https://www.gandhi.com.mx/")
            .waitForElementVisible('body', 1000)
    }
}

最佳答案

在默认部分下,您必须配置Firefox。下载gecko驱动程序,并在cli_args下提供路径。
您应该从chrome所需的功能中删除服务器路径,如上所述。两次更改之后,nightwatch.json应该看起来像这样。


{
    "src_folders": ["tests"],
    "output_folder": "reports",

    "selenium": {
        "start_process": true,
        "start_session": true,
        "server_path": "C:\\Users\\Esau Alvarez\\Desktop\\selenium-server-standalone-3.13.0.jar",
        "port": 4444,
        "cli_args": {
            "webdriver.chrome.driver": "C:\\Users\\Esau Alvarez\\Desktop\\chromedriver.exe",
            "webdriver.gecko.driver": "Path to gecko driver.exe"
        }
    },

    "test_settings": {
        "default": {
            "launch_url": "https://www.gandhi.com.mx/",
            "screenshots": {
                "enabled": false
            },
            "desiredCapabilities": {
                "browserName": "firefox",
                "marionette": true
            }
        },

        "chrome": {
            "desiredCapabilities": {
                "browserName": "chrome"
            }
        }
    }
}

Also please increase the wait time to like 2000 or 3000 for the 'body' to be visible, just to be on the safe side.

module.exports = {
    "Test": function (browser) {
        browser
            .windowMaximize()
            .url("https://www.gandhi.com.mx/")
            .waitForElementVisible('body', 3000)
    }
}


因此,根据nightwatch json,默认执行应在firefox中进行。如果要在chrome上执行相同操作,则应使用chrome键盘或将chrome配置移动到默认部分。

关于javascript - 如何处理获取空白页而不是NightWatch中指定的URL?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51603986/

10-12 12:51