SeleniumHQ / seleniumhq.github.io

Official Selenium website and documentation
https://selenium.dev
Apache License 2.0
1.07k stars 1.27k forks source link

Add all special features examples for edge using ruby #1740

Closed aguspe closed 3 months ago

aguspe commented 3 months ago

User description

Description

This PR adds extra tests to the edge spec file to add examples of special features in the browser, this PR is similar to #1711 and the related PRs

Motivation and Context

Is important that all of the users and community member have access to examples so they can easily start automating and working with Selenium

Types of changes

Checklist


PR Type

Tests, Documentation


Description


Changes walkthrough πŸ“

Relevant files
Tests
edge_spec.rb
Add tests for special features in Edge browser using Ruby

examples/ruby/spec/browsers/edge_spec.rb
  • Added tests for casting, network conditions, browser logs, and
    permissions.
  • Introduced helper method permission to check permissions.
  • +46/-0   
    Documentation
    edge.en.md
    Update Ruby code examples links in Edge documentation (EN)

    website_and_docs/content/documentation/webdriver/browsers/edge.en.md
  • Updated Ruby code examples to link to specific lines in edge_spec.rb.
  • +4/-4     
    edge.ja.md
    Update Ruby code examples links in Edge documentation (JA)

    website_and_docs/content/documentation/webdriver/browsers/edge.ja.md
  • Updated Ruby code examples to link to specific lines in edge_spec.rb.
  • +4/-4     
    edge.pt-br.md
    Update Ruby code examples links in Edge documentation (PT-BR)

    website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md
  • Updated Ruby code examples to link to specific lines in edge_spec.rb.
  • +4/-4     
    edge.zh-cn.md
    Update Ruby code examples links in Edge documentation (ZH-CN)

    website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md
  • Updated Ruby code examples to link to specific lines in edge_spec.rb.
  • +4/-4     

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

    netlify[bot] commented 3 months ago

    Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    Latest commit a18c26c78886b1408f6a10de16ce6ab1b91dd015
    codiumai-pr-agent-pro[bot] commented 3 months ago

    PR Review πŸ”

    ⏱️ Estimated effort to review [1-5] 2, because the PR involves adding new test cases and updating documentation, which are generally straightforward to review. The changes are well-documented and localized to specific functionalities.
    πŸ§ͺ Relevant tests Yes
    ⚑ Possible issues Possible Bug: The `permission` method in `edge_spec.rb` uses an asynchronous script to query permissions but does not handle the asynchronous nature in the test assertions. This might lead to flaky tests if the permissions state is not retrieved in time.
    Hardcoded Sleep: The test 'gets the browser logs' uses `sleep 1` which might lead to non-deterministic behavior and could fail if the page takes longer to load. Consider using explicit waits to ensure the page and logs are fully loaded.
    πŸ”’ Security concerns No
    codiumai-pr-agent-pro[bot] commented 3 months ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use a before block to initialize the driver once for all tests within the describe block ___ **To avoid repeatedly initializing the @driver in each test case, consider using a before
    block to set up the driver once for all tests within the 'Special Features' describe
    block.** [examples/ruby/spec/browsers/edge_spec.rb [117-135]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1740/files#diff-ce732d879039536c913cb3187ea74e6fa652d45886994b9d4c159319e57f1b20R117-R135) ```diff +before(:each) do + @driver = Selenium::WebDriver.for :edge +end + it 'casts' do - @driver = Selenium::WebDriver.for :edge sinks = @driver.cast_sinks unless sinks.empty? device_name = sinks.first['name'] @driver.start_cast_tab_mirroring(device_name) expect { @driver.stop_casting(device_name) }.not_to raise_exception end end ... it 'gets and sets network conditions' do - @driver = Selenium::WebDriver.for :edge @driver.network_conditions = {offline: false, latency: 100, throughput: 200} expect(@driver.network_conditions).to eq( 'offline' => false, 'latency' => 100, 'download_throughput' => 200, 'upload_throughput' => 200) end ```
    Suggestion importance[1-10]: 8 Why: This suggestion correctly identifies a repeated pattern of initializing `@driver` in each test case and proposes a more efficient setup using a `before` block, which is a best practice in test automation for reducing redundancy and improving test execution time.
    8
    Add an after block to quit the driver after each test to avoid resource leaks ___ **Ensure the @driver is properly quit after each test to avoid resource leaks by adding an
    after block to quit the driver.** [examples/ruby/spec/browsers/edge_spec.rb [116-155]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1740/files#diff-ce732d879039536c913cb3187ea74e6fa652d45886994b9d4c159319e57f1b20R116-R155) ```diff describe 'Special Features' do + before(:each) do + @driver = Selenium::WebDriver.for :edge + end + + after(:each) do + @driver.quit + end + it 'casts' do - @driver = Selenium::WebDriver.for :edge ... end ... end ```
    Suggestion importance[1-10]: 8 Why: The suggestion to add an `after` block to quit the driver is crucial for resource management and avoiding leaks, which is particularly important in automated testing environments. This is a best practice for maintaining clean test states.
    8
    Performance
    Replace sleep with WebDriverWait to ensure the page has loaded before retrieving logs ___ **Replace the sleep 1 statement with a more reliable wait mechanism, such as WebDriverWait,
    to ensure the page has loaded before retrieving logs.** [examples/ruby/spec/browsers/edge_spec.rb [139-141]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1740/files#diff-ce732d879039536c913cb3187ea74e6fa652d45886994b9d4c159319e57f1b20R139-R141) ```diff @driver.navigate.to 'https://www.selenium.dev/selenium/web/' -sleep 1 +wait = Selenium::WebDriver::Wait.new(timeout: 10) +wait.until { @driver.execute_script('return document.readyState') == 'complete' } logs = @driver.logs.get(:browser) ```
    Suggestion importance[1-10]: 7 Why: Replacing `sleep` with `WebDriverWait` is a valid improvement for making the test more reliable by ensuring the page is fully loaded. This change enhances the robustness of the test.
    7
    Possible issue
    Add error handling for the @driver.cast_sinks method to manage potential exceptions ___ **Add error handling for the @driver.cast_sinks method to manage potential exceptions that
    might occur when fetching cast sinks.** [examples/ruby/spec/browsers/edge_spec.rb [119-124]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1740/files#diff-ce732d879039536c913cb3187ea74e6fa652d45886994b9d4c159319e57f1b20R119-R124) ```diff -sinks = @driver.cast_sinks -unless sinks.empty? - device_name = sinks.first['name'] - @driver.start_cast_tab_mirroring(device_name) - expect { @driver.stop_casting(device_name) }.not_to raise_exception +begin + sinks = @driver.cast_sinks + unless sinks.empty? + device_name = sinks.first['name'] + @driver.start_cast_tab_mirroring(device_name) + expect { @driver.stop_casting(device_name) }.not_to raise_exception + end +rescue StandardError => e + puts "Error fetching cast sinks: #{e.message}" end ```
    Suggestion importance[1-10]: 6 Why: Adding error handling for potential exceptions from `@driver.cast_sinks` is a good practice to prevent test failures from unhandled errors. This suggestion improves the resilience of the test code.
    6