[英]Call an element across test in testcafe using javascript
我想在测试用例中使用一个元素
跨测试用例调用元素: orderIDReplace 是测试create order
中选定元素的元素(夹具app
)。 我想在测试receive order
中使用/调用 orderIDReplace(夹具backend
)
fixture `app`
.page `https://example.com/`
.beforeEach(async t => {
await t
.click(`#username`)
.typeText(`#username`, `test`, {paste : true})
.click(`#password`)
.typeText(`#password`, `test`, {paste : true})
.click('#submit')
.wait(3000)
})
test('Create Order', async t => {
.await t
......
.click(Selector('div').withAttribute('class','vBtnContent').withText('Apply'))
let orderID = await Selector('p').withAttribute('class', 'g-invoice--code').nth(0).innerText;
let orderIDReplace = (lib.replaceCharacter(orderID));
})
fixture `backend`
.page `https://contoh.com/`
.beforeEach(async t => {
await t
.click(`#name`)
.typeText(`#name`, `coba`, {paste : true})
.click(`#password`)
.typeText(`#password`, `coba`, {paste : true})
.click('#submit')
.wait(3000)
})
test('receive order', async t => {
.await t
.click('#txtSearch')
.typeText('#txtSearch', orderIDReplace, {paste: true})
.click('#filter')
预期结果:结果是订单id
实际结果:错误:“text”参数应为非空字符串,但它是“”。
您可以在测试之外定义变量并在多个测试中使用它:
import { Selector } from 'testcafe';
let title = '';
fixture('MyFixture')
.page('https://devexpress.github.io/testcafe/');
test('Test 1', async t => {
title = await Selector('.title').innerText;
});
test('Test 2', async t => {
console.log(title);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.