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

Introduce method to get driver hosts to be ignored by VCR, WebMock #109

Closed
eliotsykes opened this issue May 9, 2019 · 9 comments
Closed

Comments

@eliotsykes
Copy link

eliotsykes commented May 9, 2019

Consider adding a method to webdrivers to return all of the driver hosts that ought to be ignored by testing tools like VCR and WebMock.

This would simplify the supporting config as follows:

VCR.configure do |config|
  config.ignore_hosts(
-    "chromedriver.storage.googleapis.com",
-    "github.com/mozilla/geckodriver/releases",
-    "selenium-release.storage.googleapis.com",
-    "developer.microsoft.com/en-us/microsoft-edge/tools/webdriver"
+    *Webdrivers.driver_hosts
  )
end
-WebMock.disable_net_connect!(allow_localhost: true, allow: [
-  "https://chromedriver.storage.googleapis.com",
-  "https://github.com/mozilla/geckodriver/releases",
-  "https://selenium-release.storage.googleapis.com",
-  "https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver"
-])
+WebMock.disable_net_connect!(allow_localhost: true, allow: Webdrivers.driver_hosts)

This code was modified from the code provided at https://github.com/titusfortner/webdrivers/wiki/Using-with-VCR-or-WebMock

@titusfortner
Copy link
Owner

Well, they aren' t currently public methods, but you could:

Webdrivers::Chromedriver.send(:base_url)

Especially now that you can require only the drivers you want to use, I'm not sure it makes sense for the project to roll this up into a single method...

@eliotsykes
Copy link
Author

Thanks thats interesting. So you can get all of the base_urls with:

# With activesupport gem
driver_urls = Webdrivers::Common.subclasses.map { |driver| driver.send(:base_url) }

# Without activesupport
driver_urls = (ObjectSpace.each_object(Webdrivers::Common.singleton_class).to_a - [Webdrivers::Common]).map { |driver| driver.send(:base_url) }

Which reduces the config a little to:

VCR.configure { |config| config.ignore_hosts(*driver_urls) }

WebMock.disable_net_connect!(allow_localhost: true, allow: driver_urls)

@titusfortner
Copy link
Owner

Ok, I just merged in code that will make #base_url public so that you don't have to use #send, I think that's all the support I want to provide for this in webdrivers gem at this time.

@eliotsykes
Copy link
Author

Thanks @titusfortner!

Here's some code using the newly-public methods for anyone who stumbles on this issue and wants to know how to use them with VCR and WebMock:

# With activesupport gem
driver_urls = Webdrivers::Common.subclasses.map(&:base_url)

# Without activesupport gem
driver_urls = (ObjectSpace.each_object(Webdrivers::Common.singleton_class).to_a - [Webdrivers::Common]).map(&:base_url)

VCR.configure { |config| config.ignore_hosts(*driver_urls) }
WebMock.disable_net_connect!(allow_localhost: true, allow: driver_urls)

(I tried updating the wiki page but it looks like its not open for public edits.)

@kapoorlakshya
Copy link
Collaborator

Hi @eliotsykes, I have updated the wiki with the information you have provided - https://github.com/titusfortner/webdrivers/wiki/Using-with-VCR-or-WebMock

Let me know if anything can be improved. Thanks!

@titusfortner
Copy link
Owner

This is now available in 3.9.4

@titusfortner
Copy link
Owner

Also, ftr, I changed the wiki so that anyone can add to it.

@gnclmorais
Copy link

Hey folks, I’ve tried this but it didn’t work. base_url was giving me full URLs (like https://chromedriver.storage.googleapis.com) which was not allowing the requests.

However, extracting just the host made it work:

driver_urls = Webdrivers::Common.subclasses.map do |driver|
  Addressable::URI.parse(driver.base_url).host
end

@cdmo
Copy link

cdmo commented Oct 25, 2019

@gnclmorais When I try and use :selenium I get an error because AWS is involved, so I had to do this:

driver_urls = Webdrivers::Common.subclasses.map do |driver|
  Addressable::URI.parse(driver.base_url).host
end << 'github-production-release-asset-2e65be.s3.amazonaws.com'

Feel like github-production-release-asset-2e65be probably isn't static, but, I had to add it because just using s3.amazonaws.com didn't work.

aviav added a commit to aviav/pageflow that referenced this issue Dec 4, 2019
According to [1], chromedriver-helper is unmaintained. Its former
maintainer encourages using webdrivers [2].

As part of this change, we allow connections to update drivers in the
WebMock config. See [3] for details about this.

[1] https://github.com/flavorjones/chromedriver-helper#notice-this-gem-is-out-of-support-as-of-2019-03-31
[2] https://github.com/titusfortner/webdrivers
[3] titusfortner/webdrivers#109

REDMINE-17242
AndrewKvalheim added a commit to AndrewKvalheim/osem that referenced this issue Mar 28, 2020
Resolves:

    $ docker-compose run --rm osem bundle exec rspec --tag js
    …
    WebMock::NetConnectNotAllowedError

See titusfortner/webdrivers#109 for details.
AndrewKvalheim added a commit to AndrewKvalheim/osem that referenced this issue Apr 13, 2020
Resolves openSUSE#2557:

    $ docker-compose run --rm osem bundle exec rspec --tag js
    …
    WebMock::NetConnectNotAllowedError

See titusfortner/webdrivers#109 for details.
hennevogel pushed a commit to AndrewKvalheim/osem that referenced this issue Mar 6, 2021
Resolves openSUSE#2557:

    $ docker-compose run --rm osem bundle exec rspec --tag js
    …
    WebMock::NetConnectNotAllowedError

See titusfortner/webdrivers#109 for details.
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

No branches or pull requests

5 participants