calabash-android undefined method for second step

823 views Asked by At

I'm new to calabash, and I am trying to run a test, and calabash recognizes my first step and it passes, but for the second one i get an undefined method error,

my feature file is:

Feature: Sign-in page
Scenario: Go to dashboard with skip login
Given I am on the Login Screen
When I touch the “Skip Login” button
Then I should see the Main Screen

and my rb file is

Given(/^I am on the Login Screen$/) do
  element_exists("button marked:'authenticate'")
  end

When(/^I touch the "Skip Login" button$/) do
  tap_mark 'skip_login'
end

Then(/^I should see the Main Screen$/) do
  wait_for_elements_exist("label text: 'HeaderText'")
end

When it reaches the "When" step, the app closes on my phone. Can someone please help me with this?

The output is:

Given I am on the Login Screen          # features/step_definitions/calabash

_steps.rb:1 When I touch the "Skip Login" button # features\my_first.feature:4 Then I should see the Main Screen # features/step_definitions/calabash _steps.rb:9

1 scenario (1 undefined) 3 steps (1 skipped, 1 undefined, 1 passed) 0m22.691s

You can implement step definitions for undefined steps with these snippets:

When(/^I touch the "Skip Login" button$/) do pending # express the regexp above with the code you wish you had end

One more detail, if I take the second step and move it instead of the first, it will press the button.I can't understand why this is happening, and why it will not do the second step

3

There are 3 answers

0
jmoody On BEST ANSWER

It looks like a "smart quotes" problem to me:

When I touch the “Skip Login” button

Those are not regular double quotes ".

Since you are not using a regex in the step definition, I recommend this:

Given I am on the Login Screen
When I touch the Skip Login button
Then I should see the Main Screen

When(/^I touch the Skip Login button$/) do
  tap_mark 'skip_login'
end
1
Tobias On

First of all, see the logcat for details why you app crashes.

I think you are running an very old version of Calabash-Android. In the newer releases, and invalid query should never crash the app. wait_for_elements_exist("label text: 'HeaderText'") will crash the app in old versions of Calabash-Android, as you have a space after text: which is invalid.

A newer version of Calabash-Android would raise a Ruby error telling you about the misformed query.

1
Lasse On

The output from your tests would be good to have. But other than that in you step you have put

tap_mark 'skip_login'

So it will attempt to find a text with that exact text. But based on your feature file I am guessing that what you actually have on the button is

Skip Login

And so the tap_mark command fails.

And this is just a guess but is "skip_login" the id of the button? If you want to use that to decide what to click do something like

touch "button id:'skip_login'"