Ruby Rspec cucumber array each do -


i have scenario when upon login page, presented numerous profile(can 1 5). looking specific profile based tn number. locate element represent tn , put in array search available elements same locate correct profile in order click on it.

here code:

and(/^i "([^"]*)"$/) |number|       elements = @driver.find_elements(:css => "h3.phone-number")       elements.each |element|        renewals_page.select_profile.click if element.text == @config[number]          return element      end         fail   end 

i passing desired number yaml file depends on account. renewals_page.select_profile.click defined in file method

  def select_profile        @driver.find_element(:css => "h3.phone-number")      end     

so when try locate element , click on it, following error

unexpected return (localjumperror)     ./features/step_definitions/renewals_login_step.rb:28:in `block (2 levels) in <top (required)>'     ./features/step_definitions/renewals_login_step.rb:26:in `each'     ./features/step_definitions/renewals_login_step.rb:26:in `/^i "([^"]*)"$/' 

remove return here:

renewals_page.select_profile.click if element.text == @config[number]   #   ⇓⇓⇓⇓⇓⇓ #   return element  # removed    element   # proper working return lambda: result of last line end  

the reason return keyword may used return method only, not lambda.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -