Testcafe:有没有办法使页面之间的登录会话保持完整? [英] Testcafe: Is there a way to keep the logged-in session intact between pages?

查看:73
本文介绍了Testcafe:有没有办法使页面之间的登录会话保持完整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Instagram解释我的情况.我在Instagram中使用testUser ID登录.我循环浏览了一组Instagram帐户(例如:https://www.instagram.com/some_page/).此类直接URL是从JSON文件传递的.我验证此页面上的内容,然后转到下一页以执行相同的验证集.

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.

我的问题是,对每个数据都执行登录块.我无法在灯具"部分中提供它.当我在页面之间移动时,是否仍然可以保持登录会话的完整性.

角色代码

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

测试块:

dataSet.forEach(data => {
    test("Check Business Account", async t => {
    await t.navigateTo(data.pageURL);
    /* some code */
}
}

推荐答案

我能够使用以下代码重现该问题:

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

我在testcafe存储库中创建了一个单独的票证: https://github.com/DevExpress/testcafe/issues/4978

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

这篇关于Testcafe:有没有办法使页面之间的登录会话保持完整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆