Skip to content

[ruby] Try to load older devtools version if current browser version doesn't match#11827

Merged
diemol merged 3 commits intoSeleniumHQ:trunkfrom
arielj:devtools-version-fallback
Mar 28, 2023
Merged

[ruby] Try to load older devtools version if current browser version doesn't match#11827
diemol merged 3 commits intoSeleniumHQ:trunkfrom
arielj:devtools-version-fallback

Conversation

@arielj
Copy link
Copy Markdown
Contributor

@arielj arielj commented Mar 28, 2023

Description

This is an attempt to fix #11651.

This change makes it so, if the devtools version based on the current browser doesn't match, it tries to load an older version of devtools instead.

I added some logs/warnings to alert a user that this is happening, so they know there's something to address.

I only added 2 versions back fallback, I imagine that's plenty enough time until a new devtools release is done matching the proper version but let me know if that's not desired.

I would be happy to add tests for this but I really don't know how to do a test for something like this.

I also have to mention that I was not able to use the gem from a local clone of the repo to really really confirm this is working as expected, I CAN confirm though that the fallback is working to an extent because I can see the messages so it is trying to require older versions if the current one failed:

Could not load selenium-devtools v111. Trying older versions.

# and then the failure

LoadError:
       cannot load such file -- selenium/devtools/v109

Motivation and Context

There's a recurring problem that when chrome gets a new major version update, requiring devtools fails until a new devtools version is released and updated in the Gemfile of the app.

Types of changes

  • 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

  • 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.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 28, 2023

CLA assistant check
All committers have signed the CLA.

@arielj arielj changed the title Try to load older devtools version if current browser version doesn't match [ruby] Try to load older devtools version if current browser version doesn't match Mar 28, 2023
Copy link
Copy Markdown
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @arielj!

@diemol diemol merged commit 82bed10 into SeleniumHQ:trunk Mar 28, 2023
@arielj arielj deleted the devtools-version-fallback branch March 28, 2023 20:07
@rogerkk
Copy link
Copy Markdown

rogerkk commented Mar 29, 2023

From a random user: Thanks, @arielj! ⭐

@robotdana
Copy link
Copy Markdown
Contributor

hi could this be release perhaps as a 0.111.1? thank you :)

@diemol
Copy link
Copy Markdown
Member

diemol commented Apr 6, 2023

This has already been released.

@robotdana
Copy link
Copy Markdown
Contributor

i'm not sure it has. i think the selenium-webdriver gem has had a recent release, but the selenium-devtools gem has not had a release since this was merged.

i have the latest version of selenium-webdriver (4.8.6) and the latest version of selenium-devtools (0.111.0)
and see a LoadError: cannot load such file -- selenium/devtools/v112 when trying to do call a method that requires devtools, which i wouldn't have if this code was in it.

@diemol
Copy link
Copy Markdown
Member

diemol commented Apr 6, 2023

You are right, seems the person who released 4.8.6 did not pull in this change. We are doing a release next week in any case.

robotdana added a commit to robotdana/selenium that referenced this pull request Apr 6, 2023
When using the feature added in SeleniumHQ#11827 that loads devtools methods
possibly a version or two earlier than was necessary asked for, i was
seeing this error:

```
NoMethodError: undefined method `get_targets' for nil:NilClass
./rb/lib/selenium/webdriver/devtools.rb:75:in `start_session'
./rb/lib/selenium/webdriver/devtools.rb:34:in `initialize'
./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `new'
./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `devtools'
```
because `target` was nil because it was trying to load a class named:
```
Selenium::DevTools::V#{Selenium::DevTools.version}::#{method.capitalize}
```
which resolved to:
```
Selenium::DevTools::V112::Target
```
even though the falling-back code had already given up on 112 and loaded
111 instead.

The simplest way to fix this seems to be ensure that
`Selenium::DevTools.version` matches what was loaded.

Also now there's a test
titusfortner pushed a commit that referenced this pull request Apr 7, 2023
Fix ruby devtools version fallback

When using the feature added in #11827 that loads devtools methods
possibly a version or two earlier than was necessary asked for, i was
seeing this error:

```
NoMethodError: undefined method `get_targets' for nil:NilClass
./rb/lib/selenium/webdriver/devtools.rb:75:in `start_session'
./rb/lib/selenium/webdriver/devtools.rb:34:in `initialize'
./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `new'
./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `devtools'
```
because `target` was nil because it was trying to load a class named:
```
Selenium::DevTools::V#{Selenium::DevTools.version}::#{method.capitalize}
```
which resolved to:
```
Selenium::DevTools::V112::Target
```
even though the falling-back code had already given up on 112 and loaded
111 instead.

The simplest way to fix this seems to be ensure that
`Selenium::DevTools.version` matches what was loaded.

Also now there's a test
yashcho pushed a commit to yashcho/selenium that referenced this pull request Apr 7, 2023
…doesn't match (SeleniumHQ#11827)

Try to load older devtools version if current doesn't match

Co-authored-by: Diego Molina <[email protected]>
yashcho pushed a commit to yashcho/selenium that referenced this pull request Apr 7, 2023
Fix ruby devtools version fallback

When using the feature added in SeleniumHQ#11827 that loads devtools methods
possibly a version or two earlier than was necessary asked for, i was
seeing this error:

```
NoMethodError: undefined method `get_targets' for nil:NilClass
./rb/lib/selenium/webdriver/devtools.rb:75:in `start_session'
./rb/lib/selenium/webdriver/devtools.rb:34:in `initialize'
./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `new'
./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `devtools'
```
because `target` was nil because it was trying to load a class named:
```
Selenium::DevTools::V#{Selenium::DevTools.version}::#{method.capitalize}
```
which resolved to:
```
Selenium::DevTools::V112::Target
```
even though the falling-back code had already given up on 112 and loaded
111 instead.

The simplest way to fix this seems to be ensure that
`Selenium::DevTools.version` matches what was loaded.

Also now there's a test
@rogerkk
Copy link
Copy Markdown

rogerkk commented Apr 14, 2023

We are doing a release next week in any case.

Is that release still on for this week? Our build has been breaking all week and I'm wondering whether I should start some mitigation or just wait a little bit longer. :)

@diemol
Copy link
Copy Markdown
Member

diemol commented Apr 18, 2023

Release is delayed by one week, Eastern holidays happened.

However, I just pushed https://rubygems.org/gems/selenium-devtools/versions/0.112.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🚀 Feature]: Ruby support for older CDP versions

5 participants