2

I am using Frank to automate the iPhone and so far so good. I am trying to create a random string for the user name and also concatenate the random string to an email the in the step definitions. I need to pass that to a text field element within an iOS app. Here is what I have so far:

def generate_random_string(length=6)
    string = ""
    chars = ("a".."z").to_a
    length.times do
    string << chars[rand(chars.length-1)]
end
string
end

Given /^I generate a username$/ do
   globalVariableName = Rand.rand(10)  + "@test.email.com"
end
Pete Hodgson
  • 15,644
  • 5
  • 38
  • 46
Laser Hawk
  • 1,988
  • 2
  • 23
  • 29

1 Answers1

3

This is as much a cucumber question as it is a Frank question. Sounds like you're asking about hw

First you'll want to save your generated username somewhere it can be used in other steps. You can do that by assigning it to a member variable.

Given /^I generate a username$/ do
  @username = Rand.rand(10)  + "@test.email.com"
end

Now you can reference that variable in another step. Here's a step which will find the text field in the UI with the placeholder you want, tap it, and then type the previously assigned username into that field.

When /^I enter my username into the username field$/ do
  text_field_selector = "view:'UITextField' placeholder:'username'"
  touch( text_field_selector )
  type_into_keyboard( @username )
end

Obviously you might want to change that selector depending on what the best way is to specify the field you want to type into.

Note that I'm using the type_into_keyboard helper method which is only available in recent version of Frank. Upgrade if you need to.

Hope that helps. The frank mailing list is a great place to get support too - https://groups.google.com/group/frank-discuss

Pete Hodgson
  • 15,644
  • 5
  • 38
  • 46