2017-01-23 5 views
0

私はナイトウォッチを使用してテストを作成し、次のようになります。私は、コマンドラインからこれを実行すると、それはそれを2回実行しますnightwatchを使用してe2eテストを実行するにはどうすればよいですか?

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

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

、(?):私が得た一般の.jsに

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

"負荷"と "もの"。これは出力です:

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

ウェブサイトの読み込み時間が1秒以内ですか?あなたが1000ms与えた通り – 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>" 
      } 
     } 
    } 
} 

このヘルプあなたはいますか?

関連する問題