ios - How do I enter text in an alert textfield using Xcode UI Automation testing -


this problem bugging me. having read official documentation, book jonathan penn , online tutorials can find. have built simple app learn ui testing getting stumped @ first step. todo list app. click on uibarbuttonitem button displays dialog uitextfield , 2 button, ok , cancel. here ibaction.

@ibaction func showdialog(sender: uibarbuttonitem) {     println("showdialog")     var inputtextfield: uitextfield?     var alert:uialertcontroller     alert = uialertcontroller(title: "new item", message: "type item below", preferredstyle: uialertcontrollerstyle.alert)     alert.addtextfieldwithconfigurationhandler({(textfield: uitextfield!) in         textfield.placeholder = "item name"  // need choose correct keyboard , capitalise first letter of each word.         inputtextfield = textfield     })     alert.addaction(uialertaction(title: "ok", style: uialertactionstyle.default, handler: { (action) -> void in         if let itemname = inputtextfield?.text {             println(itemname)             self.items.append(itemname)             self.tableview.reloaddata()         }     }))     alert.addaction(uialertaction(title: "cancel", style: uialertactionstyle.cancel, handler: nil))     self.presentviewcontroller(alert, animated: true, completion: nil) } 

i have tried write ui automation test recording adding alert handler won't work. here testing script.

var target = uiatarget.localtarget();  uialogger.logwarning('script started');  target.frontmostapp().navigationbar().rightbutton().tap();  uiatarget.onalert = function onalert(alert) {     var title = alert.name();     uialogger.logwarning("alert title ’" + title + "’ encountered!");     target.frontmostapp().keyboard().typestring("cheese");     alert.buttons()["ok"].tap();     return true; } 

what doing wrong?

after searching found answer. onalert function returns true if want interact alert , false if want dismiss it.

var target = uiatarget.localtarget(); var app = target.frontmostapp(); var window = app.mainwindow(); window.navigationbar().rightbutton().tap();  uiatarget.onalert = function() {     return true; }  app.keyboard().typestring("cheese"); app.alert().buttons()["ok"].tap(); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -