Skip to content

Instantly share code, notes, and snippets.

@rafaelcs
Created April 29, 2015 16:26
Show Gist options
  • Save rafaelcs/4265f50eb92fe72ff6ff to your computer and use it in GitHub Desktop.
Save rafaelcs/4265f50eb92fe72ff6ff to your computer and use it in GitHub Desktop.
Code Example Using Selenium Webdriver + Rspec
require "selenium-webdriver"
require "rspec"
require 'rspec/expectations'
require "faker"
describe "#Add expense and create report", :suite => true do
before(:all) do
@driver = Selenium::WebDriver.for :chrome
@base_url = "https://mysite.com"
@driver.manage.window.maximize
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-pencil.icon").displayed?)
@driver.find_element(:class, "sorting_disabled").click
@driver.find_element(:id, "delete-multi-btn").click
waitDisplayModal = Selenium::WebDriver::Wait.new(:timeout => 10)
waitDisplayModal.until {@driver.find_element(:class => "bootstrap-dialog-footer-buttons")}
@driver.find_element(:xpath, "//div[3]/div/div/button[2]").click
sleep 2
end
rescue Selenium::WebDriver::Error::NoSuchElementError
@driver.find_element(:id, "current_expense_merchant").send_keys Faker::Company.name
@driver.find_element(:id, "current_expense_amount").send_keys Faker::Number.number(2)
@driver.find_element(:id, "current_expense_comment").send_keys Faker::Lorem.word
@driver.find_element(:id, "button-add-expense").click
waitDisplayIconTrash = Selenium::WebDriver::Wait.new(:timeout => 10)
waitDisplayIconTrash.until {@driver.find_element(:css => ".i.i-pencil.icon")}
end
end
it "Create report and add subject and notes" do
@driver.find_element(:css, ".btn.btn-s-md.btn-primary").click
waitDisplayModalCreateReport = Selenium::WebDriver::Wait.new(:timeout => 10)
waitDisplayModalCreateReport.until {@driver.find_element(:id => "report_subject")}
$subject = Faker::Name.last_name
@driver.find_element(:id, "report_subject").send_keys $subject
$notes = Faker::Lorem.sentence
@driver.find_element(:id, "report_notes").send_keys $notes
@driver.find_element(:xpath, "//div[3]/div/div/button").click
end
it "Check report values" do
waitDisplayModalCreateReport = Selenium::WebDriver::Wait.new(:timeout => 10)
waitDisplayModalCreateReport.until {@driver.find_element(:id => "report_comment_comment")}
$nameReport = @driver.find_element(:css, ".m-t-none.m-b-xs").text
expect($nameReport).to eq($subject)
comment = @driver.find_element(:css, ".b-light.m-b-none.panel.text-sm")
expect(comment.text).to include($notes)
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