Skip to content

Instantly share code, notes, and snippets.

@rafaelcs
Last active August 29, 2015 14:18
Show Gist options
  • Save rafaelcs/ec0edd39cd8d55d08392 to your computer and use it in GitHub Desktop.
Save rafaelcs/ec0edd39cd8d55d08392 to your computer and use it in GitHub Desktop.
upload file sauce labs + selenium
ENV['SAUCE_USERNAME'] = 'myname'
ENV['SAUCE_API_KEY'] = 'my_api'
require "selenium-webdriver"
require "rspec"
require 'rspec/expectations'
describe "#Add simple expense and after add a receipt", :saucelabs => true do
before(:all) do
@base_url = "https://mytest.com"
caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps.version = "41"
caps.platform = "Windows 7"
caps[:name] = "Testing Selenium 2 with Ruby on Sauce"
@driver = Selenium::WebDriver.for(
:remote,
url: "http://rafaelcs:[email protected]:80/wd/hub",
:desired_capabilities => caps)
@driver.file_detector = lambda do |args|
# args => ["/path/to/file"]
str = args.first.to_s
str if File.exist?(str)
end
end
it "Login in the system" do
@driver.get(@base_url)
@driver.find_element(:id, "user_email").send_keys "[email protected]"
@driver.find_element(:id, "user_password").send_keys "123456"
@driver.find_element(:name, "commit").click
@driver.find_element(:css, ".i.i-pencil").click
waitDisplayScreen = Selenium::WebDriver::Wait.new(:timeout => 10)
waitDisplayScreen.until {@driver.find_element(:id => "current_expense_merchant")}
end
it "Remove and add new expense" do
begin
while(@driver.find_element(:css, ".i.i-trashcan.icon").displayed?)
@driver.find_element(:css, ".i.i-trashcan.icon").click
waitDisplayModal = Selenium::WebDriver::Wait.new(:timeout => 10)
waitDisplayModal.until {@driver.find_element(:class => "modal-content")}
@driver.find_element(:xpath, "//*[@class='btn btn-primary']").click
sleep 8
end
rescue Selenium::WebDriver::Error::NoSuchElementError
@driver.find_element(:id, "current_expense_merchant").send_keys "Taxi to work"
@driver.find_element(:id, "current_expense_amount").send_keys "50"
@driver.find_element(:id, "button-add-expense").click
waitDisplayIconTrash = Selenium::WebDriver::Wait.new(:timeout => 10)
waitDisplayIconTrash.until {@driver.find_element(:css => ".i.i-trashcan.icon")}
end
end
it "Add a new receipt clicking in plus" do
@driver.find_element(:css, ".i.i-plus2").click
waitModalReceipt = Selenium::WebDriver::Wait.new(:timeout => 20)
waitModalReceipt.until {@driver.find_element(:xpath => ".//*[@id='expense-receipt-form']/div[2]/div/div[1]/input")}
filename = 'chess.jpg'
file = File.join(Dir.pwd, filename)
@driver.find_element(:id, "expense_attachment").send_keys filename
sleep 6
@driver.find_element(:xpath, "//*[@class='btn btn-primary']").click
sleep 6
end
it "Open fancybox and check image" do
@driver.find_element(:css, ".i.i-images").click
waitOpenModal = Selenium::WebDriver::Wait.new(:timeout => 10)
waitOpenModal.until {@driver.find_element(:css => ".fancybox-image")}
image = @driver.find_element(:css, ".fancybox-image").attribute("src")
expect(image).to include("chess")
end
after(:all) do
@driver.quit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment