简体   繁体   English

使用 Jest 按顺序运行 Puppeteer 测试

[英]Running Puppeteer tests in order with Jest

I'm using Jest Puppeteer and I have a situation where I'd like to run my login test (which sets cookie/localStorage for the authentication) first and run the others after, however, I know that Jest doesn't work this way - as it searches the local filesystem and runs tests based on the patterns in the filename, and the order in which they run is different.我正在使用 Jest Puppeteer,我想先运行登录测试(设置 cookie/localStorage 进行身份验证),然后再运行其他测试,但是,我知道 Jest 不能以这种方式工作- 因为它搜索本地文件系统并根据文件名中的模式运行测试,并且它们运行的​​顺序不同。

I'm not entirely sure I'm going about this the correct way as I'm relying on a test to set the the authentication session for the other tests.我不完全确定我会以正确的方式进行此操作,因为我依靠测试来设置其他测试的身份验证会话。

Is it possible to do the above, or do I need to rethink my approach?是否可以执行上述操作,或者我是否需要重新考虑我的方法?

This is not a timely answer.这不是一个及时的答案。 I had similar problem.我有类似的问题。 I am able to run tests in order by nesting describe blocks as shown below.我可以通过嵌套描述块按顺序运行测试,如下所示。 my tests are in separate files that I require here.我的测试在我需要的单独文件中。

const puppeteer = require('puppeteer');
const login = require('./login');
const upload = require('./upload');
let browser;

beforeAll(async () => {
    browser = await puppeteer.launch({
        headless: false,
        devtools: true,
        slowMo: 50
    });

})
describe('test suite', () => {
    describe('login', () => {

        test('url is correct', async () => {

            const url = await login();
            expect(url).toBe('https://uat2.onplanapp.com/#/');


        }, 25000);

    });
    describe('upload', () => {


        test('file upload ok', async () => {
            url = await upload();
            console.log('page.url');

            expect(url).toBe('https://uat2.onplanapp.com/#/moduleLibrary');
            //expect(url).toBe('https://uat2.onplanapp.com/#/uploadFile');

        }, 10000);

    });
    afterAll(async done => {
        console.log('GOT TO AFTER ALL');
        browser.close()
        done();
    });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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