0

I have an AngularJs application that uses requireJs and hence it uses the deferred method of bootstrapping the application. I am trying to test this using a combination of Protractor and its built in cucumber support.

I can run the cucumber tests from the protractor github pages here and the tests pass fine. When i try to add a test to test an html element that exists on the page it fails saying 'No element found using locator', wether I try to locate it by binding or css selector.

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

var expect = chai.expect;

module.exports = function() {

var ptor = protractor.getInstance();

this.Before(function(callback) {

    //Otherwise i get Error while waiting for Protractor to sync with the page error
    ptor.ignoreSynchronization = true;
    callback();
});

this.Given(/^I run Cucumber with Protractor$/, function(next) {
    next();
});

this.Given(/^I go on(?: the website)? "([^"]*)"$/, function(url, next) {
    ptor.driver.get('http://0.0.0.0:8000');
    next();
});

this.Then(/^it should still do normal tests$/, function(next) {
    expect(true).to.equal(true);
    next();
});

this.Then(/^it should expose the correct global variables$/, function(next) {
    expect(protractor).to.exist;
    expect(browser).to.exist;
    expect(by).to.exist;
    expect(element).to.exist;
    expect($).to.exist;
    next();
});

this.Then(/the title should equal "([^"]*)"$/, function(text, next) {
    expect(ptor.getTitle()).to.eventually.equal(text).and.notify(next); //passes

    //sleep here just to see the html is definately rendered
    ptor.sleep(2000);

    // when i add this it fails - No element found using locator
    expect(element(by.binding('title')).getText()).to.eventually.equal('Main');

    next();
});

};

I am wondering wether this is a problem using the combination of technologies as i have had no bother with using deferred bootstrap with protractor until i introduced cucumber to the situation. Has anyone else got experience of using require/protractor/cucumber together?

alfonsob
  • 635
  • 1
  • 6
  • 16

1 Answers1

0

Here is some information regarding that issue Protractor Issue Page

Since you are using RequireJS there might be sync issues with Protractor.

try

browser.ignoreSynchronization = false;
user3779502
  • 163
  • 11