Javascript 量角器中不循环的测试
我有一个测试,我正在努力解决。它需要单击每个结果,并验证初始结果与最终单个结果的价格和名称匹配。当前,我的代码将只单击第一个图像,但不会导航回结果页面以尝试下一个结果。我试图删除Javascript 量角器中不循环的测试,javascript,protractor,Javascript,Protractor,我有一个测试,我正在努力解决。它需要单击每个结果,并验证初始结果与最终单个结果的价格和名称匹配。当前,我的代码将只单击第一个图像,但不会导航回结果页面以尝试下一个结果。我试图删除first(),因为我的理解是该方法只接受第一个元素,而忽略其余元素。遗憾的是,这没有起作用。我错过了什么 tester.it('links to the correct product details page when a result is clicked', () => { const $offer =
first()
,因为我的理解是该方法只接受第一个元素,而忽略其余元素。遗憾的是,这没有起作用。我错过了什么
tester.it('links to the correct product details page when a result is clicked', () => {
const $offer = element.all(by.css('#main-results .catalog-offer')).first();
const offerResultsText = [];
let offerResultsPrice;
return Promise.all([
$offer.all(by.css('.offer-name .name-part')).map(($namePart) =>
$namePart.getText().then((partText) => offerResultsText.push(partText))
),
$offer
.element(by.css('.price'))
.getText()
.then((offerPrice) => (offerResultsPrice = offerPrice)),
])
.then($offer.element(by.tagName('a')).click)
.then(() =>
browser.wait(
protractor.ExpectedConditions.presenceOf(
element(by.css('#recently-purchased-details'))
),
5000
)
)
.then(() =>
expect(element(by.css('.details .subtotal > span')).getText()).to.eventually.equal(
offerResultsPrice
)
)
.then(() => {
return offerResultsText.map((sourceString) => {
console.log(sourceString);
return expect(
element(by.css('.details .setting .info')).getText()
).to.eventually.contains(sourceString);
});
});
});
发现我做错了什么。我需要删除
返回
,然后使用我们的内部方法在结果URL中循环。最后看起来像这样
expect(testerUtils.getPageId()).to.eventually.equal('Recently Purchased Engagement Ring Details');
testerUtils.go(testContext.url);
如果我是你,我会去掉所有出现的
Promise
,。然后等,并使用async/wait
谢谢Sergey!是的,不幸的是,因为我们实际上没有对Angular进行测试,所以我们必须使用测试仪模块作为垫片,这将不允许我们使用async Wait。@KevinLeroy您实际上不必使用Angular来使用async/Wait。通过执行以下操作可以关闭waitForAngular
位:browser.waitForAngularEnabled(false)
。如果你这么做了,应用程序是否使用angular就无关紧要了。在任何情况下,请帮你自己和所有需要维护此代码的人一个忙,并重构此代码。不要试图在这里刻薄,请将此视为建设性的批评,您上面粘贴的代码将是调试和维护的噩梦。让它对每个人都更容易,并以任何方式简化它。@Tehbeardone它实际上并没有太多的角度,因为它是用来运行量角器的垫片。它要求我们使用then()
。我很困惑。您说过,由于您不测试角度,因此必须使用测试模块垫片。我想说的是,以前从没听说过。我现在可以为一个非角度应用程序编写一些测试,使用普通的老式量角器,而不需要任何额外的插件或垫片。