Reputation: 1406
I am using Instagram to explain my scenario. I login with a testUser id in Instagram. I loop through a set of Instagram accounts (ex: https://www.instagram.com/some_page/). Such direct URL's are passed from a JSON file. I validate something on this page and move on to next page to perform same set of validations.
My problem here is, the login block is executed for each data. I am unable to give it in Fixture section. Is there anyway to keep the logged-in session intact when I move between pages.
Role code
const testUser = Role('https://www.instagram.com/accounts/login/', async t => {
/* some code */
}, { preserveUrl: true });
Fixture and BeforeEach:
fixture`Instaa Test`
.page`https://www.instagram.com/`
.before(async t => {
})
.beforeEach(async t => {
await t.setTestSpeed(0.3)
await t.useRole(testUser)
await t.maximizeWindow()
})
Test Block:
dataSet.forEach(data => {
test("Check Business Account", async t => {
await t.navigateTo(data.pageURL);
/* some code */
}
}
Upvotes: 1
Views: 1344
Reputation: 6318
I was able to reproduce the issue with the following code:
import { Role, Selector } from 'testcafe';
const testUser = Role('https://www.instagram.com/accounts/login/', async t => {
const login = Selector('#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(2) > div > label > input');
const password = Selector('#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(3) > div > label > input');
const submit = Selector('#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(4) > button');
await t.typeText(login, 'my-login');
await t.typeText(password, 'my-password');
await t.click(submit);
// NOTE: here is a workaround
// await t.wait(10000);
}, { preserveUrl: true });
fixture `Instagram`
.page`https://www.instagram.com/`
.beforeEach(async t => {
await t.setTestSpeed(0.3);
await t.useRole(testUser);
});
test(`test1`, async t => {
await t.navigateTo('https://www.instagram.com/cristiano/');
await t.wait(5000);
});
test(`test2`, async t => {
await t.navigateTo('https://www.instagram.com/leomessi/');
await t.wait(5000);
});
test(`test3`, async t => {
await t.navigateTo('https://www.instagram.com/neymarjr/');
await t.wait(5000);
});
I created a separate ticket in the testcafe repository: https://github.com/DevExpress/testcafe/issues/4978
To make this example work, you need to add extra time at the end of your role initializer. Uncomment the following code:
// NOTE: here is a workaround
// await t.wait(10000);
Upvotes: 3