【问题标题】:Protractor / Cucumber / RequireJs No element found using locator errorProtractor / Cucumber / RequireJs No element found using locator error
【发布时间】:2014-07-30 14:44:07
【问题描述】:

我有一个使用 requireJs 的 AngularJs 应用程序,因此它使用了引导应用程序的延迟方法。我正在尝试使用 Protractor 及其内置黄瓜支持的组合对此进行测试。

我可以从量角器 github 页面 here 运行黄瓜测试,并且测试通过了。当我尝试添加测试来测试页面上存在的 html 元素时,它会说“没有使用定位器找到元素”,我是否尝试通过绑定或 css 选择器来定位它。

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();
});

};

我想知道这是否是使用技术组合的问题,因为在我将黄瓜引入这种情况之前,我一直没有使用带量角器的延迟引导。有没有其他人有过一起使用 require/protractor/cucumber 的经验?

【问题讨论】:

    标签: angularjs requirejs protractor cucumberjs


    【解决方案1】:

    以下是有关该问题的一些信息Protractor Issue Page

    由于您使用的是 RequireJS,因此 Protractor 可能存在同步问题。

    试试

    browser.ignoreSynchronization = false;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多