SeleniumHQ / seleniumhq.github.io

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

[rb] Move examples for ruby elements interactions #1815

Closed aguspe closed 1 month ago

aguspe commented 1 month ago

User description

Description

This PR moves the examples for ruby regarding element interactions

Motivation and Context

It's important to make our documentation more maintainable for future contributors to keep the examples up to date

Types of changes

Checklist


PR Type

Documentation, Enhancement


Description


Changes walkthrough 📝

Relevant files
Enhancement
interaction_spec.rb
Add RSpec tests for element interactions in Ruby                 

examples/ruby/spec/elements/interaction_spec.rb
  • Added a new RSpec test for clicking an element.
  • Added a new RSpec test for clearing and sending keys to an element.
  • Included a before block to navigate to a specific URL before each
    test.
  • +11/-0   
    Documentation
    interactions.en.md
    Update Ruby interaction examples to use RSpec tests           

    website_and_docs/content/documentation/webdriver/elements/interactions.en.md
  • Updated Ruby code examples to reference new RSpec tests.
  • Removed inline Ruby code and replaced with links to the new examples.
  • +9/-31   
    interactions.ja.md
    Update Ruby interaction examples to use RSpec tests (Japanese)

    website_and_docs/content/documentation/webdriver/elements/interactions.ja.md
  • Updated Ruby code examples to reference new RSpec tests.
  • Removed inline Ruby code and replaced with links to the new examples.
  • +9/-30   
    interactions.pt-br.md
    Update Ruby interaction examples to use RSpec tests (Portuguese)

    website_and_docs/content/documentation/webdriver/elements/interactions.pt-br.md
  • Updated Ruby code examples to reference new RSpec tests.
  • Removed inline Ruby code and replaced with links to the new examples.
  • +9/-30   
    interactions.zh-cn.md
    Update Ruby interaction examples to use RSpec tests (Chinese)

    website_and_docs/content/documentation/webdriver/elements/interactions.zh-cn.md
  • Updated Ruby code examples to reference new RSpec tests.
  • Removed inline Ruby code and replaced with links to the new examples.
  • +9/-30   

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

    netlify[bot] commented 1 month ago

    Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    Latest commit cf2d31505fb4c6b8a840589a6d39478aff93a48b
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ No key issues to review
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Performance
    Store the result of repeated element lookups in a variable for reuse ___ **To avoid locating the same element multiple times, store the result of
    driver.find_element(name: 'email_input') in a variable and reuse it for both clear
    and send_keys operations. This reduces the number of WebDriver calls, improving test
    performance and readability.** [examples/ruby/spec/elements/interaction_spec.rb [15-16]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1815/files#diff-052780b3021b3424286fd0c7da70a500124568d1dbd1a62e38e84e78770af8aaR15-R16) ```diff -driver.find_element(name: 'email_input').clear -driver.find_element(name: 'email_input').send_keys 'admin@localhost.dev' +email_input = driver.find_element(name: 'email_input') +email_input.clear +email_input.send_keys 'admin@localhost.dev' ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: This suggestion improves performance and readability by reducing the number of WebDriver calls. It is a good practice to store the result of repeated element lookups in a variable.
    9
    Robustness
    Add error handling for element interaction commands ___ **Consider adding error handling for the click and send_keys operations to manage
    exceptions that might occur if elements are not found or are not interactable.** [examples/ruby/spec/elements/interaction_spec.rb [11-16]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1815/files#diff-052780b3021b3424286fd0c7da70a500124568d1dbd1a62e38e84e78770af8aaR11-R16) ```diff -driver.find_element(name: 'color_input').click -driver.find_element(name: 'email_input').send_keys 'admin@localhost.dev' +begin + driver.find_element(name: 'color_input').click + email_input = driver.find_element(name: 'email_input') + email_input.clear + email_input.send_keys 'admin@localhost.dev' +rescue Selenium::WebDriver::Error::NoSuchElementError => e + puts "Element not found: #{e}" +end ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Adding error handling improves the robustness of the test by managing exceptions that might occur if elements are not found or are not interactable. This is important for reliable test execution.
    8