Skip to content

Instantly share code, notes, and snippets.

@Ansh1234
Created September 20, 2016 16:24
Show Gist options
  • Save Ansh1234/90af6f72548c86a76d8be13858bfe32a to your computer and use it in GitHub Desktop.
Save Ansh1234/90af6f72548c86a76d8be13858bfe32a to your computer and use it in GitHub Desktop.
@Test
public void turnOffWifi() throws UiObjectNotFoundException {
String wiFi = "Wi‑Fi";
//Get an instance of device and press home button
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
device.pressHome();
//To get the list of all apps, find an object which has description "Apps" and click it
UiObject2 allApps = device.findObject(By.desc("Apps"));
allApps.click();
//Make a scrollable list and find TextView which has Settings written over it and click it.
UiScrollable appViewsList = new UiScrollable(new UiSelector().scrollable(true));
appViewsList.setAsHorizontalList();
appViewsList.scrollTextIntoView("Settings");
device.findObject(new UiSelector().description("Settings")).click();
//Again create a Scrollable list and find TextView which has "Wi-Fi" written over it.
UiScrollable settingList = new UiScrollable(new UiSelector().scrollable(true));
settingList.scrollTextIntoView(wiFi);
device.findObject(By.text(wiFi)).click();
//Find the switch next to it and turn it off.
device.findObject(By.clazz(Switch.class)).click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment