CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Parameter restart not working in CodeceptJs with Playwright

Open ghost opened this issue 3 years ago • 3 comments

What are you trying to achieve?

I am using CodeceptJS + Playwright

I'm looking for a before all solution to open browser e execute some steps before scenarios but can't find anyone in codeceptjs+playwright. BeforeSuite can't access browser.

What do you get instead?

I tried to use restart:false to run all scenarios in same browser window but the browser is always restarted before each scenario.

I could see something strange....when using restart:false and test finish, browser close and then another instance browser is opened but closes again and finally open another instance and continue the scenarios.

This not happen when restart:true, browser close and open ok between scenarios.

Provide test source code if related

Here is my helper with restart parameter:

helpers: {
    Playwright: {
      show: true,
      browser: 'chromium',
      windowSize: '1280x960',
      waitForNavigation: "networkidle0",
      restart: false,
      keepBrowserState: true
    },
  },

Details

  • CodeceptJS version: 3.1.1
  • NodeJS Version: 14.9.0
  • Operating System: Windows
  • Playwright version: 1.14.0
  • Configuration file:
const dotenv = require('dotenv').config();

exports.config = {
  tests: './specs/site/*.js',
  output: './reports/e2esitecc',
  helpers: {
    Playwright: {
      show: true,
      browser: 'chromium',
      windowSize: '1280x960',
      waitForNavigation: "networkidle0",
      restart: false,
      keepBrowserState: true
    },
  },
  include: {
    I: './steps_file.js',
    testePage: './pages/testePage.js',
    loginPage: './pages/login_po.js',
  },
  bootstrap: null,
  mocha: {},
  name: 'e2e-web-codeceptjs',
  plugins: {
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true
    },
    tryTo: {
      enabled: true
    },
    screenshotOnFail: {
      enabled: true
    }
  }
}

ghost avatar Aug 18 '21 19:08 ghost

Since 3.1.0 CodeceptJS uses Playwright contexts to to isolate sessions between tests. Previously all data cleanup between tests was done by CodeceptJS internally and it was pretty flaky. In this release, we just used the proposed way from Playwright to do this.

image

So technically browser is not restarted. But context is cleaned up.

Could you check if autoLogin plugin can fit your needs? https://codecept.io/plugins/#autologin

Maybe current behavior could be changed, but you see context is something new. It's like opening a new incognito tab, not a full browser. So I don't think setting restart: true should affect this behavior. Maybe this must be a new option... I don't know. I am also not sure this is the right thing to not restart contexts between tests

DavertMik avatar Aug 19 '21 07:08 DavertMik

Ok, I had to reconsider my previous comment.

I had a discussion with Playwright's team and we agreed that both flows can be used. So currently I recommend you to downgrade to 3.0.x version I will work on 3.2.0 where both options will be enabled.

Thanks for the feedback

DavertMik avatar Aug 19 '21 09:08 DavertMik

Hi!

I tried to downgrade de codeceptjs to version 3.0.7 but when reinstalling the dependencies the file \node_modules\codeceptjs\lib\helper\Playwright.js still get the last version with some updates.

I have another project that is running with 3.0.7 and works fine, browser remained open. So I compared the two versions of Playwright.js file and see several differences. I'm using Playwright 1.12.3 in both projects.

File that let browser close: Playwright.txt File that maintain browser open: PlaywrightOldVersion.txt

ghost avatar Aug 23 '21 18:08 ghost