Protractor doesn't wait for Angular in the 1st

2019-06-02 10:59发布

I run a conf.js which launches 2 specs. Each of these specs has its own base URL. On the 2nd spec, the first test case fails because the test doesn't wait for Protractor. I get this error:

Expected 'Hello {{yourName}}!' to equal 'Hello Robert!'.

When I modify the conf.js in order to run only the spec which fails, everything runs alright. Protractor just doesn't wait for Angular in the 1st test case of the second spec.

Note: in my spec, I run this command, and I think it might be the one I need to modify in order to solve this issue:

beforeEach(function () {
    browser.get(browser.baseUrl);
});

Any idea on how I could fix the problem?

EDIT: as suggested, here is my conf:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['../specs/*.js'],
  baseUrl: 'https://angularjs.org',
  framework: 'jasmine'
};

1st test spec, which runs ok:

var donnees = require('../test-data/jeu-de-donnees-demo.js');
var using = require('jasmine-data-provider');

describe("Création d'utilisateur", function() {

beforeEach(function () {
    browser.get("http://localhost:3000");
});

using(donnees.prenoms, function (data, description) {
    it("Type de données : " + description, function () {
        var input_prenom = element(by.xpath("//input[@name='name']"));
        var input_nom = element(by.xpath("//input[@name='username']"));
        var bouton_valider = element(by.xpath("//button[contains(., 'Créer')]"));
        var nombre_lignes_avant = 0;
        input_prenom.sendKeys(data.prenom);
        input_nom.sendKeys(data.nom);
        var rows = element.all(by.xpath("//ul[contains(@class, 'users-list')]/li"));
        rows.count().then(function(count){
            nombre_lignes_avant = count;
            bouton_valider.click();
            var nombre_lignes_apres = nombre_lignes_avant + 1;
            var nouvelle_ligne = element(by.xpath("//ul[contains(@class, 'users-list')]/li[" + nombre_lignes_apres + "]"));
            expect(nouvelle_ligne.getText()).toEqual(data.prenom + " " + data.nom);
        });
    });
});
});

2nd one, in which the first test case fails:

var donnees = require('../test-data/jeu-de-donnees-demo.js');
var using = require('jasmine-data-provider');
var SiteAngularPageAccueil = require('../pages/site-angular-page-accueil.js');

describe("Suite de test de la feature qui dit bonjour", function() {

var pageAccueil = new SiteAngularPageAccueil();

beforeEach(function () {
    browser.get(browser.baseUrl);
});

using(donnees.prenoms, function (data, description) {
    it("Chaîne de type " + description, function () {
        testMessageSalutations(data.prenom);
    });
});

function testMessageSalutations(prenomSaisi, prenomVoulu){
    pageAccueil.entrerPrenom(prenomSaisi);
    var prenomAVerifier = (prenomVoulu ? prenomVoulu : prenomSaisi);
    expect(pageAccueil.message_salutations.getText()).toEqual('Hello ' + prenomAVerifier + '!');
}

});

The test data file...

'use strict';

module.exports = {
prenoms: {
    'ASCII': { prenom: 'aaa', nom: "eee" },
    'Caractères spéciaux français': { prenom: 'ààà', nom: "ééé" },
    'Caractères spéciaux arabes': { prenom: 'صباح الخير', nom: 'صباح الخير'},
    'Caractères spéciaux chinois': { prenom: '安', nom: '安' },
    'Script': { prenom: "<script type='text/javascript'>alert('Hoo la laaa');</script>", nom: "<img src='../' onerror=alert('Lolilolz')/>" }
},

}

And finally, the page object used in the 2nd spec:

var SiteAngularPageAccueil = function() {
    this.champ_nom = element(by.model('yourName'));
    this.message_salutations = element(by.xpath("//div[contains(@class, 'well')]//h1"));

    this.entrerPrenom = function(prenom) {
        this.champ_nom.sendKeys(prenom);
    };
};

module.exports = SiteAngularPageAccueil;

0条回答
登录 后发表回答