CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Playwright: helper's activeSessionName instance variable becomes incorrect when re-entering an existing session

Open kayleewright-bluescape opened this issue 3 years ago • 3 comments

Hi,

I'm currently using the Playwright helper and noticed that the activeSessionName instance variable stored in the helper is sometimes incorrect.

It seems to be because in _session():

  • On first entry: start() will set it, loadVars() will use it, and restoreVars() will set it to ''.
  • On re-entering and existing session: since start() is not called, loadVars() now doesn't have an activeSessionName set and proceeds to us '' as the activeSessionName. this.sessionPages gets a new '' entry as a result too.

Functionally most things seem to work since loadVars does correctly restore the browser context. saveScreenshot() does use this.activeSessionName though so I'm not sure what the implications would be there.

https://github.com/codeceptjs/CodeceptJS/blob/c10666c9d5569c09d8daba6a01c955c4d7ecdd4a/lib/helper/Playwright.js#L490

  session('hello1', async function() {
    //Playwright helper's activeSessionName is 'hello1'
    I.say('moooo');
    await I.amOnPage('https://google.com')
  })
  session('hello2', async function() {
    //Playwright helper's activeSessionName is 'hello2'
    I.say('moooo');
    await I.amOnPage('https://google.com')
  })
  session('hello1', async function() {
    //Playwright helper's activeSessionName is ''
    I.say('moooo2');
    await I.amOnPage('https://nba.com')
  })
  session('hello2', async function() {
    //Playwright helper's activeSessionName is ''
    I.say('moooo2');
    await I.amOnPage('https://nba.com')
  })

Details

  • CodeceptJS version: 3.2.3
  • NodeJS Version: v14.16.1
  • Operating System:Windows
  • Puppeteer

kayleewright-bluescape avatar Jan 25 '22 18:01 kayleewright-bluescape

I just encountered the very same problem with the Puppeteer helper, with the same reasons (not re-initializing the property "activeSessionName").

danielrentz avatar Feb 03 '22 08:02 danielrentz

@danielrentz if it helps I've worked around the issue by pulling the session name out of the recorder rather than using the one attached to the helper:

const recorderInfo = codeceptjs.recorder.toString().split(/[\n|$]/, 1)[0];
const sessionName = recorderInfo.match(/session:(.*)>/)[1];

kayleewright-bluescape avatar Mar 16 '22 20:03 kayleewright-bluescape

@kayleewright-bluescape Nice, thanks for the hint!

danielrentz avatar Mar 17 '22 07:03 danielrentz

Looked like it's fixed. Closed for now!

  session @session
    --- STARTED "before each" hook: Before for "session @session" ---
 › Cannot save user session with empty cookies from auto login's fetch method
    I am on page "https://google.com"
    › [Browser:Info] Autofocus processing was blocked because a document already has a focused element.
    --- ENDED "before each" hook: Before for "session @session" ---
 › [New Context] {}
   moooo
    hello1: I am on page "https://google.com"
 › [New Context] {}
   moooo
    hello2: I am on page "https://google.com"
   moooo2
    hello1: I am on page "https://nba.com"
    › [Browser:Info] [AccessEnabler.js][info] Version: 4.6.0-3d1a9e6 RELEASE[AccessEnabler.js][info] Version: 4.6.0-3d1a9e6 RELEASE
    › [Browser:Info] [AccessEnablerProxy.js][info] Version: 4.6.0-3d1a9e6 RELEASE[AccessEnablerProxy.js][info] Version: 4.6.0-3d1a9e6 RELEASE
    › [Browser:Error] Storyteller Javascript SDK : 9.7.0-8.8.7 : StorytellerRowView : e.play is not a functionStoryteller Javascript SDK : 9.7.0-8.8.7 : StorytellerRowView : e.play is not a function
    › [Browser:Error] Failed to load resource: the server responded with a status of 404 ()
    › [Browser:Error] Failed to load resource: the server responded with a status of 400 ()
   moooo2
    hello2: I am on page "https://nba.com"
    › [Browser:Error] Access to XMLHttpRequest at 'https://core-api.nba.com/cp/api/v1.3/feeds/rollingschedule?platform=web' from origin 'https://www.nba.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    › [Browser:Error] Failed to load resource: net::ERR_FAILED
    › [Browser:Info] [AccessEnabler.js][info] Version: 4.6.0-3d1a9e6 RELEASE[AccessEnabler.js][info] Version: 4.6.0-3d1a9e6 RELEASE
    › [Browser:Error] Access to XMLHttpRequest at 'https://core-api.nba.com/cp/api/v1.3/feeds/gamecardfeed?gamedate=11/24/2023&platform=web' from origin 'https://www.nba.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    › [Browser:Error] Failed to load resource: net::ERR_FAILED
    › [Browser:Info] [AccessEnablerProxy.js][info] Version: 4.6.0-3d1a9e6 RELEASE[AccessEnablerProxy.js][info] Version: 4.6.0-3d1a9e6 RELEASE
    › [Browser:Error] Storyteller Javascript SDK : 9.7.0-8.8.7 : StorytellerRowView : e.play is not a functionStoryteller Javascript SDK : 9.7.0-8.8.7 : StorytellerRowView : e.play is not a function
 › [Browser:Error] Failed to load resource: the server responded with a status of 400 ()
  ✔ OK in 13511ms


  OK  | 1 passed   // 18s

kobenguyent avatar Nov 25 '23 08:11 kobenguyent