Access iOS Control Center using appium

5.3k Views Asked by At

I am trying to open the Control Center using appium and the following code:

    int halfWidth = driver.manage().window().getSize().width / 2;
    int screenHeight = driver.manage().window().getSize().height;
    driver.swipe(halfWidth, screenHeight-5, halfWidth, screenHeight-300, 500);  // driver is instance of IOSDriver

Instead of opening control centre the app simply draws on the screen upwards from the bottom (using coordinates input). Anyone know how to open Control Center using appium and swipe (or any other way)?

Thanks, Charlie

7

There are 7 best solutions below

0
On BEST ANSWER

Ok so after a fair amount of investigation it seems to me that this is not possible. If you really need this functionality then I think a tool like eggplant might be appropriate.

3
On

We can do this. I tried in Appium 1.4.13 and I am able to change settings.

I used below code to change the settings in my iPadAir2.

int height = driver.findElementByClassName("UIAWindow").getSize().getHeight();
int width = driver.findElementByClassName("UIAWindow").getSize().getWidth();
driver.swipe(width-100, height, width-100, height-200, 500);
driver.findElementByAccessibilityId("Wi-Fi").click();
0
On

Appium 1.6.5, You can use swipe method, bellow my Python code:

window_size = self.driver.get_window_size()  # this returns dictionary
el = self.driver.find_element(*self.configuration.CommonScreen.WEB_VIEW)
action = TouchAction(self.driver)
start_x = window_size["width"] * 0.5
start_y = window_size["height"]
end_x = window_size["width"] * 0.5
end_y = window_size["height"] * 0.5
action.press(el, start_x, start_y).wait(100).move_to(el, end_x, end_y).release().perform() 
0
On

C#: iOS 13.x

//Opening control center

var size = Driver.Manage().Window.Size;

var height = size.Height;

var width = size.Width;

var touchAction = new TouchAction(Driver);

touchAction.Press(width - 100, height).Wait(1000).MoveTo(width - 100, height - 200).Release().Perform();

//Clicking the WiFi button

Driver.FindElementByAccessibilityId("wifi-button").Click();

//Checking if WiFi enabled or not

var myElement = Driver.FindElementByAccessibilityId("wifi-button");

var result = myElement.GetAttribute("label");

if(!result.Contains("Wi-Fi, Not Connected") && !result.Equals("Wi-Fi"))
{
    // WiFi connected
}
else
{
    // WiFi Not connected
}
0
On

I am able to toggle the Wifi OFF or turn Airplane mode ON using Appium 1.6.4-beta for iOS

Swipe up from the bottom of the screen Click continue link Click the Wifi or Airplane button Swipe down from middle of screen

But this doesn't appear to be doing anything in the simulator. I have to actually turn off my computers internet connection to disable the internet on the simulator.

@iOSFindBy(xpath = "//XCUIElementTypeSwitch[@name='Wi-Fi']")
private MobileElement WIFI_MODE_BUTTON;

public void disableWifi()  {
    openToolBarMenu();
    //if wifi is on/true then turn it off
   if (WIFI_MODE_BUTTON.getAttribute("value") == "true" ) {
       Autoscope.tap(WIFI_MODE_BUTTON);
   }
    closeToolBarMenu();
}


@iOSFindBy(xpath = "//XCUIElementTypeButton[@name='Continue']")
private MobileElement CONTINUE_BUTTON; //continue button on control center

public void openToolBarMenu() {
    Autoscope.scrollFromBottomOfScreen();
    if (Autoscope.isElementDisplayed(CONTINUE_BUTTON)) {
        Autoscope.tap(CONTINUE_BUTTON);
    }
}


static public void scrollFromBottomOfScreen() {
    TouchAction touchAction = new TouchAction(autoscopeDriver);

    int xStartPoint = Math.round(pixelWidth() / 2);
    int yStartPoint = pixelHeight();
    int yEndPoint = 0 - yStartPoint;
    touchAction.press(xStartPoint, yStartPoint).moveTo(0, yEndPoint).release().perform();
}
0
On

The idea is to simulate the swipe action you use to open Control Center on the corresponding iOS device. My device is iPhone 11 so it is swipe from the top right(to the right of the notch) down. My code is to swipe from position(x,y) (80% width, 0) to (80% width, 50% height)

    Dimension size = getScreenSize();

    int x = (size.getWidth() / 5) * 4;
    int startY = 0;
    int endY = size.getHeight() / 2;

    new TouchAction(driver).press(PointOption.point(x, startY))
            .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))
            .moveTo(PointOption.point(x, endY))
            .release().perform();
1
On

This code will help in bringing up the Control center, while you are in your app, you can perform all the operations which are available in the Control Center

new TouchAction(DriverConfig.getInstance().getDriver()).press(point(250, 735)).waitAction(waitOptions(Duration.ofSeconds(3))).moveTo(point(250, -460)).release()
                        .perform();