Skip to content

Instantly share code, notes, and snippets.

@rafaelcs
Created April 8, 2015 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcs/dd4db18ba76d367aaf14 to your computer and use it in GitHub Desktop.
Save rafaelcs/dd4db18ba76d367aaf14 to your computer and use it in GitHub Desktop.
require "selenium-webdriver"
require "rspec"
require 'rspec/expectations'
describe "#Add simple expense with receipt", :suite => true do
before(:all) do
@driver = Selenium::WebDriver.for :chrome
@base_url = "https://mytest.com"
@driver.manage.window.maximize
end
it "Login in the system" do
@driver.get(@base_url)
@driver.find_element(:id, "user_email").send_keys "rafaelcrvs+automation@gmail.com"
@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 => 5)
waitDisplayScreen.until {@driver.find_element(:id => "current_expense_merchant")}
end
it "Remove and add new expense with receipt" 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 => 5)
waitDisplayModal.until {@driver.find_element(:class => "modal-content")}
@driver.find_element(:xpath, "//*[@class='btn btn-primary']").click
sleep 2
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"
filename = 'chess.jpg'
file = File.join(Dir.pwd, filename)
@driver.find_element(:id, "expense_attachment_new").send_keys file
sleep 6
@driver.find_element(:id, "button-add-expense").click
waitDisplayIconTrash = Selenium::WebDriver::Wait.new(:timeout => 5)
waitDisplayIconTrash.until {@driver.find_element(:css => ".i.i-trashcan.icon")}
end
end
it "Check expense values" do
expense = @driver.find_element(:id, "report-expenses")
expect(expense.text).to include("Taxi to work")
expect(expense.text).to include("$50")
expect(expense.text).to include("Transportation")
expect(expense.text).to include("Cash")
expect(@driver.find_element(:id, "data-expense-count").text)
.to eq("1")
expect(@driver.find_element(:id, "data-expense-cost").text)
.to eq("$50")
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