rafazzevedo
rafazzevedo

Reputation: 410

Getting timeout when comparing GetAttribute on Protractor

I am quite new with protractor and javascript and I am having an issue when I compare a string with an attribute value. The message on console is: function timed out after 30000 milliseconds. In the Protractor API says that I don't need to create a function when expecting for a condition. When I create the function and print the element, I get the right value, but when I try to compare with expect I got 'TypeError: getAttribute is not thenable' Does anyone have any tip ?

Class Elements:

'use strict';

var protractor = require('protractor');
var element = protractor.element;
var by = protractor.by;

function Elements() {
    return {
        getDate: function() {
            return element(by.id('visit-date'));
        }
    };
}

module.exports = Elements;

Class Assertions:

'use strict';

var Elements = require('./elements');
var protractor = require('protractor');
var browser = protractor.browser;

function Assertions() {

    var elements = new Elements();

    return {
        assertDate: function() {
            var dateElement = elements.getDate();
            return expect(dateElement.getAttribute('value')).to.eventually.contain('2015-08-26');
        },
        assertUpdatedTexts: function() {
            return this.assertDate();
        }
    };
}

module.exports = Assertions;

Thank you !

Upvotes: 0

Views: 249

Answers (2)

rafazzevedo
rafazzevedo

Reputation: 410

for the problem, we have fixed changing the assertion date function:

 assertDate: function(datetime) {
            var dateElement = elements.getDate();
            var dateValue = dateElement.getAttribute('value');
            return expect(dateValue).to.eventually.contain(datetime.format('YYYY-MM-DD'));
        },

and passing the date parameter like proper dates not string:

 var VISIT_DATETIME = moment({y: 2016, M: 7, d: 21, h: 12, m: 20});
 var VISIT_DURATION = moment.duration({hours: 3, minutes: 20});

Thank you for the help anyway !

Upvotes: 0

Brine
Brine

Reputation: 3731

It looks like you're using Mocha as your test runner? Protractor hacks Jasmine to automatically handle promises, but not Mocha. So use either Jasmine or handle the promises with .then().

Upvotes: 0

Related Questions