Skip to content
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

Added more detail to Avoid Sharing State Documentation #1948

Merged
merged 6 commits into from
Sep 23, 2024

Conversation

shbenzer
Copy link
Contributor

@shbenzer shbenzer commented Sep 17, 2024

User description

Added some more details to Avoid Sharing States in Encouraged Practices in Testing Practices

Description

updated index.md in all languages with more details regarding Avoid Sharing State in Testing Practices

Motivation and Context

More comprehensive documentation

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

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Documentation


Description

  • Enhanced the "Avoid Sharing State" section in the documentation across multiple languages.
  • Added detailed instructions on using pytest to manage WebDriver instances for test isolation.
  • Updated English, Japanese, Portuguese, and Chinese documentation to include guidance on using global fixtures with pytest.

Changes walkthrough 📝

Relevant files
Documentation
avoid_sharing_state.en.md
Enhance English documentation with `pytest` usage for test isolation

website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.en.md

  • Added guidance on using pytest for test isolation.
  • Suggested using a global fixture to manage WebDriver instances.
  • +5/-0     
    avoid_sharing_state.ja.md
    Update Japanese documentation with `pytest` guidance         

    website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.ja.md

  • Added instructions for using pytest in Japanese documentation.
  • Explained the use of global fixtures for WebDriver management.
  • +2/-0     
    avoid_sharing_state.pt-br.md
    Add `pytest` instructions to Portuguese documentation       

    website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.pt-br.md

  • Included pytest usage details in Portuguese documentation.
  • Described global fixture use for WebDriver instances.
  • +2/-0     
    avoid_sharing_state.zh-cn.md
    Enhance Chinese documentation with `pytest` usage details

    website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.zh-cn.md

  • Provided pytest usage information in Chinese documentation.
  • Discussed global fixture for managing WebDriver instances.
  • +2/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    netlify bot commented Sep 17, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit d15573a

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added documentation Improvements or additions to documentation Review effort [1-5]: 2 labels Sep 17, 2024
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No key issues to review

    Copy link
    Contributor

    codiumai-pr-agent-pro bot commented Sep 17, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Add a code example to illustrate the use of a global fixture for WebDriver instances in pytest

    Consider adding a code example to demonstrate how to create a global fixture for
    WebDriver instances using pytest. This will make it easier for readers to implement
    the suggested practice.

    website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.en.md [25-28]

     * If you choose [pytest](https://pytest.org/) as your test runner, this can be 
     easily done by yielding your driver in a global fixture. This way each test gets its own 
     driver instance, and you can ensure that drivers always quit after a test is finished 
    -(pass or fail).
    +(pass or fail). Here's an example:
     
    +```python
    +import pytest
    +from selenium import webdriver
    +
    +@pytest.fixture(scope="function")
    +def driver():
    +    driver = webdriver.Chrome()
    +    yield driver
    +    driver.quit()
    +
    +def test_example(driver):
    +    driver.get("https://www.example.com")
    +    assert "Example" in driver.title
    +```
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a code example significantly enhances the clarity and usability of the documentation, making it easier for readers to implement the suggested practice.

    8
    Expand on the benefits of using a global fixture for test isolation and parallelization

    Consider adding more context about why using a global fixture is beneficial for test
    isolation and parallelization. This will help readers understand the importance of
    this practice.

    website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.ja.md [23]

    -* もしテストランナーとして[pytest](https://pytest.org/)を選ぶ場合、グローバルフィクスチャでドライバーを返すことで簡単に実行できます。この方法を使えば、各テストが独自のドライバーインスタンスを取得し、テストが終了した後(成功・失敗にかかわらず)常にドライバーが終了することを保証できます.
    +* もしテストランナーとして[pytest](https://pytest.org/)を選ぶ場合、グローバルフィクスチャでドライバーを返すことで簡単に実行できます。この方法を使えば、各テストが独自のドライバーインスタンスを取得し、テストが終了した後(成功・失敗にかかわらず)常にドライバーが終了することを保証できます。これにより、テスト間の独立性が高まり、並列実行時の問題を防ぐことができます。また、各テストが新しいドライバーインスタンスを使用することで、前のテストの状態が次のテストに影響を与えることを防ぎ、より信頼性の高いテスト結果を得ることができます。
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Providing additional context about the benefits of using global fixtures helps readers understand the importance of the practice, improving the documentation's educational value.

    7
    Explain the concept of fixtures in pytest to provide context for the suggested practice

    Consider adding a brief explanation of what a fixture is in pytest, as some readers
    might not be familiar with this concept. This will help in better understanding the
    suggested practice.

    website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.zh-cn.md [23]

    -* 如果你选择 [pytest](https://pytest.org/) 作为你的测试运行器,可以通过在全局 fixture 中返回你的驱动程序轻松完成。这样,每个测试都会获得自己的驱动程序实例,并且可以确保测试完成后(无论通过还是失败)驱动程序始终会退出
    +* 如果你选择 [pytest](https://pytest.org/) 作为你的测试运行器,可以通过在全局 fixture 中返回你的驱动程序轻松完成。在 pytest 中,fixture 是一种提供测试数据或对象的机制,可以在多个测试中重复使用。通过使用全局 fixture,你可以:
    +  - 确保每个测试都会获得自己的驱动程序实例
    +  - 保证测试完成后(无论通过还是失败)驱动程序始终会退出
    +  - 简化测试代码,减少重复的设置和清理操作
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Explaining the concept of fixtures is beneficial for readers who may not be familiar with pytest, thereby improving comprehension and the overall effectiveness of the documentation.

    7
    Best practice
    Add information about potential pitfalls when using global fixtures for WebDriver instances

    Consider adding information about potential pitfalls or common mistakes when using
    global fixtures, to help readers avoid issues in their implementation.

    website_and_docs/content/documentation/test_practices/encouraged/avoid_sharing_state.pt-br.md [25]

    -* Se você escolher o [pytest](https://pytest.org/) como seu executor de testes, isso pode ser facilmente feito retornando seu driver em um fixture global. Dessa forma, cada teste terá sua própria instância de driver, e você pode garantir que os drivers sempre sejam encerrados após a conclusão de um teste (seja ele aprovado ou reprovado)
    +* Se você escolher o [pytest](https://pytest.org/) como seu executor de testes, isso pode ser facilmente feito retornando seu driver em um fixture global. Dessa forma, cada teste terá sua própria instância de driver, e você pode garantir que os drivers sempre sejam encerrados após a conclusão de um teste (seja ele aprovado ou reprovado). Ao implementar isso, tenha cuidado para:
    +  - Não compartilhar estado entre testes através do fixture
    +  - Garantir que o driver seja sempre fechado, mesmo em caso de erros
    +  - Não criar dependências desnecessárias entre testes que usam o mesmo fixture
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Highlighting potential pitfalls and common mistakes can prevent implementation errors, enhancing the reliability of the tests and the documentation's practical utility.

    6

    💡 Need additional feedback ? start a PR chat

    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

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

    Thank you @shbenzer !

    @harsha509 harsha509 merged commit e1fa2da into SeleniumHQ:trunk Sep 23, 2024
    3 checks passed
    selenium-ci added a commit that referenced this pull request Sep 23, 2024
    … site]
    
    * added more detail to Avoid
    
    * put back in English - to be tagged for translation
    
    * put back in English - to be tagged for translation
    
    * put back in English - to be tagged for translation e1fa2da
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation Review effort [1-5]: 2
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants