2017-06-20 10 views
0

私はキュウリと分度器を使用して動作テストを作成しています。私のシナリオとすべてのステップは合格しますが、最後にタイムアウトエラーが表示されます。最初のステップでホームページがロードされ、後でステップ定義ファイルに記述されているステップは実行されません。ページが読み込まれたら、タブをクリックします。私はステップ定義ファイルでこれらのステップを述べました。しかし、これらのステップは実行されず、コンソールに渡されたすべてのステップが表示されます。私は、このエラーメッセージキュウリ+分度器 - ステップ実行中のタイムアウトエラー

enter image description here

ある参照https://semaphoreci.com/community/tutorials/getting-started-with-protractor-and-cucumber

ために、このリンクをたどっ以下のサンプルコードを見つけてください。

//sample.feature 
Feature: The Dashboard has 2 tabs, Statistics and Results 

Scenario: I want to have 2 tabs with Displayed text "Statistics" and "Results" on the homepage 

Given I go to Dashboard homepage 
And I click on the "#/results" 
Then the Results page is displayed 
And I click on the "#/Statistics" tab 
Then the Statistics page is displayed 

//menu.steps.js 
var chai = require('chai'); 
var chaiAsPromised = require('chai-as-promised'); 

chai.use(chaiAsPromised); 
var expect = chai.expect; 

module.exports = function() { 
    this.Given(/^I go to Dashboard homepage$/, function() { 
    browser.get('http://localhost:8100/#/'); 
    browser.waitForAngular(); 
    }); 

    this.Then(/^I click on the "([^"]*)"$/,function(arg1){ 
    element(by.css('[href="#/results"]')).click();  
    }); 

    this.Then(/^the results page is displayed$/,() => { 
    browser.get('http://localhost:8100/#/results'); 
}); 
    this.When(/^I click on the "([^"]*)" tab$/, function(arg1) { 
    element(by.css('[href="#/statistics"]')).click();  
    }); 


    this.Then(/^the statistics page is displayed$/, () =>{   
    browser.get('http://localhost:8100/#/statistics'); 
    }); 

//cucumber.conf.js 
exports.config = { 
    framework: 'custom', // set to "custom" instead of cucumber. 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
    specs: ['test/e2e/cucumber/*.feature'], 
    capabilities: { 
    'browserName': 'firefox', 

}, 
baseUrl: 'http://localhost:8100/#/', 


    // cucumber command line options 
    cucumberOpts: { 
    require: ['test/e2e/cucumber/*.steps.js'], // require step definition files before executing features 
    tags: [],      // <string[]> (expression) only execute the features or scenarios with tags matching the expression 
    strict: true,     // <boolean> fail if there are any undefined or pending steps 
    format: ["pretty"],   // <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable) 
    dryRun: false,     // <boolean> invoke formatters without executing steps 
    compiler: []     // <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable) 
    }, 

onPrepare: function() { 
    browser.manage().window().maximize(); // maximize the browser before executing the feature files 
    }, 

    resultJsonOutputFile: './test/e2e/results.json' 
} 

答えて

1

あなたがCucumberJSを使用している場合は、コールバックまたは約束を使用するように選択することができます。あなたのコードでは、あなたはそのうちの1つを使っていませんでした。以下に、コールバックの約束をどのように使用できるかの手順の例を示します。

あなたは2つの解決策の一つは、あなたのテストがまだ失敗する可能性が実装している場合ということに注意して、それは代わりにコールバックするためのソリューションのテスト実装を行うことがより多くを持っている/

// With promises 
 
module.exports = function() { 
 
    this.Given(/^I go to Dashboard homepage$/, function() { 
 
    browser.get('http://localhost:8100/#/'); 
 
    return browser.waitForAngular(); 
 
    }); 
 

 
    this.Then(/^I click on the "([^"]*)"$/, function(arg1) { 
 
    return element(by.css('[href="#/results"]')).click(); 
 
    }); 
 

 
    this.Then(/^the results page is displayed$/,() => { 
 
    return browser.get('http://localhost:8100/#/results'); 
 
    }); 
 
    this.When(/^I click on the "([^"]*)" tab$/, function(arg1) { 
 
    return element(by.css('[href="#/statistics"]')).click(); 
 
    }); 
 

 
    this.Then(/^the statistics page is displayed$/,() => { 
 
    return browser.get('http://localhost:8100/#/statistics'); 
 
    }); 
 
} 
 

 
// With callbacks 
 
module.exports = function() { 
 
    this.Given(/^I go to Dashboard homepage$/, function(done) { 
 
    browser.get('http://localhost:8100/#/'); 
 
    browser.waitForAngular().then(done); 
 
    }); 
 

 
    this.Then(/^I click on the "([^"]*)"$/, function(arg1, done) { 
 
    element(by.css('[href="#/results"]')).click().then(done); 
 
    }); 
 

 
    this.Then(/^the results page is displayed$/, (done) => { 
 
    browser.get('http://localhost:8100/#/results').then(done); 
 
    }); 
 
    this.When(/^I click on the "([^"]*)" tab$/, function(arg1, done) { 
 
    element(by.css('[href="#/statistics"]')).click().then(done); 
 
    }); 
 

 
    this.Then(/^the statistics page is displayed$/, (done) => { 
 
    browser.get('http://localhost:8100/#/statistics').then(done); 
 
    }); 
 
}
を約束

+0

Hey !!約束をもって - 私はTimedエラーを出力します。「関数は、5000ミリ秒後にタイムアウトし、コールバックを受け取ると、私は 'TypeError:プロパティがnotify 'notifyのプロパティを読み取ることができません」というメッセージを返します。 、 – Mythri

+0

' 5000ミリ秒 'デフォルトでは「5000ミリ秒」のタイムアウトになっていますので、これを修正するには[this](https://github.com/cucumber/cucumber-js/blob/1.x/docs/support_files/timeouts.md)をお読みください。 ご希望の場合 – wswebcreation

+0

タイムアウトは最初のステップ 'this.Given(/ ^ダッシュボードのホームページ$ /、{timeout:60 * 1000}、function(){ return browser.get( 'http:// localhost:8100 /#/ '); }); 'と同じ方法で2番目の手順でタイムアウトを追加しましたが、起動時に上記の画像に示すようにタイムアウトエラーが表示されませんでした – Mythri

関連する問題