seleniumhq.github.io icon indicating copy to clipboard operation
seleniumhq.github.io copied to clipboard

Start adding special features examples

Open aguspe opened this issue 1 year ago • 1 comments

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.

Description

Motivation and Context

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.

aguspe avatar May 07 '24 16:05 aguspe

Deploy request for selenium-dev pending review.

Visit the deploys page to approve it

Name Link
Latest commit 6b08dee16568c374f8b73e6b807cfd55f10f8b85

netlify[bot] avatar May 07 '24 16:05 netlify[bot]

PR Description updated to latest commit (https://github.com/SeleniumHQ/seleniumhq.github.io/commit/bbdc626b28449199b8d4ee208691332b750fa50c)

qodo-code-review[bot] avatar May 08 '24 14:05 qodo-code-review[bot]

PR Review 🔍

⏱️ Estimated effort to review [1-5]

2, because the PR primarily involves adding a new example for a specific feature in Ruby and updating documentation across multiple languages to reference this new example. The changes are straightforward and localized, making the review process relatively quick and easy.

🧪 Relevant tests

Yes

⚡ Possible issues

Possible Bug: The code checks if the list of sinks is empty but does not handle the scenario where @driver.cast_sinks might return nil or an unexpected value, which could lead to errors when attempting to access sinks.first['name'].

🔒 Security concerns

No

qodo-code-review[bot] avatar May 08 '24 14:05 qodo-code-review[bot]

PR Code Suggestions ✨

CategorySuggestions                                                                                                                                                       
Best practice
Add an after block to properly close the WebDriver after each test.

To ensure that the @driver instance is properly cleaned up and closed after each test,
it's recommended to use an after block to quit the driver. This prevents resource leakage
and ensures that each test runs in a clean state.

examples/ruby/spec/browsers/chrome_spec.rb [118-124]

 @driver = Selenium::WebDriver.for :chrome
 @driver.cast_sinks
 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
+after(:each) do
+  @driver.quit
+end
 
Specify the type of exception expected in the test for clarity.

To improve the exception handling, specify the type of exception you expect not to be
raised in the test. This makes the test more precise and easier to understand.

examples/ruby/spec/browsers/chrome_spec.rb [124]

-expect { @driver.stop_casting(device_name) }.not_to raise_exception
+expect { @driver.stop_casting(device_name) }.not_to raise_error
 
Performance
Reduce redundant WebDriver calls by reusing the result stored in a variable.

Instead of calling @driver.cast_sinks twice, store the result in a variable and reuse it.
This reduces unnecessary calls to the WebDriver, which can improve the performance of the
tests.

examples/ruby/spec/browsers/chrome_spec.rb [119-120]

[email protected]_sinks
 sinks = @driver.cast_sinks
 
Maintainability
Use a more descriptive variable name for the list of casting devices.

To improve the readability and maintainability of the test, consider using a more
descriptive variable name than sinks for the list of casting devices.

examples/ruby/spec/browsers/chrome_spec.rb [120]

-sinks = @driver.cast_sinks
+casting_devices = @driver.cast_sinks
 
Enhancement
Add an assertion to ensure the list of sinks is not empty before proceeding with the test.

To ensure that the test is more robust, add an assertion to check that the list of sinks
is not empty before proceeding with the test. This helps in identifying issues with the
setup or environment early.

examples/ruby/spec/browsers/chrome_spec.rb [121-124]

+expect(sinks).not_to be_empty
 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
 

qodo-code-review[bot] avatar May 08 '24 14:05 qodo-code-review[bot]

HI @aguspe,

Can we just include code from L119-L122 Or L124?

Hi @harsha509 thank you so much for the question, I think the best is still L119-L124 because in the current implementation if people try just to use @driver.cast_sinks it will actually not work

I made a question regarding this on the slack channel to see how much we needed to expand the example for the users, here is the message: https://seleniumhq.slack.com/archives/C0K0BK8MQ/p1715280896233389

aguspe avatar May 10 '24 06:05 aguspe

HI @aguspe, Can we just include code from L119-L122 Or L124?

Hi @harsha509 thank you so much for the question, I think the best is still L119-L124 because in the current implementation if people try just to use @driver.cast_sinks it will actually not work

I made a question regarding this on the slack channel to see how much we needed to expand the example for the users, here is the message: https://seleniumhq.slack.com/archives/C0K0BK8MQ/p1715280896233389

L119-L124 looks fine to me...

harsha509 avatar May 10 '24 06:05 harsha509

HI @aguspe, Can we just include code from L119-L122 Or L124?

Hi @harsha509 thank you so much for the question, I think the best is still L119-L124 because in the current implementation if people try just to use @driver.cast_sinks it will actually not work I made a question regarding this on the slack channel to see how much we needed to expand the example for the users, here is the message: https://seleniumhq.slack.com/archives/C0K0BK8MQ/p1715280896233389

L119-L124 looks fine to me...

Perfect thank you so much @harsha509, let me know if there are other questions

aguspe avatar May 10 '24 07:05 aguspe