-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Moved javascript code examples for element locators into test files #2312
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
base: trunk
Are you sure you want to change the base?
Moved javascript code examples for element locators into test files #2312
Conversation
👷 Deploy request for selenium-dev pending review.Visit the deploys page to approve it
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I have found that declaring the URL only once in the first test helps and it can persist in the next set of lines. An alternative is also putting
driver.get
in the before block for refined consistency.
before(async function () {
driver = new Builder()
.forBrowser(Browser.CHROME)
.build();
});
after(async () => await driver.quit());
it('should locate element by class name', async function () {
await driver.get('https://www.selenium.dev/selenium/web/locators_tests/locators.html');
const loc = await driver.findElement(By.className('information'));
assert.equal(await loc.getTagName(), "input")
});
it("should locate element by css selector", async function () {
const loc = await driver.findElement(By.css('#fname'));
assert.equal(await loc.getAttribute("value"), "Jane")
})
```
Other blocks of code in the documentation do show the relevant code only: https://www.selenium.dev/documentation/webdriver/elements/interactions/. It's alot cleaner in my opinion than including the URL in the documentation.
2. Putting `text=true` in tab header ensures correct rendering on the browser as follows:
```md
{{< tab header="JavaScript" text=true >}}
```
Lastly, I think we are required to update the translated markdown code as well.
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:
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
Checklist
PR Type
Tests, Documentation
Description
Added comprehensive JavaScript tests for all element locator strategies.
Updated documentation to reference tested code examples via
gh-codeblock
.Fixed minor typo in checkbox test comment.
Changes walkthrough 📝
locators.spec.js
Add JavaScript tests for all element locator strategies
examples/javascript/test/elements/locators.spec.js
linkText, and partialLinkText.
locators.en.md
Reference tested JavaScript locator examples in documentation
website_and_docs/content/documentation/webdriver/elements/locators.en.md
gh-codeblock
referencing newtest file.
information.spec.js
Fix typo and formatting in element information test
examples/javascript/test/elements/information.spec.js