【问题标题】:How do I get Nightwatch to show Chai assertions in the reporter?我如何让 Nightwatch 在记者中显示 Chai 断言?
【发布时间】:2021-07-13 16:34:51
【问题描述】:

我正在使用 Nightwatch JS v0.9.16 在我的本地主机上运行 selenium / chai 测试。所有断言都适用于守夜人,但我无法让 chai 断言显示在记者中。

此问题已在此处讨论:https://github.com/nightwatchjs/nightwatch/issues/601 但是它已关闭但没有解决方案......有人可以让它工作吗?

这是我的测试:

var assert = require('chai').assert;

module.exports = {
  'pressing the "Servers" tab should change the URL to #servers' : function (client) {
    const pages = client.page,
          home_page = pages.home(),
          servers_page = pages.servers();

    home_page.navigate();
    servers_page.expect.element('body').to.be.present.before(1000);
    client.pause(1000);
    servers_page.click('@nav');
    servers_page.expect.element('@servers_div').to.be.present.before(1000);
    client.url(function(response){
        var currentUrl = response.value.replace(client.launch_url,"");
        console.log("url is ",response.value);

        //***CHAI ASSERTION doesn't get shown on reporter:***
        assert(currentUrl.indexOf('#servers')!=-1);

        client.end();
    });

  }
};

此测试通过时的屏幕截图显示了除 chai 之外的所有断言:

失败时会显示AssertionError: Unspecified AssertionError:

这是我的测试设置 (nightwatch.json)

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "page_objects_path" : "./config/pages/",
  "globals_path" : "./config/globals.js",

  "selenium" : {
    "start_process" : false,
    "server_path" : "./libs/selenium-server-standalone-2-53-1.jar",
    "log_path" : "./logs/",
    "port" : 4444
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost:8081",
      "selenium_port"  : 9515,
      "selenium_host"  : "localhost",
      "default_path_prefix" : "",
      "screenshots" : {
        "enabled" : true,
        "path" : "./screens/",
        "on_failure": true
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions" : {
          "args" : ["--no-sandbox"]
        },
        "acceptSslCerts": true
      }
    }
  }
}

版本:

"selenium-webdriver": "^3.0.1",
"nightwatch": "^0.9.8",
"chromedriver": "^2.25.2",
"chai": "latest"

【问题讨论】:

  • 真的希望有人对此也有解决方案。

标签: chai nightwatch.js


【解决方案1】:

根据文档,assert() 将消息作为第二个参数 (http://www.chaijs.com/api/assert/),您尝试过吗?如果有,是否显示了消息?

或者,您是否尝试过更简单的测试(一个失败,一个没有),例如:assert.isOk(false) & assert.isOk(true)

最后,您是否尝试在 client.url() 的回调之外运行您的 chai 断言?

我不熟悉 Nightwatch,但我会尝试过。

【讨论】:

  • 嘿尼古拉斯!谢谢,我试试看!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-08
  • 2020-10-27
  • 1970-01-01
  • 2018-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多