量角器连接两个具有相同 class 名称的跨度
Protractor concatenate two spans with same class name
我是 Protractor E2E 测试的新手。在我正在测试的网页上,有两个 class 名称为 name-part
的 span 标签。我需要一种方法将两者的值连接到一个元素结果中。这是代码的布局方式。
<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")
我是 Protractor E2E 测试的新手。在我正在测试的网页上,有两个 class 名称为 name-part
的 span 标签。我需要一种方法将两者的值连接到一个元素结果中。这是代码的布局方式。
<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")