automation - UIATarget.onAlert = function onAlert(alert) Issue - Script doesn't seem to go into block correctly -


thanks firstly taking time read , offer incite issue. @ moment, i'm quite trying automate logging in , logging out of app company making using instruments. ran few small issues (as can see password entry, roll char char instead of using string because of strange typing issue).

the issue when alert pop screen wish tap logout button. however, seems never enter block should handling alert. can deduce because of logmessages littered in onalert block, not appear in logs when test script run. know default handler dismisses alerts unless alert explicitly handled otherwise. believe or @ least trying explicitly handle alert can tap right button.

what doing wrong? followed apple instruments guide , believe i'm using exact same syntax offer example. please find code below, included of it, block of interest @ end.

var target = uiatarget.localtarget(); var password = "something"  uialogger.logstart("test1");  target.frontmostapp().mainwindow().scrollviews()[0].webviews()[0].textfields()[0].tap();  target.frontmostapp().keyboard().typestring("something");  uiatarget.localtarget().delay(2);  target.frontmostapp().mainwindow().scrollviews()[0].webviews()[0].securetextfields()[0].tap();  uiatarget.localtarget().delay(2);  (i = 0; < password.length; i++){      var strchar = password.charat(i);     target.frontmostapp().keyboard().typestring(strchar);  }  target.frontmostapp().mainwindow().scrollviews()[0].webviews()[0].buttons()["log in"].tap();  target.frontmostapp().mainwindow().tableviews()[0].cells()["wipe data after 10 attempts"].statictexts()["wipe data after 10 attempts"].scrolltovisible();  target.frontmostapp().mainwindow().tableviews()[0].groups()["logout default"].buttons()["logout default"].tap(); // alert detected. expressions handling alerts should moved               uiatarget.onalert function definition.  uialogger.logmessage("just before alert");  uiatarget.onalert = function onalert(alert){      uialogger.logmessage("in alert!");      uiatarget.delay(1);     var title = alert.name();     uialogger.logmessage("alert title '" + title + "' encountered!");       uialogger.alert.logelementtree();     alert.buttons()["logout"].tap();   } 

i had issue , found automation code progressing onto next line before ui (in case alert view) displayed in simulator. mitigate added delay prior onalert block allow alert view displayed.

uiatarget.localtarget().delay(3) uiatarget.onalert = function onalert(alert){     var title = alert.name();     uialogger.logwarning("alert title ’" + title + "’ encountered!");     target.frontmostapp().alert().cancelbutton().tap();     return false; // use default handler } 

Comments