Reputation: 103
I have a Fixture with 4 tests, I want to test this Fixture 2 different browsers. So I run below command:
testcafe -c 1 chrome,firefox testsfolder/
I am using t.fixtureCtx
to set values across these 4 tests because I need to refer values from one test to another. I was expecting that it will spin up one instance each of Chrome and FF and run entire test independent of each other (browser).
However, the issue I am facing is that the tests do not stay in their lane. In other words, values set by Chrome in Test#1 are used by Firefox in its Test#2.
I can always run these tests separately in two separate commands however I wanted to test it on multiple browsers in a single command. Am I missing something here?
Upvotes: 2
Views: 497
Reputation: 2348
The t.fixtureCtx object is created once before fixture tests run on the server side, and it is shared between several browsers. This behavior is by design.
I suggest you save shared values as an object according to the browser name.
For example:
const logTimestamp = t => {
if (!t.fixtureCtx.sharedData)
t.fixtureCtx.sharedData = {};
const browser = t.browser.name;
if (!t.fixtureCtx.sharedData[browser]) {
t.fixtureCtx.sharedData[browser] = { timestamp: new Date().getTime() };
}
};
fixture`Fixture 1`
.page`about:blank`;
test('Test 1', async t => {
await t.wait(1000);
logTimestamp(t);
console.log(`Test 1, browser: ${t.browser.name}, timestamp: ${t.fixtureCtx.sharedData[t.browser.name].timestamp}`);
});
test('Test 2', async t => {
await t.wait(1000);
console.log(`Test 2, browser: ${t.browser.name}, timestamp: ${t.fixtureCtx.sharedData[t.browser.name].timestamp}`);
});
Upvotes: 4