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

Fix Ruby code generation #1879

Closed
wants to merge 2 commits into from
Closed

Conversation

cmburn
Copy link

@cmburn cmburn commented Dec 10, 2024

User description

Thanks for contributing to the Selenium IDE!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Currently, generated Ruby code can't be properly run if it utilizes certain (common) features, namely it tries to invoke
move_to_element, which is valid in Python's selenium binding, but not ruby's. The correct function is simply move_to.

RSpec should also be qualified in the top level describe during code generation, or it can cause issues.

Motivation and Context

Generated code is currently broken for Ruby/RSpec.

Types of changes

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [ x] I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix, Enhancement


Description

  • Fixed the Ruby code generation by replacing the incorrect move_to_element method with the correct move_to method for mouse actions.
  • Enhanced the Ruby/RSpec code generation by qualifying describe with RSpec to prevent potential issues.

Changes walkthrough 📝

Relevant files
Bug fix
command.js
Fix Ruby mouse action methods in code generation                 

packages/code-export-ruby-rspec/src/command.js

  • Replaced move_to_element with move_to for Ruby compatibility.
  • Updated mouse action commands to use the correct Ruby method.
  • +4/-4     
    Enhancement
    index.js
    Qualify RSpec describe in Ruby code generation                     

    packages/code-export-ruby-rspec/src/index.js

    • Qualified describe with RSpec in Ruby code generation.
    +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @CLAassistant
    Copy link

    CLA assistant check
    Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


    cmburn seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
    You have signed the CLA already but the status is still pending? Let us recheck it.

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    API Compatibility
    Verify that the Ruby Selenium WebDriver API documentation confirms that move_to is the correct method name and that it accepts the same parameters as the previous move_to_element

    Framework Integration
    Confirm that explicitly qualifying describe with RSpec namespace is the recommended approach and won't cause issues with different RSpec configurations

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Implement explicit wait before mouse actions to ensure element interactivity

    Add wait mechanism before mouse actions to ensure the element is not only present
    but also interactive.

    packages/code-export-ruby-rspec/src/command.js [430-441]

     async function emitMouseMove(locator) {
       const commands = [
         {
           level: 0,
    -      statement: `element = @driver.find_element(${await location.emit(locator)})`,
    +      statement: `wait = Selenium::WebDriver::Wait.new(timeout: 10)`,
    +    },
    +    {
    +      level: 0,
    +      statement: `element = wait.until { @driver.find_element(${await location.emit(locator)}) }`,
         },
         { level: 0, statement: '@driver.action.move_to(element).perform' },
       ]
       return Promise.resolve({ commands })
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding explicit waits is crucial for test stability in dynamic web applications, as it ensures elements are not just present but fully interactive before performing mouse actions.

    8
    Add validation to ensure the element exists before performing mouse actions

    Add error handling for when element is not found before performing mouse actions.
    The current code assumes the element exists but could throw an exception if not
    found.

    packages/code-export-ruby-rspec/src/command.js [413-428]

     async function emitMouseDown(locator) {
       const commands = [
         {
           level: 0,
           statement: `element = @driver.find_element(${await location.emit(locator)})`,
    +    },
    +    {
    +      level: 0,
    +      statement: 'raise "Element not found" if element.nil?',
         },
         {
           level: 0,
           statement: '@driver.action.move_to(element).click_and_hold.perform',
         },
       ]
       return Promise.resolve({ commands })
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding element existence validation is important for preventing runtime errors and providing clearer error messages when elements are not found, which improves test reliability and debugging.

    7

    💡 Need additional feedback ? start a PR chat

    @cmburn cmburn closed this by deleting the head repository Dec 10, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants