Ruby on Rails Tuesday, January 6, 2015

Hi,

My scenario is:

1) Access menu
2) While icon "trash" exist, remove all
3) If icon not exist, then add a new register

My code is:


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

describe "Current Expense" do

  before(:all) do
    @driver = Selenium::WebDriver.for :firefox
    @base_url = "https://mysite.com"
    @driver.manage.window.maximize
  end

  after(:all) do
    @driver.quit   
  end

  it "Login in the system" do
    @driver.get(@base_url)
    @driver.find_element(:id, "user_email").send_keys "myemail@gmail.com"
    @driver.find_element(:id, "user_password").send_keys "123456"
    @driver.find_element(:name, "commit").click
    @driver.find_element(:xpath, "//*[@href='/expenses/current']").click
    
    wait = Selenium::WebDriver::Wait.new(:timeout => 5)
    wait.until {@driver.find_element(:id => "expense_merchant")}
  end
  
  it "Remove and add new expense" do
    begin 
    while(@driver.find_element(:xpath, "//*[@class='i i-trashcan icon']").displayed?)
      @driver.find_element(:xpath, "//*[@class='i i-trashcan icon']").click 
      sleep 2
      @driver.find_element(:xpath, "//*[@class='btn btn-primary']").click 
    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(:xpath, "//*[@type='submit']").click
      sleep 3
    end 
  end
end


I need that work WHILE only in the block in bold in the above code, otherwise runs the rescue

My problem is that WHILE not stay in the loop, it runs only once and then run the rescue. Why?

Cheers,
Rafael

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1f8159c1-353f-45be-b48d-7c6a0bd4dd86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment