簡體   English   中英

量角器連接兩個具有相同類名的跨度

[英]Protractor concatenate two spans with same class name

我是 Protractor E2E 測試的新手。 在我正在測試的網頁上,有兩個 span 標簽,其類名稱為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);
  }
});

});

這應該有效(可能需要一些更改)

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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM