简体   繁体   中英

Call an element across test in testcafe using javascript

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 "".

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM