量角器:异步超时,我认为是因为它找不到元素

Protractor: Async timing out, I think because it won't find an element

更新 #2:使用 $timeout 而不是 $interval 追溯到网络应用程序。这里解释下http://www.protractortest.org/#/timeouts等待页面同步

更新:所以我投入了 browser.ignoreSynchronization=true; browser.sleep(5000); 进行第二次测试,它成功了。不知道为什么……没有它,登录页面也能正常工作。现在最好的猜测是它是一个 运行 脚本,所以它永远不会完成同步????不太确定为什么它不同步。 所以或多或少,为什么我需要忽略同步知道该站点是 angular????????

我在 Jasmine 框架中使用 Protractor。
到目前为止,测试一直在进行。

我认为 Protractor 找不到我的元素,因此超时。
我不明白为什么它找不到我的元素,因为它在早期的测试中表现得非常好。

我的conf.js

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js'],
  allScriptsTimeout: 10000,
  onPrepare: function() {
    var SpecReporter = require('jasmine-spec-reporter');
    jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
  },
  jasmineNodeOpts: {
    showColors: true,
    isVerbose: true,
    realtimeFailure: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 10000,
    print: function() {}
  }
};

当前spec.js

describe('Authorizing newly created account', function() {
//This test works fine
it('should navigate back to login and login', function() {
    browser.get('website');
    element(by.model('$parent.username')).sendKeys('user');
    element(by.model('$parent.password')).sendKeys('test');
    element(by.buttonText('Login')).click();
}); 
//This one doesn't
it('should navigate to organizations', function() {

    //DOESN'T WORK
    var button = element(by.id('btn_organizations'));
    button.click();

});
});

我正在尝试获取 HTML 的片段 ("Organization" link)

<li ng-if="user.administrator || user.organizationAdministrator">
        <a ui-sref="organizations"  ng-click="closeNav()" id="btn_organizations">
                <span class="glyphicons glyphicons-tree-structure"></span>
                <span class="hidden-sm"><g:message code="organizations" /></span>
        </a>                        
</li>

我想既然组织有一个 ID 我可以用它来访问它,但 Protractor 似乎不喜欢它。

然后我收到错误

-Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL

我真的希望这不是我遗漏的东西。

尝试所有这些选项,它应该与回调一起工作:

  describe('Authorizing newly created account', function() {
 beforeEach(function(done) {
  done();
  }, 10000);   
//This test works fine
it('should navigate back to login and login', function() {
    browser.get('website');
    element(by.model('$parent.username')).sendKeys('user');
    element(by.model('$parent.password')).sendKeys('test');
    element(by.buttonText('Login')).click();
},10000); 
//This one doesn't
it('should navigate to organizations', function() {

    //DOESN'T WORK
    var button = element(by.id('btn_organizations'));
    button.click();

},10000);
},10000);

看看这个问题以及我是如何解决它的: