如何使用夜视仪运行e2e测试?

时间:2017-01-23 04:31:31

标签: reactjs nightwatch.js

我使用夜视仪创建了一个测试,看起来像这样:

var config = require('../nightwatch.conf.js');
pages=require('./pages/general.js');
module.exports = {
    'stuff': function () {
        pages.load();
    }
};

一般来说。我得到了:

var config = require('../../nightwatch.conf.js');

module.exports = {
    load: function () {
        return this.client
            .url('http://www.bing.com')
            .waitForElementVisible('body', 1000)
            .assert.title('Bing')
    }
};

当我从命令行运行它时,它运行两次(?),"加载"和"东西"。这是输出:

Running:  load                                                                
 √ Element <body> was visible after 163 milliseconds.                         
 √ Testing if the page title equals "Bing".                                   

OK. 2 assertions passed. (5.769s)                                             

[Test] Test Suite                                                             
=====================                                                         

Running:  stuff                                                               
 √ Element <body> was visible after 116 milliseconds.                         
 × Testing if the page title equals "Bing".  - expected "Bing" but got: ""    

如何解决填充部分中的问题?

1 个答案:

答案 0 :(得分:0)

要解决您的问题,我建议您将client对象传递给general模块。 然后注意nightwatch.json文件中的配置。

为了帮助您,我创建了一个完整的运行示例:

我创建了3个文件app.jsgeneral.jsnightwatch.json

enter image description here

当我运行测试时,结果是:

enter image description here

<强> app.js

var config = require('./nightwatch.json');
pages=require('./general.js');
module.exports = {
    'stuff': function (client){
    pages.load(client);
  }
};

<强> general.js

var config = require('./nightwatch.json');
module.exports = {
    load: function (client) {
        return client
            .url('http://www.bing.com')
            .waitForElementVisible('body', 1000)
            .assert.title('Bing')
    }
};

<强> nightwatch.json

{
    "src_folders": [
        "app.js"
    ],
    "live_output": true,
    "tests_output": "test/tests_output/",
    "detailed_output": true,
    "selenium": {
        "start_process": false,
        "host": "hub.browserstack.com",
        "port": 80
    },
    "test_workers": {
        "enabled": false,
        "workers": "auto"
    },
    "test_settings": {
        "chrome": {
            "selenium_port": 80,
            "selenium_host": "hub.browserstack.com",
            "silent": true,
            "desiredCapabilities": {
                "os": "Windows",
                "os_version": "10",
                "browserName": "chrome",
                "resolution": "1024x768",
                "javascriptEnabled": true,
                "acceptSslCerts": true,
                "browserstack.local": "true",
                "browserstack.video": "true",
                "browserstack.debug": "true",
                "browserstack.localIdentifier": "<yourLocalIdentifier>",
                "browserstack.user": "<yourYserName>",
                "browserstack.key": "<yourKey>"
            }
        }
    }
}

这对你有帮助吗?