我在Angular 1.6.3网站上使用了Protractor 4.0.14。连续两次相同的量角器测试,第二次失败
我执行两个相同的测试。第一个会成功,但不会是第二个。任何想法 ?
it('Should return a toast error on inferior amount', function() {
$$('#purposeList input.amount').first().clear().sendKeys('4999');
$$('button[type="submit"]').get(0).click();
expect($('div.toast.toast-error').isPresent()).toBe(true);
element.all(by.model('purpose.amount')).first().clear();
$$('button.toast-close-button').each(function (item) {
item.click();
});
expect($('button.toast-close-button').isPresent()).toBe(false);
});
it('Should return a toast error on inferior amount BIS', function() {
$$('#purposeList input.amount').first().clear().sendKeys('4999');
$$('button[type="submit"]').get(0).click();
expect($('div.toast.toast-error').isPresent()).toBe(true);
element.all(by.model('purpose.amount')).first().clear();
$$('button.toast-close-button').each(function (item) {
item.click();
});
expect($('button.toast-close-button').isPresent()).toBe(false);
});
该字段提供了错误的数量,所以当我提交时它会抛出一个toast错误。当我手动执行时,我得到吐司错误。使用量角器时,只有第一个相同的测试会通过。另一方面,它看起来像吐司永远不会很快启动或关闭。
我试过睡觉,忽略浏览器等待同步。我试图用处理错误敬酒的服务中的$ interval替换$ timeout(尽管可能存在其他$ timeout)。它没有改变任何东西。
它实际上是第一个想到的是失败,并没有从错误中没有实际的帮助,第二个它的,它只是一个预计的假,而不是真正:
Message:
Expected false to be true.
编辑:
所以@LostJon,通过处理每一个承诺,你的意思是这样的:
it('Should return a toast error on inferior than authorized purpose amount on step 1 BIS', function() {
$$('#purposeList input.amount').first().clear().then(function() {
$$('#purposeList input.amount').first().sendKeys('4999').then(function() {
$$('button[type="submit"]').get(0).click().then(function() {
expect($('div.toast.toast-error').isPresent()).toBe(true);
element.all(by.model('purpose.amount')).first().clear().then(function() {
$$('button.toast-close-button').each(function (item) {
item.click();
}).then(function() {
expect($('button.toast-close-button').isPresent()).toBe(false);
});
});
});
});
});
});
我试过了,结果相同。
编辑:
显然,这是一个ignoreSynchronization = TRUE,这是等待,而不是之前的内部。因为我还设置了browser.manage()。timeouts()。implicitlyWait(2000),所以没有同步,我们仍然在等待元素,但它不准确。
您能否在您的问题上添加其他信息? 就像第一次点击后发生的情况一样,html示例,它在哪里失败,在控制台中显示了什么错误等。 –
您可以首先确定哪两个失败?你可以把一个console.log来区分这两个 –