ReadyTalk/cukefarm

Standardize the use of optional elementType parameters in Step Defs

Closed this issue · 0 comments

Some Step Defs provide support for optional elementType parameters to be captured in Gherkin aside from the main elementName capture group. They are later used to build variable names, such as in this Step Def:

@When /^I click the "([^"]*)"(?: )?(link|button|drop down list|tab|)$/, (elementName, elementType,  callback) ->
  elementType = @transform.elementTypeToVariableName(elementType)
  element = @transform.stringToVariableName(elementName + elementType)
  @currentPage[element].click()
  callback()

Other Step Defs hard code similar functionality:

@When /^I select "([^"]*)" in the "([^"]*)" drop down list$/, (optionText, list, callback) ->
  @currentPage[@transform.stringToVariableName(list + 'Select')].then (select) ->
    select.element(protractor.By.cssContainingText('option', optionText)).click().then callback

Still others mandate that the entire variable name be expressed in a single capture group:

@Then /^the "([^"]*)" should be present$/, (el, callback) ->
  @el = @transform.stringToVariableName el
  @expect(@currentPage[@el].isPresent()).to.eventually.equal(true).and.notify(callback)

The use of optional elementType captures should be standardized across all applicable Step Defs so that users can adhere to a single pattern when writing Feature files.