We are working in the insurance domain and have a specific scenario that we want to achieve using TestCafe:
1st step: Login into the application 2nd step: Create a claim and store the claim number in a global variable 3rd step: Use the globally declared claim number in all the test scripts.
We are implementing the Page Object Model to accomplish this scenario.
Please advise on how we can achieve this in TestCafe. We have noticed that the web element value obtained in the 2nd file disappears as soon as the test case is executed. How can we pass that web element value to our 3rd file?
If possible, please provide detailed steps on how to do this.
We have attempted to use keywords like "global" and "globalthis" to define our selector, but it did not work.
In our 'page.js' file:
import { Selector, t } from 'testcafe'; class PageModel { constructor() { global.ClaimNumber = Selector('#Txt_claimnumber'); // Selector for Claim Number
this.DateOfEvent = Selector('#dateofevent'); // Selector for Date of Event
this.DateOfClaim = Selector('#dateofclaim') // Selector for Date of Claim
this.TimeOfEvent = Selector('#timeofevent') // Selector for Time of Event
this.TimeOfClaim = Selector('#timeofclaim') // Selector for Time of Claim
this.ClaimStatus = Selector('#claimstatus') // Selector for Claim Status
this.Save = Selector('#Save'); // Selector for Save Button
}};
export default new PageModel();
In our 'test.js' file:
import { Selector } from 'testcafe';
import PageModel from './page';
fixture`Getting Started` .page`https://devexpress.github.io/testcafe/example`; var claimid; // Claim ID will be generated after saving a claim test('My first test', async t => { await t .typeText(this.DateOfEvent, '20/09/2022')
.typeText(this.DateOfClaim, '20/09/2022')
.typeText(this.TimeOfEvent, '12:00')
.typeText(this.TimeOfClaim, '12:00')
.typeText(this.ClaimStatus, 'xyz')
.click(this.Save)
claimid = global.ClaimNumber.value
// After saving the claim, we want to fetch the claim ID and use it in another test script
});
In our 'test1.js' file:
import { Selector } from 'testcafe';
import PageModel from './page';
import Test from './test'
fixture`Getting Started` .page`https://devexpress.github.io/testcafe/example`; test('My first test', async t => { var claimid1 = '23445'; await t.expect(claimid1).eql('claimid');
// Verify if the claim ID from test.js is equal to the claim ID from test1.js or not
// This is just an example, but our requirement is to use the claim ID (obtained from test.js) for different operations in the test1.js script.
});
Please provide guidance on how to achieve this scenario effectively.