我是 Protractor E2E 测试的新手。在我正在测试的网页上,有两个类名为name-part. 我需要一种方法将两者的值连接到一个元素结果中。这是代码的布局方式。<div class="offer-name"> 1.01 ct. Center Diamond <span class="name-part">Monique Lhuillier Timeless Rollover Halo Diamond Engagement Ring</span> <span class="name-part">in 18k Rose Gold</span></div>我需要将两个跨度连接成一个断言。Monique Lhuillier Timeless Rollover Halo Diamond Engagement Ring in 18k Rose Gold这是我的代码:tester.it('Clicking the defined number of products should bring up Product Details page every time', (testContext) => {catalogResults().totalResults().then((totalCount) => { for (let i = 0; i < totalCount; i++) { let testLink = element.all(by.css('.catalog-offer a')).get(i); const offerResultsName = element.all(by.css('.offer-name')).get(i).getText(); const offerResultsPrice = element.all(by.css('.offer-details-wrapper .price-display')).get(i).getText(); testerUtils.performActionAndWait(testLink.click); element(by.css('.image-and-details .name-start')).getText().then(displayName => { expect(offerResultsName).to.eventually.include(displayName, 'Display name does not match with results name.') console.log(displayName); }) element(by.css('.details .subtotal > span')).getText().then(displayPrice => { expect(offerResultsPrice).to.eventually.equal(displayPrice, 'Display price does not match with results price.'); console.log(displayPrice); }); expect(testerUtils.getPageId()).to.eventually.equal('Recently Purchased Engagement Ring Details'); testerUtils.go(testContext.url); }});});
1 回答
守着星空守着你
TA贡献1799条经验 获得超8个赞
这应该工作(可能需要一些改变)
let elementsWithTheSameClass = element.all(by.css('.someClass'))
let arrayOfStrings = await elementsWithTheSameClass.getText() // ["Monique Lhuillier Timeless Rollover Halo Diamond Engagement Ring", "in 18k Rose Gold"]
let endResult = arrayOfStrings.join(" ") // "Monique Lhuillier Timeless Rollover Halo Diamond Engagement Ring in 18k Rose Gold"
expect(endResult).toBe("Monique Lhuillier Timeless Rollover Halo Diamond Engagement Ring in 18k Rose Gold")
添加回答
举报
0/150
提交
取消