Skip to content

Instantly share code, notes, and snippets.

@ckenst
Last active August 28, 2017 02:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
A simple selenium script using chrome headless
require 'selenium-webdriver'
require 'rspec/expectations'
include RSpec::Matchers
def setup
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--remote-debugging-port=9222')
@driver = Selenium::WebDriver.for :chrome, options: options
end
def teardown
@driver.quit
end
def run
setup
yield
teardown
end
run do
@driver.get 'http://www.kenst.com/about'
expect(@driver.title).to eql "About – Chris Kenst's Blog"
@driver.save_screenshot(File.join(Dir.pwd, "headless.png"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment