jeudi 17 septembre 2015

Protractor/js end-to-end test stops execution before Promise, using async commands

The sense of below scenario is cache (remember) values of given elements of the table record on the main page, and after click on this records assert that on the second page the same content is displayed.

I assume that test finishing before the callback returns.

Scenario:

var Q = require('q');

module.exports = {

    afterEach: function (browser, done) {
        browser.end(function() {
            done();
        });
    },

    'should display same data on second page as on first page': function (browser) {
        //Given
        var firstPage = bowser.pages.first()
        //When
        Q.all([
            firstPage.getTextPromise('@element1'),
            firstPage.getTextPromise('@element2'),
            firstPage.getTextPromise('@element3')]
        ).then( function(values) {
            users.click('@linkToSecondPage');
            //Then
            var secondPage = browser.page.secondPage();
            secondPage.expect.element('@dataElement1').text.to.equal(values[0]).before(5000);
            secondPage.expect.element('@dataElemnet2').contains.text(values[1]);
            secondPage.expect.element('@dataElement3').contains.text(values[2]);
        });
    } }

The getTextPromise command is defined by me in following way:

commands: [{
    getTextPromise: function(selector) {
        var self = this;
        return Q.Promise(function (resolve, reject) {
            self.getText(selector, function(result) {resolve(result.value); });
        });
    } }]

Tried as well to solve it with async.series library - I mean pack some steps into separate functions and run it sequentially but met problem that everything what is inside a function is local for this function so can't be invoked in the next one.

Aucun commentaire:

Enregistrer un commentaire