Nem*_*vic 6 testing automated-tests e2e-testing testcafe
我在选择有条件地出现在页面上的元素时遇到了麻烦。我尝试过awaiting,但是没有用。
// Gets imported as detailedProductPage
export default class Page {
constructor () {
this.chipItem0 = Selector('[data-test-id="chipItem0"]').child('.tag-name').child('[data-test-id="tagValue"]');
}
}
test('should accept value and allow for making the selection of multiple items.', async t => {
const string0 = 'Professionelle Nassreinigung nicht erlaubt';
const string1 = 'Handwäsche';
const string2 = 'Waschen 30°C';
await t
.click(detailedProductPage.listContainerFirstChild)
.typeText(detailedProductPage.symbols, string0)
.click(detailedProductPage.symbolsResultsItem0)
.expect(string0).eql(detailedProductPage.chipItem0.innerText)
.typeText(detailedProductPage.symbols, string1)
.click(detailedProductPage.symbolsResultsItem0)
.expect(string1).eql(detailedProductPage.chipItem1.innerText)
.typeText(detailedProductPage.symbols, string2)
.click(detailedProductPage.symbolsResultsItem1)
.expect(string2).eql(detailedProductPage.chipItem2.innerText);
});
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以使用该exists属性来检查元素是否存在于页面上。这样,您可以单击有条件显示在页面上的元素:
const el = Selector('#el');
if(await el.exists)
await t.click(el);
Run Code Online (Sandbox Code Playgroud)
为了使测试正确,您需要修复断言。根据TestCafe断言API,eql断言应以以下方式使用:
await t.expect( actual ).eql( expected, message, options );
Run Code Online (Sandbox Code Playgroud)
TestCafe允许用户将异步选择器属性作为actual参数传递。这些属性表示测试页面上相关DOM元素的状态。在您的情况下,实际值为detailedProductPage.chipItem0.innerText。该expected值不能是异步属性,而应该是一个计算值(例如字符串,布尔值,数字或某些对象等)。以下代码应正常工作:
await t
.click(detailedProductPage.listContainerFirstChild)
.typeText(detailedProductPage.symbols, string0)
.click(detailedProductPage.symbolsResultsItem0)
.expect(detailedProductPage.chipItem0.innerText).eql(string0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1250 次 |
| 最近记录: |