至尊寶的傳說(shuō)
2023-03-24 16:40:02
我是 Protractor E2E 測(cè)試的新手。在我正在測(cè)試的網(wǎng)頁(yè)上,有兩個(gè)類(lèi)名為name-part. 我需要一種方法將兩者的值連接到一個(gè)元素結(jié)果中。這是代碼的布局方式。<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>我需要將兩個(gè)跨度連接成一個(gè)斷言。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貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
這應(yīng)該工作(可能需要一些改變)
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")
添加回答
舉報(bào)
0/150
提交
取消