seleniumhq.github.io
seleniumhq.github.io copied to clipboard
Moved javascript code examples for element locators into test files
User description
Description
This PR moves all JavaScript code examples for the following element locators into test files and updates the corresponding documentation to reference those examples using gh-codeblock:
className
cssSelector
id
name
tagName
xpath
linkText
partialLinkText
This ensures all locator examples are tested automatically and reduces duplication. Unfortunately I could not get hugo working with my PAT so I could not preview the changes on the website directly
P.S: This is my first pull request, I really like Selenium so any tips you have would be greatly appreciated!
Motivation and Context
This PR helps integrate the documentation examples for the locators into CI
Types of changes
- [ ] Change to the site (I have double-checked the Netlify deployment, and my changes look good)
- [ ] Code example added (and I also added the example to all translated languages)
- [ ] Improved translation
- [ ] Added new translation (and I also added a notice to each document missing translation)
Checklist
- [x] I have read the contributing document.
- [] I have used hugo to render the site/docs locally and I am sure it works.
PR Type
Tests, Documentation
Description
-
Added comprehensive JavaScript tests for all element locator strategies.
- Covers className, cssSelector, id, name, tagName, xpath, linkText, partialLinkText.
-
Updated documentation to reference tested code examples via
gh-codeblock.- Ensures documentation examples are always tested and up-to-date.
-
Fixed minor typo in checkbox test comment.
Changes walkthrough 📝
| Relevant files | |||
|---|---|---|---|
| Tests |
| ||
| Documentation |
| ||
| Miscellaneous |
|
Need help?
Type /help how to ...in the comments thread for any questions about Qodo Merge usage.Check out the documentation for more information.
Deploy request for selenium-dev pending review.
Visit the deploys page to approve it
| Name | Link |
|---|---|
| Latest commit | 317caa678a50e42dfe454e80d75b6fff6d389867 |
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
| ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪ |
| 🧪 PR contains tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewXPath Mismatch
|
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
Ensure driver cleanupThe test creates a new WebDriver instance for each test but doesn't properly examples/javascript/test/elements/locators.spec.js [65-68]
Suggestion importance[1-10]: 7__ Why: Wrapping the test logic in a try/finally block to guarantee driver cleanup is a good practice that improves test reliability and prevents resource leaks, but it is a standard improvement rather than a critical fix. | Medium |
| General |
Add test timeout configurationThe test suite lacks a timeout configuration, which can lead to test failures in examples/javascript/test/elements/locators.spec.js [1-2]
Suggestion importance[1-10]: 6__ Why: Adding a test timeout helps prevent false negatives in slow environments, improving test robustness, but it is a minor configuration enhancement rather than a major functional change. | Low |
| ||
I could not add the try catch block in the test functions because gh-codeblock does not allow discontinuous lines. Because of this, I could not fit the declaration and definition of the webdriver object before the URL fetch and the relevant element fetch.