Access iOS Control Center using appium
Asked Answered
P

7

13

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

Pandurate answered 18/6, 2015 at 11:12 Comment(1)
Looking at the details of the swipe() method, I suspect it might be because we press down, then move, rather than just moving from the start... but I will wait and see if others can confirm this.Pandurate
P
-1

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.

Pandurate answered 7/7, 2015 at 21:31 Comment(0)
L
5

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();
Lading answered 1/2, 2016 at 6:59 Comment(3)
Did the wifi accessibility ID change between iOS versions and/or devices? And where did you find the accessibility ID value for wifi in control center? Is it documented somewhere? I got as far as bring up the control center with the code snippet, but it can't find the wifi button/icon by the accessibility ID. I tested on iPod Touch running iOS 8.4.1, Appium 1.4.16, and XCode 7.2.Methylal
I don't think accessibilityId changes between OS versions. I used Appium Inspector to identify the accessibilityID of the Wifi button.Lading
Hi, I am getting following error. Any suggestion would be great Proxying [POST /element] to [POST localhost:8100/session/340CCDB4-E673-42F7-8767-FE27934B2917/… with body: {"using":"xpath","value":"//XCUIElementTypeOther[@label='Wi-Fi']"} Got response with status 200: {"value":"*** setObjectForKey: object cannot be nil (key: top)\n\n(\n\t0 HTTP] <-- POST /wd/hub/session/26cbc5b8-0260-409b-b9b0-3d6855c97fbb/element 500 442 ms - 164Calvities
C
1

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() 
Charactery answered 25/10, 2017 at 15:31 Comment(0)
H
0

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();
}
Hospitable answered 1/5, 2017 at 18:33 Comment(0)
I
0

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();
Ingalls answered 29/7, 2019 at 10:10 Comment(1)
@Alessio Glad that the code worked, I will edit my answer and provide more details, thanksIngalls
S
0

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
}
Strickland answered 11/3, 2020 at 12:44 Comment(0)
C
0

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();
Coorg answered 10/8, 2020 at 8:38 Comment(0)
P
-1

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.

Pandurate answered 7/7, 2015 at 21:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.