XCUITests — Interact with Settings Application

Nishith Shah
Quality Engineering University
2 min readJun 13, 2020
Photo by James Harrison on Unsplash

Using XCUITests, you can interact with any of the System/Installed applications. For example, if you want to collect the device information, now this is possible using XCUITests.

First, we need to launch the Settings application just like a normal app and provide its bundle identifier.

In the General -> About section, we can see all the information about the device. If you want to use any of the device information then you can collect it using XCUITests.

Here, I will show you how can you get Serial Number of your device.

First, please create the following class in your project.

public class Settings {
private var app: XCUIApplication?
public func launch() -> Settings {
self.app = XCUIApplication(bundleIdentifier:Application.settings.bundleId)
self.app?.launch()
return self
}
public func navigateTo(option: String) -> Settings {
self.app?.descendants(matching: .staticText)[option].tap()
return self
}
public func value(option: String) -> Any? {
return self.app?.descendants(matching: .cell)[option].value
}
}

Here is the code that you have to add in your XCUITest script from where you want to get the value.

Settings()
.launch()
.navigateTo(option: "General")
.navigateTo(option: "About")
.value(option: "Serial Number")

This is just one example to interact with the Settings Application. You can also do interaction with Wi-Fi, Bluetooth, Location services very easily.

Let me know — along with any questions, comments, or feedback that you might have on https://www.linkedin.com/in/nshthshah.

--

--