seleniumhq.github.io
seleniumhq.github.io copied to clipboard
petesong/Add a Python example for the test practice
User description
Thanks for contributing to the Selenium site and documentation! A PR well described will help maintainers to review and merge it quickly
Before submitting your PR, please check our contributing guidelines. Avoid large PRs, and help reviewers by making them as simple and short as possible.
Description
- Correct the right link of Hugo Installation
- Add a Python example for the test practices.
Motivation and Context
For the test practices, there's no python example.
Types of changes
- [x] Change to the site
- [ ] 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.
- [x] I have used
hugo serverto render the site/docs locally, but failed. Since I only have minor changes in the existing pages, and I am sure it works.
PR Type
Documentation, Tests
Description
- Updated the Hugo installation link in the README to point directly to the official Hugo site, improving clarity and accessibility.
- Added a detailed Python example using pytest and Selenium to the test practices documentation. This example demonstrates best practices with the "ActionBot" and "LoadableComponent" patterns.
- The example includes multiple test cases for interacting with a Todo application, showcasing various functionalities such as adding, toggling, and deleting todos.
Changes walkthrough 📝
| Relevant files | |||
|---|---|---|---|
| Documentation |
| ||
| Tests |
|
💡 PR-Agent usage: Comment
/helpon the PR to get a list of all available PR-Agent tools and their descriptions
Deploy Preview for selenium-dev canceled.
| Name | Link |
|---|---|
| Latest commit | 1f36a5d290a9a5f6e1a0acf4a04d315535ef69fd |
| Latest deploy log | https://app.netlify.com/projects/selenium-dev/deploys/67aaede5febcc1000838045b |
PR Reviewer Guide 🔍
| ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪ |
| 🧪 PR contains tests |
| 🔒 No security concerns identified |
| ⚡ Key issues to review Code Complexity Error Handling Commented Code |
PR Code Suggestions ✨
| Category | Suggestion | Score |
| Best practice |
✅ Use a context manager for WebDriver to ensure proper resource cleanupSuggestion Impact:The suggestion to use a context manager for the WebDriver was implemented, ensuring proper resource cleanup.code diff:
Consider using a context manager for the WebDriver to ensure proper resource website_and_docs/content/documentation/test_practices/design_strategies.en.md [399-404]
Suggestion importance[1-10]: 9Why: This suggestion is a best practice for resource management, ensuring that the WebDriver is properly closed even if an exception occurs, which is crucial for preventing resource leaks. | 9 |
Use specific exception handling instead of a bare except clauseIn the website_and_docs/content/documentation/test_practices/design_strategies.en.md [516-523]
Suggestion importance[1-10]: 8Why: Using specific exceptions improves error handling by avoiding the masking of unexpected exceptions, which is a significant improvement in code robustness. | 8 | |
✅ Add assertions to verify initial state in test methodsSuggestion Impact:An assertion was added to verify the initial state of the todo count in the test method, which aligns with the suggestion to enhance test reliability by ensuring the test environment is correctly set up.code diff:
In the test methods, consider adding assertions to verify the initial state before website_and_docs/content/documentation/test_practices/design_strategies.en.md [571-573]
Suggestion importance[1-10]: 7Why: Adding assertions for initial state verification enhances test reliability by ensuring the test environment is correctly set up, which is a good practice for test accuracy. | 7 | |
| Enhancement |
✅ Convert static method to instance method for consistency and flexibilitySuggestion Impact:The static method build_count_todo_left was converted to an instance method in the TodoPage class.code diff:
Instead of using a static method for website_and_docs/content/documentation/test_practices/design_strategies.en.md [503-507]
Suggestion importance[1-10]: 5Why: While converting the static method to an instance method can improve consistency, it is not critical to the functionality and mainly enhances potential future flexibility. | 5 |
PR Code Suggestions ✨
Category Suggestion Score Best practice ✅ Use a context manager for WebDriver to ensure proper resource cleanup 9 Use specific exception handling instead of a bare except clause 8 ✅ Add assertions to verify initial state in test methods 7 Enhancement ✅ Convert static method to instance method for consistency and flexibility 5
Applied the suggestions.
PR Reviewer Guide 🔍
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪ 🧪 PR contains tests 🔒 No security concerns identified ⚡ Key issues to review
Code ComplexityThe added Python example is quite long and complex. Consider breaking it down into smaller, more manageable sections or separate files for better readability and maintainability.
Error HandlingThe
is_loadedmethod in theTodoPageclass uses a bare except clause, which might catch and suppress unexpected errors. Consider using a more specific exception or at least logging the error.Commented CodeThere is commented out code in the
hovermethod of theActionBotclass. Consider removing it if it's not needed or add a comment explaining why it's kept.
Applied the suggestions.
Thank you for the contribution @PeteSong! Before it can be properly reviewed a few things must be changed:
- the example must be moved into a separate executable file like our other examples
- the example must be properly formatted like other examples to pull from the example file
- the example must be propagated to all translations
- lines must be kept to 100 characters per the style guide https://www.selenium.dev/documentation/about/style/
Thank you for the contribution @PeteSong! Before it can be properly reviewed a few things must be changed:
- the example must be moved into a separate executable file like our other examples
- the example must be properly formatted like other examples to pull from the example file
- the example must be propagated to all translations
- lines must be kept to 100 characters per the style guide https://www.selenium.dev/documentation/about/style/
DONE
Thank you for the contribution @PeteSong! Before it can be properly reviewed a few things must be changed:
- the example must be moved into a separate executable file like our other examples
- the example must be properly formatted like other examples to pull from the example file
- the example must be propagated to all translations
- lines must be kept to 100 characters per the style guide https://www.selenium.dev/documentation/about/style/
DONE
Awesome, thank you! @harsha1502
@PeteSong please resolve conflicts for this PR.
DONE
The merging is blocked, who could help me to merge it?
@shbenzer, @A1exKH , Hope you are doing well.
The merging is blocked for quite a time. What should I do or who could help me to merge it?
Best regards, Peter
@PeteSong hi! You need a review and approval from people, who are contributors to this repository.
Hello @PeteSong, thank you for your contributions!
I have added some review comments, let me know if you have any questions. The main point I'm trying to get across as you refactor the examples is that these are examples - they don't need to be fully fleshed out.
Since you have provided a full seemingly working example in python - what we can instead do is utilize the codeblock architecture:
{{< gh-codeblock path="examples/python/tests/selenium_manager/usage.py#L10-L12" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
{{% tab header="JavaScript" %}}
and therefore use all the code you've written throughout the page (I personally prefer this alternative) - and this way we can keep the java example, as well.
Hi @shbenzer ,
Thanks for your good comment. I have updated them per your suggestion.
DONE!
Best regards, Peter
Hello @PeteSong, thank you for your contributions!
I have added some review comments, let me know if you have any questions. The main point I'm trying to get across as you refactor the examples is that these are examples - they don't need to be fully fleshed out.
Since you have provided a full seemingly working example in python - what we can instead do is utilize the codeblock architecture:
{{< gh-codeblock path="examples/python/tests/selenium_manager/usage.py#L10-L12" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} {{% tab header="JavaScript" %}}and therefore use all the code you've written throughout the page (I personally prefer this alternative) - and this way we can keep the java example, as well.
@shbenzer Hope you are doing well. Could you be kind to review the changes and approve the PR? Thank you very much
Best regards, Peter
Hey @PeteSong this looks good! Only thing I notice atm that needs to be changed is that you're missing the other languages in the codeblock elements. We use those so that readers can see where examples are missing and for ease of contributions.
Hey @shbenzer,
Good suggestion! DONE!
Hey @PeteSong this looks good! Only thing I notice atm that needs to be changed is that you're missing the other languages in the codeblock elements. We use those so that readers can see where examples are missing and for ease of contributions.
LGTM
@harsha509 I don’t seem to have permissions to this repo, could you take a look?
Hi @harsha509, hope you are doing well! Could I trouble you to take some time to review and merge it? Thank you very much.
Alright, now that I have permissions I pulled locally. There's a few more changes that need to be made and you'll be good to go.
- lets put all examples in the codeblock elements
- in the codeblock elements, make sure that each language without an example has a badgecode so we can help facilitate contributions
Alright, now that I have permissions I pulled locally. There's a few more changes that need to be made and you'll be good to go.
- lets put all examples in the codeblock elements
- in the codeblock elements, make sure that each language without an example has a badgecode so we can help facilitate contributions
Hi @shbenzer, for 1), I already put all my examples in the codeblock elements. for 2), what is the badgecode? could you show me an example?
Hi @shbenzer, for 1), I already put all my examples in the codeblock elements.
That's correct! However, now that we're using multiple languages in this document, it'd be best to put the other code examples you didn't alter into codeblocks so the page is consistently formatted.
for 2), what is the badgecode? could you show me an example?
Gladly!
Badge codes have this structure in codeblocks:
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< /tab >}}
and they produce this when rendered:
Clicking the link then takes you to the creating examples section of the contribution guide
Hi @shbenzer, hope you are doing well.
- for now, only one example in Python.
- added the badgecode.
Best regards, Peter
Hi @shbenzer, hope you are doing well.
- for now, only one example in Python.
- added the badgecode.
Best regards, Peter
Regarding 1, that's not what I meant, but it can be done in another PR.
LGTM
Thank you @PeteSong !