javascript - 如何处理获取空白页面而不是 NightWatch 中指定的 url?

标签 javascript web nightwatch.js

我是 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/

相关文章:

java - 尝试在 JSP 中访问 "response"时出现 NullPointerException

selenium - 拒绝连接! Selenium 服务器启动了吗?

javascript - jQuery 适用于多个按钮和 div

javascript - 解构作为 Firefox 中的第二个参数

javascript - Internet Explorer Web 浏览器中不显示内容

java - JSP 和外部 javascript 文件之间的交互

javascript - 如何在 Nightwatch js 中将变量值从一个函数传递到另一个函数

javascript - 无法编译此 Typescript

javascript - CDATA 下带有 Jquery 的 HTML 按钮

Javascript:替换 a 但不是 ab 中的 a