2017-01-23 90 views
0

我使用nightwatch创建了一个测试,看起来像这样:如何使用守夜服务运行e2e测试?

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

一般的.js我:

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: ""  

如何解决东西部分的问题?

+0

该网站是在几秒钟之内加载的?因为你已经给1000毫秒 – Smriti

+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>" 
      } 
     } 
    } 
} 

这是否帮助你吗?

相关问题