Skip to content

fix: update assertion method in DebuggerHelper to use GetNAssertElementText #40937

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 1 commit into from
Jun 16, 2025

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Jun 13, 2025

Description

Problem

The existing assertion in DebuggerHelper falsely passed even when there were visible errors in the debug console, leading to unreliable test validations.

Root cause

The assertion used assert contains, which only checked for the presence of the word "debug". Since this word is present regardless of the actual error count, the assertion would always pass, even if there were errors.

Solution

This PR handles the update of the assertion method in DebuggerHelper to use getNAssertElementText instead of assert contains. This enforces strict validation by checking for an exact match in the debug message text, ensuring accurate test outcomes when error count is expected to be zero.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Datasource, @tag.Widget, @tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/15633758023
Commit: 105857f
Cypress dashboard.
Tags: @tag.Datasource, @tag.Widget, @tag.Sanity
Spec:


Fri, 13 Jun 2025 13:52:55 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Tests
    • Improved the accuracy of error count assertions in test cases to ensure exact text matches for error indicators in the debugger interface.

…ntText

Why was this updated? The assertion for when the count is equal to zero would always pass regardless of the actual error count. For example, if there are three errors, the text in the error count would be "debug space three." The previous assertion used "assert contains," which would always include the text "debug," making it true regardless of the number of errors visible in the console. I have now replaced it with "get assert element text," which enforces strict checking for an empty debug message when the error count is zero.
Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

Walkthrough

The internal logic of the AssertErrorCount method in the DebuggerHelper class was updated. The method now uses a different assertion approach and adjusts the expected string when the error count is zero. No changes were made to public interfaces or exported declarations.

Changes

File(s) Change Summary
app/client/cypress/support/Pages/DebuggerHelper.ts Modified AssertErrorCount to use strict text assertion and adjusted the expected zero-count string.

Poem

In DebuggerHelper’s careful hand,
The error count must match as planned.
A trailing space now marks the way,
With stricter checks to save the day.
No public face has changed its tune—
Just sharper eyes beneath the moon!
🌙🔍

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rahulbarwal rahulbarwal self-assigned this Jun 13, 2025
@github-actions github-actions bot added the Bug Something isn't working label Jun 13, 2025
@rahulbarwal rahulbarwal added List Widget V2 Issues related to the list widget v2 Error handling Issues related to error management within Appsmith Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Unplanned Work - Q&W Work items that are unplanned ok-to-test Required label for CI labels Jun 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/client/cypress/support/Pages/DebuggerHelper.ts (1)

144-145: Locator duplication can be consolidated

Both _debuggerIcon (line 16) and _errorCount (line 24) resolve to the same selector .t--debugger-count. This divergence in naming invites accidental drift.

Consider removing _errorCount and re-using _debuggerIcon, or vice-versa, to avoid duplicated selectors and keep maintenance overhead low.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dea1c03 and 105857f.

📒 Files selected for processing (1)
  • app/client/cypress/support/Pages/DebuggerHelper.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`app/client/cypress/**/**.*`: Review the following e2e test code written using the Cypress test library. Ensure that: - Follow best practices for Cypress code and e2e automation. ...

app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
  • app/client/cypress/support/Pages/DebuggerHelper.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: mark-stale
  • GitHub Check: build
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build

Comment on lines +144 to +145
const assertion = count > 0 ? `Debug (${count})` : "Debug ";
this.agHelper.GetNAssertElementText(this.locators._errorCount, assertion);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Avoid brittle equality check caused by trailing space

Relying on the literal string "Debug " (note the trailing space) makes the assertion brittle—any UI trim, refactor, or font-based non-breaking space will break the test.
Prefer a whitespace-insensitive comparison, e.g. assertion.trim() or a regex that tolerates optional whitespace.

-const assertion = count > 0 ? `Debug (${count})` : "Debug ";
-this.agHelper.GetNAssertElementText(this.locators._errorCount, assertion);
+const assertion =
+  count > 0 ? `Debug (${count})` : "Debug"; // no trailing space
+this.agHelper.GetNAssertElementText(
+  this.locators._errorCount,
+  assertion,
+  { trim: true }, // assume helper supports an options bag
+);

If GetNAssertElementText lacks a trim/regex option, consider switching to a helper that does, or wrap the retrieved text with .trim() before comparing.
This small tweak will harden the test against UI whitespace changes.


🏁 Script executed:

#!/bin/bash
# Locate the definition of GetNAssertElementText to inspect its signature and default behavior
rg -n "GetNAssertElementText" -n app/client/cypress/support

Length of output: 693


🏁 Script executed:

#!/bin/bash
# Show definition and surrounding lines for GetNAssertElementText
rg -n "public GetNAssertElementText" -n app/client/cypress/support/Pages/AggregateHelper.ts
sed -n '360,420p' app/client/cypress/support/Pages/AggregateHelper.ts

Length of output: 2058


Avoid brittle equality check caused by trailing space

Using the literal "Debug " (with a trailing space) makes this assertion fragile—any UI trim or accidental whitespace change will break the test. Remove the trailing space and switch to a containment assertion:

- const assertion = count > 0 ? `Debug (${count})` : "Debug ";
- this.agHelper.GetNAssertElementText(this.locators._errorCount, assertion);
+ const assertion = count > 0 ? `Debug (${count})` : "Debug";
+ this.agHelper.GetNAssertElementText(
+   this.locators._errorCount,
+   assertion,
+   "contain.text", // tolerates surrounding whitespace
+ );

If you require an exact match, you can invoke .invoke("text").then(text => expect(text.trim()).to.equal(assertion)) or extend GetNAssertElementText to accept a trim option. This change hardens the test against incidental whitespace.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/client/cypress/support/Pages/DebuggerHelper.ts around lines 144-145, the
assertion uses a literal string with a trailing space ("Debug "), making the
test fragile to whitespace changes. Remove the trailing space from the string
and modify the assertion to either trim the retrieved text before comparison or
use a containment check instead of strict equality. If GetNAssertElementText
does not support trimming, replace it with a custom assertion that invokes
.invoke("text") on the element and compares the trimmed text to the expected
string to make the test resilient to incidental whitespace.

@rahulbarwal rahulbarwal merged commit 8ba0961 into release Jun 16, 2025
59 of 62 checks passed
@rahulbarwal rahulbarwal deleted the rahulbarwal/fix-faulty-assertion branch June 16, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Error handling Issues related to error management within Appsmith List Widget V2 Issues related to the list widget v2 ok-to-test Required label for CI Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Unplanned Work - Q&W Work items that are unplanned
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants