我正在测试一个包含按标题过滤的产品的页面,并希望对测试的正确性设置一个期望:页面上的所有标题均包含单词“Juvederm”,而不是任何其他标题(“Emla”, «Coolsense» 等))。 并且只能通过第一个单词找到标题 - Juvederm(不是完整标题:JUVEDERM® ULTRA SMILE Europe;JUVEDERM® VOLBELLA WITH LIDOCAINE Europe)。
一种产品的 HTML 是:
<div class="col-xs-12 col-sm-6 col-md-4 block_history_" style="">
<section class="product">
<div class="product__holder">
<a href="https://www.cosmedicalsupplies.com/.html" class="product__category"></a>
<h2 class="product__title">
<a href="juvederm-hydrate.html">JUVEDERM® HYDRATE™ Europe</a>
</h2>
</div>
</section>
我的代码console.log(s)正确(如果页面上有“Juvederm” - 它显示“通过”,如果没有 - “未通过”:
it("products titles on the page should be Juvederm", () => {
let product = $$(".product > div > h2 > a");
browser.get(«…/advanced_search.html?keyword=juvederm");
product.each(function(element, index) {
element.getText().then(function(text) {
if(text.indexOf("JUVEDERM®") !== -1) {
console.log(«Passed»);
}else{
console.log("NOT PASSED");
}
});
});
});
但我自己决定我需要有一个期望。 如何/在哪里设置?期望是什么?当我在“If”中使用时
expect(order.product.getText()).toEqual(text);
我收到有关文本差异的错误:
JUVEDERM® HYDRATE™ Europe toEqual JUVEDERM®
当我在“If”中使用时
browser.wait(() => {
return EC.textToBePresentInElement(order.product);
}, 3000, "ASDF");
测试通过(但我需要看到“JUVEDERM®”,而不是“ASDF”)。
请多多指教。
最佳答案
您需要像下面这样更改期望语句。
expect(order.product.getText()).toContain('JUVEDERM®');
关于javascript - Protractor:如何正确设置每个函数的期望 getText()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54737595/