Skip to content

Conversation

@iamlokanath
Copy link

@iamlokanath iamlokanath commented Jan 8, 2026

ui-test/src/main/java/stepdefinitions/StepDef.java
instead of if condition, used iterator for getting and storing the window handles in variables and used that

Cleaned up * and used the appropriate path for all the xpath elemtns in all pages.
avoided using the * in xpath and use appropriate tag

Summary by CodeRabbit

  • Tests
    • Enhanced UI test element targeting for improved test reliability and accuracy across multiple pages.
    • Refined window/tab switching logic to ensure proper detection of secondary windows.
    • Optimized test execution by removing unnecessary wait times during token-based login workflows.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

Walkthrough

This pull request updates XPath selectors across multiple UI test pages to use more specific element-tag-qualified expressions instead of generic data-testid queries. Additionally, window-switching logic in step definitions is improved to handle multi-window scenarios robustly, and timing-related waits in OIDC login are removed.

Changes

Cohort / File(s) Summary
XPath Selector Refinement – FAQ & Login Pages
ui-test/src/main/java/pages/FaqPage.java, ui-test/src/main/java/pages/Loginpage.java
Replaced generic //*[@data-testid='...'] with tag-specific selectors (e.g., //p, //h3, //button) for content text, titles, and arrow buttons to improve element targeting precision.
XPath Selector Refinement – Home Page
ui-test/src/main/java/pages/HomePage.java
Updated large set of locators across footer text, page container, header/menu buttons, search inputs, and feature items to use specific element tags (//div, //button, //input, //p, //span, //img) instead of wildcard selectors.
XPath Selector Refinement – Credential Pages
ui-test/src/main/java/pages/MosipCredentials.java, ui-test/src/main/java/pages/SunbirdCredentials.java
Narrowed locators for ItemBox containers, login buttons, OTP buttons, and text displays to use specific element types (e.g., //div[@data-testid='...'], //button[@data-testid='...'], //p[@data-testid='...']).
Window Switching Logic & Timing Improvements
ui-test/src/main/java/stepdefinitions/StepDef.java, ui-test/src/main/java/stepdefinitions/StepDefOIDCLogin.java
Enhanced window-switching in user_open_new_tab and UserSwitchToAboutInjiTab to identify second window by iteration rather than size comparison; removed two 10-second waits in user_performs_token_login_using_refresh_token around cookie handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • lsivanand
  • jackjain

Poem

🐰✨ With whiskers twitched and paws held high,
XPath selectors now specify—
No more wildcards in our test,
Each element tagged and truly blessed!
Window switches now feel quite right,
As waits fade into the moonlit night. 🌙

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: XPath selector cleanup and window handling refactoring across the UI test codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ui-test/src/main/java/pages/HomePage.java (1)

35-383: Excellent refactoring to use specific element tags in XPath selectors.

The systematic replacement of generic XPath patterns with element-specific selectors (e.g., //button[@data-testid='...'], //p[@data-testid='...']) is a best practice that improves selector performance and clarity.

However, address the following brittleness issues:

  • Lines 198, 358, 362: Indexed XPath selectors [1] and [2] are fragile and will break if the DOM structure changes. Consider using more stable selectors or adding fallback logic.
  • Line 113: //button[text()='Go To Home'] uses text content matching, which is brittle if the button text changes. Align with the data-testid pattern used throughout the file.

Verify all locators function correctly by running the UI test suite.

🧹 Nitpick comments (3)
ui-test/src/main/java/stepdefinitions/StepDef.java (1)

1064-1084: Improved window handling logic.

The iterator-based approach is more robust than array indexing because it:

  • Explicitly identifies a window different from the current one
  • Handles the case where a second window might not exist
  • Doesn't rely on assumptions about window ordering
♻️ Optional: Extract duplicated window-switching logic

Both user_open_new_tab (lines 1069-1083) and UserSwitchToAboutInjiTab (lines 1089-1103) contain identical window-switching logic. Consider extracting this into a helper method:

private void switchToSecondWindow() {
    Set<String> allWindowHandles = baseTest.getDriver().getWindowHandles();
    String currentWindowHandle = baseTest.getDriver().getWindowHandle();
    String secondWindowHandle = null;

    java.util.Iterator<String> iterator = allWindowHandles.iterator();
    while (iterator.hasNext()) {
        String handle = iterator.next();
        if (!handle.equals(currentWindowHandle)) {
            secondWindowHandle = handle;
            break;
        }
    }

    if (secondWindowHandle != null) {
        baseTest.getDriver().switchTo().window(secondWindowHandle);
    }
}

Then use it in both methods:

@Then("User open new tab")
public void user_open_new_tab() {
    ((JavascriptExecutor) baseTest.getDriver()).executeScript("window.open('" + baseTest.url + "')");
    switchToSecondWindow();
}
ui-test/src/main/java/pages/HomePage.java (2)

198-198: Consider making the selector more specific to avoid positional indexing.

The indexed XPath (//div[@data-testid='HeaderTile-Text'])[1] suggests multiple elements share the same data-testid. Position-based selectors are fragile and can break if the DOM structure changes or elements are reordered.

If possible, use a more specific data-testid value that uniquely identifies this element, or add additional context to the XPath (e.g., parent container constraints).


115-115: Use data-testid attribute instead of text-based selector for consistency.

The text-based selector //button[text()='Go To Home'] is fragile and inconsistent with the rest of the file's approach:

  • Breaks with text changes or internationalization
  • Sensitive to whitespace variations
  • All other selectors in this file use data-testid attributes

Consider updating the HTML to add a data-testid attribute and use it here for consistency and maintainability.

♻️ Proposed refactor

If the button has or can have a data-testid attribute (e.g., data-testid='Go-To-Home-Button'), use:

-return isElementIsVisible(driver, By.xpath("//button[text()='Go To Home']"));
+return isElementIsVisible(driver, By.xpath("//button[@data-testid='Go-To-Home-Button']"));
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4c7129 and 0d7614e.

📒 Files selected for processing (7)
  • ui-test/src/main/java/pages/FaqPage.java
  • ui-test/src/main/java/pages/HomePage.java
  • ui-test/src/main/java/pages/Loginpage.java
  • ui-test/src/main/java/pages/MosipCredentials.java
  • ui-test/src/main/java/pages/SunbirdCredentials.java
  • ui-test/src/main/java/stepdefinitions/StepDef.java
  • ui-test/src/main/java/stepdefinitions/StepDefOIDCLogin.java
💤 Files with no reviewable changes (1)
  • ui-test/src/main/java/stepdefinitions/StepDefOIDCLogin.java
🔇 Additional comments (8)
ui-test/src/main/java/pages/SunbirdCredentials.java (1)

30-30: LGTM! XPath selectors improved with specific element tags.

The refactoring from wildcard selectors (//*) to specific div elements improves selector specificity, performance, and maintainability. These changes align with Selenium best practices.

Also applies to: 71-71

ui-test/src/main/java/pages/Loginpage.java (1)

251-251: LGTM! Back arrow selectors correctly target button elements.

Replacing the wildcard selector with explicit button tags ensures the correct element type is targeted and improves test stability.

Also applies to: 279-279

ui-test/src/main/java/stepdefinitions/StepDef.java (1)

1087-1104: Consistent window handling with user_open_new_tab.

The logic correctly mirrors the approach in user_open_new_tab, ensuring consistent window switching behavior across test steps.

ui-test/src/main/java/pages/MosipCredentials.java (3)

51-51: LGTM! Specific div selector for credential container.

Replacing the wildcard with div improves selector precision while maintaining the same functionality for extracting the PDF name.


63-67: LGTM! Button selectors correctly updated.

Both button IDs (login_with_otp and get_otp) now explicitly target button elements, improving selector specificity and reducing the risk of matching incorrect elements.


75-75: LGTM! Paragraph selector for description text.

Using //p instead of //* correctly targets the paragraph element containing the download result description.

ui-test/src/main/java/pages/FaqPage.java (2)

22-22: LGTM! Semantic HTML tags for FAQ content.

Using p for content text and h3 for title text aligns with proper semantic HTML structure and improves selector reliability.

Also applies to: 26-26


30-30: LGTM! Button selectors for FAQ arrow interactions.

All arrow-related selectors now explicitly target button elements, which is semantically correct for interactive controls and improves test stability.

Also applies to: 34-34, 39-39, 44-44

@iamlokanath iamlokanath changed the title refactor(ui-test): cleanup xpath selectors and window handling INJIWEB:1609 refactor(ui-test): cleanup xpath selectors and window handling Jan 27, 2026
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.

1 participant