Skip to content

Instantly share code, notes, and snippets.

@dwt
Created February 28, 2018 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwt/a8caf3a68086fd9651fcbfa00442bf60 to your computer and use it in GitHub Desktop.
Save dwt/a8caf3a68086fd9651fcbfa00442bf60 to your computer and use it in GitHub Desktop.
CHROMEDRIVER_PATH = '/Users/dwt/.virtualenvs/yeepa/bin/chromedriver'
CHROME_PATH = '/Users/dwt/Applications/Network/Browser/Google Chrome.app/Contents/MacOS/Google Chrome'
def selenium()
require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'
Capybara.register_driver :chrome do |app|
Selenium::WebDriver::Chrome.driver_path = CHROMEDRIVER_PATH
options = Selenium::WebDriver::Chrome::Options.new()
options.binary = CHROME_PATH
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options
)
end
Capybara.default_driver = :chrome
Capybara.app_host = 'http://localhost:8080' unless Capybara.app_host
puts 'before visit without anchor'
Capybara.visit('http://localhost:8080')
puts 'before visit with anchor'
puts 'the print after this visit is not reached, instead it hangs and then shows an'
puts 'ERROR Net::ReadTimeout: Net::ReadTimeout - just wait for it'
Capybara.visit('http://localhost:8080#foo')
# [2018-02-28 08:26:23] ERROR Net::ReadTimeout: Net::ReadTimeout
# [...]/net/protocol.rb:176:in `rbuf_fill'
puts 'after visit with anchor'
end
def sinatra()
require 'sinatra'
set port: 8080
get '/' do
erb :index
end
end
Thread.abort_on_exception = true
Thread.new do
selenium()
end
sinatra()
__END__
@@ index
<a href="/#foo">link</a>
<a id="foo">target</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment