CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

How to run many different Scenario() without closing the browser?

Open arsa666 opened this issue 10 years ago • 7 comments

How to run many different Scenario() without closing the browser? This is my code:

Before((I) => {
    I.amOnPage('/');
    I.fillField('email', '[email protected]');
    I.fillField('password', '123456');
    I.click('Sign in');
});

Scenario('Check to see if it has landing page and welcome msg', (I) => {
    I.see('Welcome to Casefriend Version 1.0');
    I.amOnPage('http://cflocal/#landing');


});

Scenario('Logining into Casefriend', (I) => {
    I.click('Users');
    I.click('New User');
});

This code passes correctly but it opens firefox, test Scenario 1 then closes firefox, opens again, and tests second Scenario. I want it to do everything on one single firefox instance. How can I do?

arsa666 avatar Dec 19 '15 22:12 arsa666

I think this is a good feature that will be available soon in upcoming releases ) Thanks for the suggestion

DavertMik avatar Dec 20 '15 13:12 DavertMik

@DavertMik It would be really awesome if the state is reset to the initiale state of the site after each test, in order to enable a clean testing environment. (This is something CasperJS has issues with :wink:)

fabioel avatar Jan 05 '16 10:01 fabioel

@DavertMik This is kinda killer for working with SauceLabs (starting browsers there is slooow)

I've been looking at how to implement this today ... Basic plan of attack is just a custom WebDriverIO Helper that only starts the browser if it hasn't already been created... This could then be easily be expanded to work off a config option, and I'd probably add that after a test fails, it might be worth restarting the browser.

... only problem is there is no beforeAll/afterAll currently implemented (as per https://github.com/Codeception/CodeceptJS/issues/103) so there is no place to hook into really shut down the browser ... any thoughts on doing this?

smozely avatar May 31 '16 04:05 smozely

@smozely I created a PR with this feature for Protractor/Selenium, I can try to look into it for webdriver.io or If you want to have a look feel free. https://github.com/Codeception/CodeceptJS/pull/167

Nighthawk14 avatar Jul 22 '16 12:07 Nighthawk14

@fabioel Have you tried using Nightmare? There's a setting that effectively does what you're referring to. Below is an extract from my helpers config:

Nightmare: {
      url: 'http://localhost:3000',
      webPreferences: {
        partition: 'nopersist'
      }
   }

HughZurname avatar Jan 09 '17 09:01 HughZurname

Closing this issue, now there is restart option that can be used for disabling browser restart

APshenkin avatar Jun 01 '17 07:06 APshenkin

helpers: { Playwright: { browser: 'chromium', url: '***', show: true, keepBrowserState: true, // This ensures cookies and session are maintained across scenarios restart: false, // Prevents browser from restarting after each scenario keepCookies: true, } }

I have given restart as 'false' but still the browser is getting relaunched after every scenario

FathimaAfshan avatar Feb 03 '25 10:02 FathimaAfshan