Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix : naming convention session / main erasing with long test.title/tags#4992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
julien-ft-64 wants to merge1 commit intocodeceptjs:3.x
base:3.x
Choose a base branch
Loading
fromjulien-ft-64:fix/3.x-sessions-playwright-traces

Conversation

julien-ft-64
Copy link

Motivation/Description of the PR

  • Description of this PR, which problem it solves
    Solve issue in some use case where videos and traces of Playwright are not saved correctly when using multiple sessions

fix : naming convention session / main erasing with long test.title/tags
--> file name of traces and video have title limited to 245 char and contains sessions name at end and test status, which in case of gherkin/bdd is not enough, the session name is truncated. Meaning all traces/videos of sessions are written to same file. Changed the naming to have the session before test title, therefore, having always a different file name

fix: context is funtion in session and not property
--> in the sessions iteration, the access to context is not a property but a function, it resulted in getting out of saving because no tracing property existed. Added the () to context usage for sessions loop

fix : dual saving main session
--> main session is also in the list of sessions, generating a Playwright error as the traces are already savec for the main session, and having 2 times the session saved. Added a check on session name to exclude it from the sessions loop.

Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium
  • TestCafe

Applicable plugins:

  • allure
  • autoDelay
  • autoLogin
  • customLocator
  • pauseOnFail
  • coverage
  • retryFailedStep
  • screenshotOnFail
  • selenoid
  • stepByStepReport
  • stepTimeout
  • wdio
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 🧹 Chore
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Runnpm run docs)
  • Lint checking (Runnpm run lint)
  • Local tests are passed (Runnpm test)

fix: context is funtion in session and not propertyfix : dual saving main session
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

This PR fixes issues related to saving video and trace artifacts in multi-session Playwright tests by correcting the naming convention and the use of context as a function.

  • Renames artifact files by prepending the session name to the test title.
  • Fixes the context access by calling it as a function.
  • Excludes the main session (represented by an empty string) from the sessions loop to prevent duplicate saving.

@@ -2377,15 +2377,16 @@ class Playwright extends Helper {
if (this.options.recordVideo && this.page && this.page.video()) {
test.artifacts.video = saveVideoForPage(this.page, `${test.title}.failed`)
for (const sessionName in this.sessionPages) {
test.artifacts[`video_${sessionName}`] = saveVideoForPage(this.sessionPages[sessionName], `${test.title}_${sessionName}.failed`)
if (sessionName === '') continue
Copy link
Preview

CopilotAIMay 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

[nitpick] Consider defining a constant (e.g. MAIN_SESSION) for the main session check instead of using an empty string literal, to enhance code clarity and maintainability.

Suggested change
if(sessionName==='')continue
if(sessionName===MAIN_SESSION)continue

Copilot uses AI. Check for mistakes.

}
}

if (this.options.trace) {
test.artifacts.trace = await saveTraceForContext(this.browserContext, `${test.title}.failed`)
for (const sessionName in this.sessionPages) {
if (!this.sessionPages[sessionName].context) continue
test.artifacts[`trace_${sessionName}`] = await saveTraceForContext(this.sessionPages[sessionName].context, `${test.title}_${sessionName}.failed`)
if (!this.sessionPages[sessionName].context || sessionName === '') continue
Copy link
Preview

CopilotAIMay 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

[nitpick] Similarly, use a named constant for the main session check in the trace saving logic to improve clarity and avoid hard-coding empty string comparisons.

Suggested change
if(!this.sessionPages[sessionName].context||sessionName==='')continue
if(!this.sessionPages[sessionName].context||sessionName===MAIN_SESSION_NAME)continue

Copilot uses AI. Check for mistakes.

@@ -2399,7 +2400,8 @@ class Playwright extends Helper {
if (this.options.keepVideoForPassedTests) {
test.artifacts.video = saveVideoForPage(this.page, `${test.title}.passed`)
for (const sessionName of Object.keys(this.sessionPages)) {
test.artifacts[`video_${sessionName}`] = saveVideoForPage(this.sessionPages[sessionName], `${test.title}_${sessionName}.passed`)
if (sessionName === '') continue
Copy link
Preview

CopilotAIMay 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

[nitpick] Consider using a consistent iteration approach (for example, either for...in or Object.keys) across the different loops for handling sessions to improve readability.

Copilot uses AI. Check for mistakes.

@kobenguyent
Copy link
Collaborator

@julien-ft-64 may you suggest if we could add some tests for those changes?https://github.com/codeceptjs/CodeceptJS/blob/3.x/test/helper/Playwright_test.js#L1431

@kobenguyent
Copy link
Collaborator

Run our tests and still see the error, maybe this needs deeper investigation.

Error: tracing.stop: Must start tracing before stopping

    Timeouts: 10000 › [Session] Starting singleton browser session  should sessions-playwright-traces @Puppeteer @Playwright › Test Timeout: 10000s › [New Session] {"ignoreHTTPSErrors":true,"acceptDownloads":true,"recordVideo":{"size":{"width":400,"height":600},"dir":"/Users/t/Desktop/projects/CodeceptJS/test/acceptance/output/videos/"}}  Scenario()    I am on page "/"    › Changed URL to base url + relative path: http://localhost:8000/ › [New Context] {}    john: I am on page "/form/bug1467"    › Changed URL to base url + relative path: http://localhost:8000/form/bug1467 › <screenshotOnFail> Test failed, try to save a screenshot › [Screenshot] output/should_sessions-playwright-traces_@Puppeteer_@Playwright.failed.png › [Screenshot] john - output/john_should_sessions-playwright-traces_@Puppeteer_@Playwright.failed.png/Users/t/Desktop/projects/CodeceptJS/test/acceptance/output/trace/ff6dea66-928c-4c6c-a15c-f38cd36a6515_should_sessions-playwright-traces_@Puppeteer_@Playwright.failed.zip/Users/t/Desktop/projects/CodeceptJS/test/acceptance/output/trace/0b34d9c8-ba4b-4fe5-9aec-1e8b236b8b78_john_should_sessions-playwright-traces_@Puppeteer_@Playwright.failed.zip    [1] <session:john>  Error (Non-Terminated) | Error: tracing.stop: Must start tracing before stopping | e => error(e)...Error: tracing.stop: Must start tracing before stopping  ✔ OK in 619ms  OK  | 1 passed   // 1s

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@thomashohnthomashohnthomashohn approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

having playwright trace when using multiple sessions sessions
3 participants
@julien-ft-64@kobenguyent@thomashohn

[8]ページ先頭

©2009-2025 Movatter.jp