ios - How to test UITextField in Xcode UI Testing when the text field is empty? -
i making uitest
in xcode. when record test works fine when run test, gives error.
these lines of code error occurs:
xcuielement *cleartexttextfield = [app.textfields containingtype:xcuielementtypebutton identifier:@"clear text"].element; [cleartexttextfield typetext:@"sheffield"];
the error says
ui testing failure - no matches found textfield
i imagine because text field not have initial string , tester cannot find text box initial string "clear text"
.
i watched following tutorial on youtube.
the demonstrators code turns out fine because textfield has initial string. (at least think problem is)
is there way make test work empty text fields?
there few ways this.
if textfield has placeholder text can use placeholder text find textfield.
you can use
elementboundbyindex
method textfield @ index. i.e. if textfield in app @ time can usexcuiapplication().textfields.elementboundbyindex(0)
to textfield. (or whatever query need particular textfield @ time)
- you can set accessibility identifier in code or in storyboard find textfield.
it nice use option 2 before setting accessibility identifiers, long textfield going findable same query. also, option 1 fail if multiple textfields have same placeholder text @ same time, option 2 more appealing.
Comments
Post a Comment