2017-06-20 1 views
0

J'utilise concombre et rapporteur pour écrire des tests comportementaux. Mes scénarios et toutes les étapes vont passer mais à la fin il montrera une erreur de délai. La page d'accueil sera chargée pour la première étape et plus tard, elle n'effectuera aucune des étapes décrites dans le fichier de définition des étapes. Une fois la page chargée, il faut cliquer sur les onglets. J'ai mentionné ces étapes dans le fichier de définition d'étape. Mais ces étapes ne sont pas exécutées et il montrera toutes les étapes passées dans la console. Je suivais ce lien pour référence https://semaphoreci.com/community/tutorials/getting-started-with-protractor-and-cucumberConcombre + Protractor - erreur expirée lors de l'exécution des étapes

Ceci est le message d'erreur

enter image description here

S'il vous plaît trouver le code exemple ci-dessous.

//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' 
} 

Répondre

1

Si vous utilisez CucumberJS, vous pouvez choisir d'utiliser ou callbackspromesses. Dans votre code, vous n'avez pas utilisé l'un d'entre eux. Ci-dessous, vous trouverez un exemple de vos étapes pour savoir comment utiliser les promesses, les rappels.

Soyez conscient du fait que si vous mettre en œuvre l'une des 2 solutions, vos tests pourrait encore échouer, mais qui a plus à voir avec la mise en œuvre de test au lieu de la solution pour les callbacks/promet

// 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 !! Avec des promesses - j'ai une erreur Timed out 'la fonction a expiré après 5000 millisecondes' et avec des callbacks je reçois' TypeError: Impossible de lire la propriété 'notify' d'undefined ' – Mythri

+0

La raison pour laquelle vous obtenez l'erreur' 5000 milliseconds' est que CucumberJS est par défaut à un délai de '5000 millisecondes', veuillez lire [this] (https://github.com/cucumber/cucumber-js/blob/1.x/docs/support_files/timeouts.md) pour résoudre ce problème. Espérons que cela fonctionne – wswebcreation

+0

Le délai d'expiration a fonctionné pour la première étape 'this.Given (/^Je vais à la page d'accueil Dashboard $ /, {timeout: 60 * 1000}, function() { return browser.get ('http: // localhost: 8100/#/'); }); 'et pour la deuxième étape de la même façon j'ai ajouté le timeout mais il a échoué montrant une erreur expiré comme le montre l'image ci-dessus au début – Mythri