Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can actually use UIAutomator to set the WiFi setting on and off. I wrote the code this evening :)</p> <p>Here's the code. You can add it to the Android example which is here <a href="http://developer.android.com/tools/testing/testing_ui.html">http://developer.android.com/tools/testing/testing_ui.html</a> </p> <p>Add the following enum at the top of the class</p> <pre><code>private enum OnOff { Off, On }; </code></pre> <p>Add the new code after:</p> <pre><code> // Validate that the package name is the expected one UiObject settingsValidation = new UiObject(new UiSelector() .packageName("com.android.settings")); assertTrue("Unable to detect Settings", settingsValidation.exists()); </code></pre> <p>Here is the new code:</p> <pre><code> UiSelector settingsItems = new UiSelector().className(android.widget.TextView.class.getName()); UiObject wiFi = appViews.getChildByText(settingsItems, "Wi-Fi"); // We can click on Wi-Fi, e.g. wiFi.clickAndWaitForNewWindow(); // So we know we have found the Wi-Fi setting UiSelector switchElement = new UiSelector().className(android.widget.Switch.class.getName()); setSwitchTo(OnOff.Off); // Or set it to On as you wish :) } private void setSwitchTo(OnOff value) throws UiObjectNotFoundException { String text; UiObject switchObject = getSwitchObject(); for (int attempts = 0; attempts &lt; 5; attempts++) { text = switchObject.getText(); boolean switchIsOn = switchObject.isChecked(); final OnOff result; if (switchIsOn) { result = OnOff.On; } else { result = OnOff.Off; } System.out.println("Value of switch is " + switchObject.isSelected() + ", " + text + ", " + switchIsOn); if (result == value) { System.out.println("Switch set to correct value " + result); break; } else { switchObject.click(); } } } private UiObject getSwitchObject() { UiObject switchObject = new UiObject(new UiSelector().className(android.widget.Switch.class.getName())); assertTrue("Unable to find the switch object", switchObject.exists()); String text; return switchObject; } </code></pre> <p>The loop was to compensate for some behaviour I observed, where the click didn't seem to change the switch position. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload