cukefarm icon indicating copy to clipboard operation
cukefarm copied to clipboard

Input field should be focused when typing, even if typing an empty string

Open thompsnm opened this issue 10 years ago • 0 comments

In one of our projects, we have a scenario that looks like this:

Scenario: Input Invalid Information
  Given I go to the "Login" page
  When I type "" in the "User Name" field
    And I type "1234" in the "Pass Code" field
    And I click the "Submit" button
  Then the "Username Required Red Error Box" should be displayed

The intent of this scenario is to ensure that an error appears for the User Name field if no value is entered. We recently updated the business logic so that the error will appear on blur events. This scenario works for that situation on OS X, but it fails when run on Windows. It appears that this is because WebDriver doesn't alway focus on an input on Windows if an empty string is sent, so no blur event is triggered as focus shifts in later steps.

The 'When I type "**" in the "**" field' step should always focus on the element, even if no string is typed. This can be done by adding a call to click on the element in the Step Definition:

@When /^I type "([^"]*)" in(?:to)? the "([^"]*)" field$/, (text, fieldName, callback) ->
  field = @transform.stringToVariableName(fieldName + 'Field')
  @currentPage[field].click()
  @currentPage[field].clear()
  @currentPage[field].sendKeys(text).then ->
    callback()

thompsnm avatar Jul 06 '15 22:07 thompsnm