mercredi 24 décembre 2014

Selenium + Ruby - Working with conditions

Currently my test check if element is present in the screen. If element is present then run a specific action, else the test continuous normally. See my code:



require "selenium-webdriver"
require "rspec"
require 'rspec/expectations'


describe "Current Expense" do


before(:all) do
@driver = Selenium::WebDriver.for :firefox
@base_url = "http://ift.tt/13YVqZu"
@driver.manage.window.maximize
end

after(:all) do
@driver.quit
end


it "Check icon" do
@driver.get(@base_url)
if expect(@driver.find_element(:xpath, "//*[@href='/gallery/']").displayed?).to be_truthy
@driver.find_element(:xpath, "//*[@href='/gallery/']").click
sleep 2
puts "element appears"
else
puts "element NOT appears"
end
end
end


When the element is present, the message appears, but when the element not is present in the page, occurs an error and the message of "ELSE" not run.


someone help me?


Aucun commentaire:

Enregistrer un commentaire