CodeceptJS
CodeceptJS copied to clipboard
Playwright: helper's activeSessionName instance variable becomes incorrect when re-entering an existing session
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, andrestoreVars()will set it to''. - On re-entering and existing session: since
start()is not called,loadVars()now doesn't have anactiveSessionNameset and proceeds to us''as theactiveSessionName.this.sessionPagesgets 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
I just encountered the very same problem with the Puppeteer helper, with the same reasons (not re-initializing the property "activeSessionName").
@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 Nice, thanks for the hint!
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