Multiple parameters in an action

46 views
Skip to first unread message

Vaughn Dice

unread,
May 17, 2012, 3:32:04 PM5/17/12
to Zucchini Framework
Hello,

As I write multiple screens and perform actions with them as dictated
by my feature.zucchini file, I find that I wish to add more actions to
the screen.coffee superclass. I've done so, but ran into a roadblock
(read: my lack of coffee-script knowledge!) when intending to write an
action with more than one parameter -- specifically, wanting to create
a 'Type (text) in the (field) field'. (A template I would use quite
often.)

I understand and have used the single parameter 'Type (text)' action:

'Type "([^"]*)"$': (text) ->
app.keyboard().typeString text

(Here I must add an aside: for the app I'm testing, instead of
performing a field.setValue, I've found it necessary to actually
employ the app.keyboard() to type the text -- which assumes the field
has been tapped/selected in a prior step/action)

But I'm unsure how to construct a similar action with two parameters
(text and field). The crux of my confusion lies on not understanding
the '$' character, its use and placement. My rough draft looks like:

'Type "([^"]*)" in the "([^"]*)" field$': (text, field) ->
field.tap()
app.keyboard().typeString text

Any information/tips/suggestions would be greatly appreciated. Thank
you very much for your time and energy!

Vaughn

Vasily Mikhaylichenko

unread,
May 17, 2012, 8:42:42 PM5/17/12
to zucchini...@googlegroups.com
Hi Vaughn,

Two and more parameters are not supported at the moment. It really sounds like a good addition to a future version.

In the meanwhile, have a look at Nathan Sudell's fork that supports two parameters: https://github.com/NathanSudell/zucchini/compare/master...textfield-actions 

I would really like Zucchini to support an arbitrary number of them though.

- Vasily.

Vaughn

unread,
May 18, 2012, 12:34:44 PM5/18/12
to zucchini...@googlegroups.com
Thanks, Vasily!  Nathan Sudell's fork supplied the exact solution to what I was encountering.  Must remember to explore the forks a bit more.

Would Zucchini's solution to supporting an arbitrary number of parameters be something as simple as putting splats here?

func.bind(screen)(match[1],match[2]...)

Also, if you have a minute, would you kindly explain the use of the '$' symbol, as used for each action definition, i.e.

'Take a screenshot named "([^"]*)"$' : (name) ->
      target.captureScreenWithName(name)

Thanks!

Vaughn

Nathan Sudell

unread,
May 20, 2012, 5:57:31 AM5/20/12
to Zucchini Framework
Glad someone found that useful :)

I'm not really familiar with splats, but looks like they're about
defining what is received, not what is sent.

The only solution I see is to pass the whole "match" array and letting
the actions figure out what's contained:

in base.coffee...
func.bind(screen)(match)

in screen.coffee...

'Tap "([^"]*)"$' : (matches) ->
element = matches[1]
throw "Element '#{element}' not defined for the screen
'#{@name}'" unless @elements[element]
@elements[element]().tap()

The $ is a regex symbol for matching end on line:
Reply all
Reply to author
Forward
0 new messages