Skip to content

Instantly share code, notes, and snippets.

@rafaelcs
Created March 25, 2015 19:25
Show Gist options
  • Save rafaelcs/417b34c90c624d117b3a to your computer and use it in GitHub Desktop.
Save rafaelcs/417b34c90c624d117b3a to your computer and use it in GitHub Desktop.
Example Sauce Labs
require "selenium-webdriver"
require "rspec"
require 'rspec/expectations'
describe "#Add simple expense and after add a receipt", :suite => true do
before(:all) do
@driver = Selenium::WebDriver.for :chrome
@base_url = "https://myurl.com"
@driver.manage.window.maximize
end
it "Login in the system" do
@driver.get(@base_url)
@driver.find_element(:id, "user_email").send_keys "myuser"
@driver.find_element(:id, "user_password").send_keys "mypass"
@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 => "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 3
end
rescue Selenium::WebDriver::Error::NoSuchElementError
@driver.find_element(:id, "expense_merchant").send_keys "Taxi to work"
@driver.find_element(:id, "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 => 10)
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 file
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