gpt4 book ai didi

angularjs - Protractor :异步超时,我认为是因为它找不到元素

转载 作者:行者123 更新时间:2023-11-28 20:14:23 26 4
gpt4 key购买 nike

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

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

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

我认为 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() {}
}
};

当前规范.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 片段(“组织”链接)

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

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

关于angularjs - Protractor :异步超时,我认为是因为它找不到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37446179/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com