Reputation: 11
I want to use an element across a test case
Call an element across test case: orderIDReplace is element from the selected element in test create order
(fixture app
). I want to use/call orderIDReplace in test receive order
(fixture 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')
Expected result: The result is order id
Actual result: Error: The "text" argument is expected to be a non-empty string, but it was "".
Upvotes: 1
Views: 816
Reputation: 2348
You can define your variable outside the test and use it in several tests:
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);
});
Upvotes: 1