conditional - How do I perform an action on a field for Swift UI Tests based on the contents/state of the field? -
i have usernamefield. on initial state, field empty. if log in successfully, , log out, remembers username me.
trying create test case ios (in swift) clear out field (use cleartext button) if field has content , enter desired string. if it's empty, needs skip cleartext button action (since doesn't exist when field value nil) , go straight entering username.
it skips if statement, when it's true. looks cleartext button, , fails. works if there's value in field, though.
tried lots of different approaches, here's best current working code. open suggestions, have no 1 me learn stuff. i'm sure i'm missing fundamental:
let staffusernameloginfield = app.scrollviews.otherelements.textfields["staffusernameloginfield"] staffusernameloginfield.tap() func checkusernamefieldcontents() { if staffusernameloginfield == (content:nil) { staffusernameloginfield.typetext("owner") } else { elementsquery.buttons["clear text"].tap() staffusernameloginfield.typetext("owner") } } checkusernamefieldcontents()
have tried:
if staffusernameloginfield == ("") { staffusernameloginfield.typetext("owner") } else { elementsquery.buttons["clear text"].tap() staffusernameloginfield.typetext("owner") } }
i know hack having enter value field , clear out , enter desired value, in test case, i'm not trying test that.
i compare value (raw attribute of element). type can vary string:
if staffusernameloginfield.value as! string == "" { staffusernameloginfield.typetext("owner") } else { elementsquery.buttons["clear text"].tap() staffusernameloginfield.typetext("owner") }
now should enter 'owner' if sees there no value in staffusernameloginfield.
Comments
Post a Comment