Skip to content

Instantly share code, notes, and snippets.

@ckenst
Last active August 28, 2017 02:50
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 ckenst/c1e7f32f290312adfeec46a93d283ac0 to your computer and use it in GitHub Desktop.
Save ckenst/c1e7f32f290312adfeec46a93d283ac0 to your computer and use it in GitHub Desktop.
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