Skip to content

Instantly share code, notes, and snippets.

@tourdedave
Created December 16, 2014 19:08
Show Gist options
  • Save tourdedave/ae7955c0c87bc919f3df to your computer and use it in GitHub Desktop.
Save tourdedave/ae7955c0c87bc919f3df to your computer and use it in GitHub Desktop.
require 'selenium-webdriver'
require 'rspec/expectations'
include RSpec::Matchers
def setup
caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer
caps.version = '8'
caps.platform = 'Windows XP'
@driver = Selenium::WebDriver.for(
:remote,
url: "http://your-sauce-username:[email protected]:80/wd/hub",
desired_capabilities: caps)
end
def teardown
@driver.quit
end
def run
setup
yield
teardown
end
run do
@driver.file_detector = lambda do |args|
# args => ["/path/to/file"]
str = args.first.to_s
str if File.exist?(str)
end
filename = 'some-file.txt'
file = File.join(Dir.pwd, filename)
@driver.get 'http://the-internet.herokuapp.com/upload'
@driver.find_element(id: 'file-upload').send_keys file
@driver.find_element(id: 'file-submit').click
uploaded_file = @driver.find_element(id: 'uploaded-files').text
expect(uploaded_file).to eql filename
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment