Skip to content

feat: better I.grab logging in live interactive mode #4986

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2025

Conversation

owenizedd
Copy link
Contributor

@owenizedd owenizedd commented May 6, 2025

Motivation/Description of the PR

Currently, the interactive shell mode with pause() resulting output like:
[Object object].... this is clearly not useful during live interactive mode when we're using:
I.grabBrowserLogs();
or
I.grabRecordedNetworkTraffics();

By json stringify the value, we can safely see every type of output in the terminal session like following.
image

  • Resolves #issueId (if applicable).

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 (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

@owenizedd owenizedd changed the title feat: better I.grab logging feat: better I.grab logging in live interactive mode May 6, 2025
@kobenguyent kobenguyent requested review from Copilot and thomashohn May 6, 2025 07:56
Copy link
Contributor

@Copilot Copilot AI 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 improves the logging output in live interactive mode by formatting the output of I.grab commands with JSON.stringify.

  • Improved logging by converting the logged value to a JSON string with indentation.
  • Enhances clarity during debugging sessions in interactive mode.

Add try/catch

Co-authored-by: Copilot <[email protected]>
@owenizedd owenizedd requested a review from kobenguyent May 7, 2025 00:37
@kobenguyent kobenguyent requested a review from Copilot May 7, 2025 03:55
Copy link
Contributor

@Copilot Copilot AI 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 improves the interactive shell logging during I.grab* commands by stringifying the output, thereby providing clearer and more readable terminal output during live sessions.

  • Enhanced readability of interactive shell logs by applying JSON.stringify to the result
  • Added error handling to catch potential JSON stringification failures

@@ -175,7 +175,11 @@ async function parseInput(cmd) {
output.print(output.styles.success(' OK '), cmd)
}
if (cmd?.startsWith('I.grab')) {
output.print(output.styles.debug(val))
try {
Copy link
Preview

Copilot AI May 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a comment here to explain that JSON.stringify is applied to handle various output types for improved readability.

Suggested change
try {
try {
// Use JSON.stringify to format the output for improved readability, especially for complex objects.

Copilot uses AI. Check for mistakes.

@kobenguyent kobenguyent requested a review from Copilot May 7, 2025 09:40
Copy link
Contributor

@Copilot Copilot AI 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 addresses a bug where interactive logging produced uninformative output and replaces it with JSON stringified output for better readability.

  • Adds a try-catch block around JSON.stringify in I.grab command logging
  • Improves error reporting during JSON conversion failures
Comments suppressed due to low confidence (1)

lib/pause.js:181

  • [nitpick] Consider logging additional error context (such as the full error stack) to improve debugging when JSON.stringify fails.
output.print(output.styles.error(' ERROR '), 'Failed to stringify result:', err.message)

Co-authored-by: Copilot <[email protected]>
@kobenguyent kobenguyent merged commit 256e525 into codeceptjs:3.x May 7, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants