On Friday, December 26, 2014 11:15:10 AM UTC-8, Rafael s wrote: > > 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 "element" do > > > before(:all) do > @driver = Selenium::WebDriver.for :firefox > @base_url = "http://the-internet.herokuapp.com/disappearing_elements > <https://www.linkedin.com/redirect?url=http%3A%2F%2Fthe-internet%2Eherokuapp%2Ecom%2Fdisappearing_elements&urlhash=F1r-&_t=tracking_anet> > " > @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? >
Expectations are not meant to be used in conditionals like this -- they communicate pass/fail by raising an exception or not rather than returning boolean values. So, just use the expression you've wrapped in `expect` directly in a conditional: if @driver.find_element(:xpath, "//*[@href='/gallery/']").displayed? @driver.find_element(:xpath, "//*[@href='/gallery/']").click sleep 2 puts "element appears" else puts "element NOT appears" end HTH, Myron -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/1cf78fc7-abd9-48e6-8a46-81af3d27f7e1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
