Accessing iOS Control Center Using Appium

Accessing iOS Control Center Using Appium

21 May 2024 Stephan Petzl Leave a comment Tech-Help

Opening the Control Center on iOS devices using Appium can be a bit challenging. This guide will help you understand the most effective methods to achieve this, ensuring your automated tests can interact with the Control Center seamlessly.

Common Approach for Accessing Control Center

One of the widely used approaches involves simulating a swipe action from the bottom of the screen. This method has been tested and proven to work on various iOS versions and devices. Below is the code snippet that you can use:

int height = driver.findElementByClassName("UIAWindow").getSize().getHeight();
int width = driver.findElementByClassName("UIAWindow").getSize().getWidth();
driver.swipe(width-100, height, width-100, height-200, 500);

This method performs a swipe action from near the bottom of the screen to a higher point, simulating the gesture used to open the Control Center. After opening the Control Center, you can interact with various elements, such as toggling Wi-Fi.

Alternative Methods

If the above method does not work for your specific setup, you might consider the following alternative approach:

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, start_x, start_y).wait(100).move_to(el, end_x, end_y).release().perform()

This Python code snippet performs a similar swipe action but uses different coordinates and a TouchAction object for more control over the gesture.

Considerations for Different iOS Versions

It’s important to note that different iOS versions and device models may require slight adjustments to the coordinates and swipe actions. For instance, iPhone models with notches or different screen sizes might need custom coordinates:

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))
        .moveTo(PointOption.point(x, endY))

This code snippet adjusts the swipe action to account for devices with notches, such as the iPhone 11, by swiping from the top-right corner.

Enhancing Your Test Automation

While Appium is a powerful tool for test automation, it can sometimes be slow and prone to instability. This is where Repeato can significantly enhance your testing workflow. Repeato is a no-code test automation tool for iOS and Android that leverages computer vision and AI to create, run, and maintain tests more efficiently.

Compared to Appium, Repeato offers faster test creation and execution, making it ideal for teams looking to streamline their testing processes. Its intuitive interface and robust features ensure that your tests are not only quicker to set up but also more reliable.

For more information on how Repeato can improve your test automation, visit our Getting Started page.

Like this article? there’s more where that came from!