Search code examples
rubycalabash-android

Ruby/calabash: undefined method `each' for 2:Fixnum (NoMethodError)


I'm stuck with an error while creating some auto test in calabash. So my code is:

Then /^I set some site$/ do
    arr=["Google.com","Youtube.com"]
    for i in arr.length {
        touch("* id:'browserActivity_linLout_toolbar_url'")
        sleep 5
        currentSite=arr[i]
        keyboard_enter_text (currentSite)
        sleep 10
        press_enter_button
        i=i+1
        sleep 20
        }
    end
end

When I try to run my test I get this error:

undefined method each' for 2:Fixnum (NoMethodError) ./features/step_definitions/calabash_steps.rb:339:in/^I set some site$/' features/my_first.feature:6:in `Then I set some site'

Any ideas how to solve it?


Solution

  • You are writing the for loop with the wrong syntax. In Ruby, use:

    for element in arr
        #...
        currentSite = element
        #...
    end
    

    Or better, without for:

    arr.each do |element|
        #...
        currentSite = element
        #...
    end