Skip to content

added cookie ruby file #2303

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

Merged
merged 8 commits into from
May 6, 2025

Conversation

pallavigitwork
Copy link
Member

@pallavigitwork pallavigitwork commented May 6, 2025

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.

added cookie ruby file

Description

added cookie ruby file

Motivation and Context

added cookie ruby file

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

Tests


Description

  • Add comprehensive RSpec tests for cookie management in Ruby

  • Test adding, retrieving, and deleting cookies via WebDriver

  • Ensure correct behavior for single and multiple cookies

  • Validate error handling for deleted cookies


Changes walkthrough 📝

Relevant files
Tests
cookies_spec.rb
Add and validate cookie management tests in Ruby                 

examples/ruby/spec/interactions/cookies_spec.rb

  • Added multiple RSpec test cases for cookie operations
  • Covered adding, retrieving (single/all), and deleting cookies
  • Included assertions for correct cookie values and error handling
  • Improved code formatting and lint compliance
  • +56/-1   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    netlify bot commented May 6, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 57df7e0

    Copy link
    Contributor

    qodo-merge-pro bot commented May 6, 2025

    PR Reviewer Guide 🔍

    (Review updated until commit 946188b)

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    @pallavigitwork
    Copy link
    Member Author

    Will add in document later. just added code file as of now.

    Copy link
    Contributor

    qodo-merge-pro bot commented May 6, 2025

    PR Code Suggestions ✨

    Latest suggestions up to 946188b
    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Add error case testing

    Add error handling for the case when the named cookie doesn't exist. The current
    test only verifies the happy path, but should also test the error case to ensure
    proper exception handling.

    examples/ruby/spec/interactions/cookies_spec.rb [16-23]

     it 'gets a named cookie' do
       driver.navigate.to 'https://www.selenium.dev/selenium/web/blank.html'
       # Add cookie into current browser context
       driver.manage.add_cookie(name: 'foo', value: 'bar')
       # Get cookie details with named cookie 'foo'
       cookie = driver.manage.cookie_named('foo')
       expect(cookie[:value]).to eq('bar')
    +  
    +  # Verify error is raised for non-existent cookie
    +  expect { driver.manage.cookie_named('non_existent') }.to raise_error(Selenium::WebDriver::Error::NoSuchCookieError)
     end
    • Apply / Chat
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion improves test coverage by adding a negative test case for retrieving a non-existent cookie. This enhances the robustness of the new tests, aligning with the PR's goal of adding comprehensive cookie operation tests.

    Medium
    • Update

    Previous suggestions

    Suggestions up to commit 8a026cf
    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Check for nil values

    Add a check to verify that both cookies are found. If either test1_cookie or
    test2_cookie is nil, the test will fail with a nil reference error when
    accessing [:value] rather than a clear assertion failure.

    examples/ruby/spec/interactions/cookies_spec.rb [27-42]

     it 'gets all cookies' do
       driver.navigate.to "https://www.selenium.dev/selenium/web/blank.html"
       # Add cookies into current browser context
       driver.manage.add_cookie(name: "test1", value: "cookie1")
       driver.manage.add_cookie(name: "test2", value: "cookie2")
       
       # Get cookies
       cookies = driver.manage.all_cookies
       
       # Verify both cookies exist with correct values
       test1_cookie = cookies.find { |c| c[:name] == "test1" }
       test2_cookie = cookies.find { |c| c[:name] == "test2" }
       
    +  expect(test1_cookie).not_to be_nil
    +  expect(test2_cookie).not_to be_nil
       expect(test1_cookie[:value]).to eq("cookie1")
       expect(test2_cookie[:value]).to eq("cookie2")
     end
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion improves test clarity. Adding checks for nil before accessing [:value] on test1_cookie and test2_cookie provides a more specific assertion failure if a cookie is not found, rather than a less informative nil reference error.

    Low

    @pallavigitwork pallavigitwork self-assigned this May 6, 2025
    @pallavigitwork
    Copy link
    Member Author

    lint issues fixed. test run in some, failing in other - for other reason than code.

    @pallavigitwork pallavigitwork merged commit f4f0d98 into SeleniumHQ:trunk May 6, 2025
    7 of 10 checks passed
    @pallavigitwork
    Copy link
    Member Author

    will add snippets to document later.

    @diemol diemol mentioned this pull request May 8, 2025
    6 tasks
    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.

    1 participant