【发布时间】:2019-10-07 04:28:15
【问题描述】:
我是自动化新手,我正在运行一个非常基本的测试,它运行良好,但最近它停止工作,我不断收到以下错误:
失败:脚本超时:11 秒内未收到结果
我查看了它并进行了一些基本调试,发现 Protractor 没有找到我所指的元素 (element(by.id('mat-input-0')) - 更多信息请参见 spec.js 代码文件。
我正在使用最新版本的 Protractor (5.4.2),以及 Jasmine 最新版本 (3.4.0)。我正在最新的 chrome 浏览器上进行测试。
我尝试了很多在线解决方案(例如使用 async/await,在配置文件中添加长 allScriptsTimeout 和 defaultTimeoutInterval(如下所示),使用不同的定位器调用元素(通过 xpath、id、tagName、 ...),尝试browser.waitForAngular(); 或browser.ignoreSynchronization = true,...)但没有奏效,所以我想知道是否有人对可能的解决方案有任何意见? (或者真正的问题是什么?)
元素 HTML
<input _ngcontent-mkt-c2="" class="mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-invalid ng-touched" formcontrolname="email" matinput="" name="email" placeholder="Email" required="" type="text" id="mat-input-0" aria-invalid="true" aria-required="true">
Spec.js:
describe('Login', function(){
it('test 1', async function(){
await browser.get('the STG URL im testing');
})
it('set username', async function(){
await element(by.id('mat-input-0')).sendKeys('root@user.com');
})
it('set password', async function(){
await element(by.id('mat-input-1')).sendKeys('1234');
})
})
Conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
allScriptsTimeout: 80000,
framework: 'jasmine',
specs: ['spec.js'],
SELENIUM_PROMISE_MANAGER: false,
jasmineNodeOpts: {
defaultTimeoutInterval: 50000
}
};
【问题讨论】:
-
browser.waitForAngular()不等同于browser.ignoreSynchronization你可能会想到browser.waitForAngularEnabled()。您可以发布您尝试定位的对象的 HTML 吗? -
@DublinDev 我猜
browser.waitForAngular()会和browser.waitForAngularEnabled(true)一样吗? - 如果我错了纠正我。这是我试图定位的字段的 HTML:<input _ngcontent-mkt-c2="" class="mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-invalid ng-touched" formcontrolname="email" matinput="" name="email" placeholder="Email" required="" type="text" id="mat-input-0" aria-invalid="true" aria-required="true"> -
我确实通过使用
browser.waitForAngularEnabled(false)解决了这个问题,但我读到不建议使用它,并且之后的测试会变得不稳定......所以我正在研究另一种解决方案......我想知道我如何知道我的页面上尚未稳定的内容? (它超过了Angular 7)。 @都柏林开发 -
waitForAngularEnabled(true)告诉 Protractor 你希望它等到页面上的所有 Angular 调用都完成并且页面在 every 操作之前稳定。 Mu 的理解是,如果设置了waitForAngular(),将在尝试任何交互之前调用。 -
您对禁用
waitForAngularEnabled的缺点是正确的。根据您的最后评论,您的问题似乎与量角器没有变得“稳定”有关。你能在 chrome 开发工具上打开控制台并运行以下命令getAllAngularTestabilities()。当您展开结果时,您可能会看到属性hasPendingMacrotasks: false和hasPendingMicrotasks: true。是这样吗?
标签: javascript jasmine protractor