Skip to content

Instantly share code, notes, and snippets.

@leoc
Created February 2, 2018 11:18
Show Gist options
  • Save leoc/d7c45244bae4ccb2185ecb751e86f065 to your computer and use it in GitHub Desktop.
Save leoc/d7c45244bae4ccb2185ecb751e86f065 to your computer and use it in GitHub Desktop.
require 'bundler/inline'
def binary_found?(name)
`which #{name}`
$?.success?
end
def check_binary(name)
return if binary_found?(name)
puts "Missing binary: #{name}"
exit
end
gemfile do
source 'https://rubygems.org'
gem 'selenium-webdriver'
gem 'pry'
gem 'pry-byebug'
gem 'rspec-expectations'
end
check_binary('chromedriver')
check_binary('scrot')
puts 'Latest: selenium/chrome-standalone-debug'
begin
include RSpec::Matchers
driver = Selenium::WebDriver.for(
:remote,
url: 'http://localhost:4444/wd/hub',
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w[--start-maximized --disable-translate]
}
)
)
driver.navigate.to "http://#{IPSocket.getaddress(Socket.gethostname)}:3030"
draggable = driver.find_element(id: '1')
droppable = driver.find_element(id: '2')
# Take a screenshot before
system('vncviewer -config config.vnc & sleep 5 && scrot -u run_chrome_in_docker_before.jpg; killall vncviewer')
# Perform drag drop
driver.action.drag_and_drop(draggable, droppable).perform
# Take a screenshot after
system('vncviewer -config config.vnc & sleep 5 && scrot -u run_chrome_in_docker_after.jpg; killall vncviewer')
# Inspect page text
page_text = driver.execute_script('return document.body').text
expect(page_text).to eq("Element Two\nElement One")
rescue RSpec::Expectations::ExpectationNotMetError => e
puts e.message
ensure
driver && driver.quit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment