【发布时间】:2019-09-25 04:43:17
【问题描述】:
我想在测试用例中使用一个元素
跨测试用例调用一个元素:orderIDReplace 是来自测试create order(夹具app)中选定元素的元素。我想在测试receive order(夹具backend)中使用/调用orderIDReplace
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”参数应该是一个非空字符串,但它是“”。
【问题讨论】:
-
从您的问题中不清楚您想要实现什么行为。请查看a fixture context object 功能。它可能适合您的需求。如果不是,请更详细地描述您的场景。您的测试的完整代码将非常有帮助。
-
感谢您的建议@AleksandrProkhorov 编辑了我上面的帖子
标签: javascript automated-tests e2e-testing testcafe web-testing