Access iOS Control Center using appium

佐手、 提交于 2019-12-04 17:11:29

问题


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


回答1:


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();



回答2:


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() 



回答3:


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();
}



回答4:


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();



回答5:


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.



来源:https://stackoverflow.com/questions/30913784/access-ios-control-center-using-appium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!