Angular Protractor - Leave browser open after E2E tests

后端 未结 5 1392
名媛妹妹
名媛妹妹 2020-12-17 07:31

Is it possible to leave the test browser windows open after Angular Protractor tests run? I have a tough test failing in FireFox and it\'d be useful to access the state of t

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 08:17

    super simple solution, that does exactly what's needed

    The idea is that you don't really want to keep alive the session but rather pause it for a very long time when tests are done and be able to resume on-close procedures at any time

    So just add this to your config.js

        async onComplete() {
            await browser.waitForAngularEnabled(false);
            await browser.wait(
                async () => {
                    let url = await browser.getCurrentUrl();
                    return url.includes('close/');
                },
                5 * 60 * 1000,
                'Keep-alive timeout reached, closing the session...',
            );
        },
    

    What the code does is, after all tests passed or failed, it waits until you type and submit close/ in browser's url field, or times out itself in 5 mins.

    The reason await browser.waitForAngularEnabled(false); is needed here, because the browser opens an empty page when you type close/ which is non angular

    You can even improve it and make it conditional, based on a parameter you pass to protractor config

提交回复
热议问题