Fred Chan
Fred Chan

Reputation: 117

Calabash Android - Is there a way to input text without having to include the field?

Is there a way that I can just enter text in my script by typing

Then I enter "[email protected]"

rather than

Then I enter "[email protected]" into "edit_text_dialog_first_field"?

This is for Calabash Android.

Thanks

Upvotes: 0

Views: 1083

Answers (3)

Mr.Tester
Mr.Tester

Reputation: 1

Yeap, custom steps helps out much better, if you need some examples, try this link here.

Upvotes: 0

Aravin
Aravin

Reputation: 7077

You can write .feature file in anyway but you have to write step definitionsaccording to your feature.

This Then I enter "[email protected] or this Then I enter "[email protected]" into "edit_text_dialog_first_field"? does not matter.

If you use

Then I enter "[email protected]" into "edit_text_dialog_first_field"?

Your Step Definition will be

Then (/^I enter "(.*?)" into "(.*?)$/") do | arg1, arg2 |
  do action...
end

If you use

Then I enter "[email protected]

Your Step Definition will be

Then (/^I enter "(.*?)") do | arg1 |
  do action...
end

Upvotes: 1

John Engelhart
John Engelhart

Reputation: 279

I recommend you create a custom step definition then you can call that step in your scenario. Using the predefined steps are generally poor practice.

  • Create a folder called android_steps inside of you Features file
  • Create a file in that folder called my_steps.rb (Eventually you would want multiple step files that are specific to one are aka landing page, sign in, menu)
  • Using regex you can create a step definition inside of your my_steps.rb file
  • It would look something like

    Then (/^I enter (.*)$/) do |information|
        touch("* id:'Field_id_you_want_to_enter_info_into'")
        keyboard_enter_text(information)
    end
    

I recommend you make a more intuitive step name though something along the lines of I enter the (.*) into the username field I have started creating an intro guide on youtube. Please reference https://www.youtube.com/playlist?list=PLInoIpH9dfLyvdaOjozON9QnQP1pK30y-

Upvotes: 4

Related Questions