Add runWirelessWatcher();
to your code.
runWirelessWatcher();
getUiDevice().pressHome();
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
UiObject playstoretab = new UiObject(new UiSelector().description("PlayStore"));
playstoretab.clickAndWaitForNewWindow();
Unless you are already doing this and you aren't showing it.
Edit
Try this: it will help debug: (Just copy/paste)
public void runWirelessWatcher() throws UiObjectNotFoundException {
String NONETWORKWATCHER_STRING = "CancelWirelessWatcher";
UiWatcher CancelWirelessWatcher= new UiWatcher() {
@Override
public boolean checkForCondition() {
UiObject okDialog = new UiObject(new UiSelector().text("No Network"));
if(okDialog.exists()){
UiObject okButton = new UiObject(new UiSelector().text("Home"));
try {
okButton.click();
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
Log.d("Watcher", "Found okButton!");
return (true);
}
Log.d("watcher", "Watcher is running");
return false;
}
};
UiDevice.getInstance().registerWatcher(NONETWORKWATCHER_STRING, CancelWirelessWatcher);
}
And your code:
runWirelessWatcher();
UiDevice.getInstance.runWatchers();
getUiDevice().pressHome();
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
UiObject playstoretab = new UiObject(new UiSelector().description("PlayStore"));
playstoretab.clickAndWaitForNewWindow();
//this is where your watcher should be called?
//Do something here to keep test running