【问题标题】:Call an element across test in testcafe using javascript使用javascript在testcafe中跨测试调用元素
【发布时间】: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


【解决方案1】:

您可以在测试之外定义变量并在多个测试中使用它:

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);
});

【讨论】:

  • 我试过了,不行,功能报错,我试试其他的,谢谢
  • 请显示您面临的错误以及发生错误的代码行。
猜你喜欢
  • 2021-03-25
  • 1970-01-01
  • 2022-07-19
  • 1970-01-01
  • 2020-04-11
  • 2019-02-12
  • 2011-12-09
  • 1970-01-01
  • 2021-10-02
相关资源
最近更新 更多