Last active
August 28, 2017 02:50
-
-
Save ckenst/c1e7f32f290312adfeec46a93d283ac0 to your computer and use it in GitHub Desktop.
A simple selenium script using chrome headless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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