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.

  1. if textfield has placeholder text can use placeholder text find textfield.

  2. you can use elementboundbyindex method textfield @ index. i.e. if textfield in app @ time can use

    xcuiapplication().textfields.elementboundbyindex(0)  

to textfield. (or whatever query need particular textfield @ time)

  1. 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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -