iOS native automation testing
Last updated
Last updated
Appfigurate doesn't currently support automation testing watchOS, iOS Mobile Flutter apps or iOS React Native apps.
Appfigurate can change the configuration of an iOS app being automation tested using XCTestCase
.
An example UI testing bundle AppfigurateExampleUITests
is available in both Objective-C example and Swift example GitHub repositories. To test, ensure AppfigurateExample (ObjC/Swift iOS)
is selected as the scheme, then long tap the run button to show more options and tap Test
(⌘U).
Tap on your APLConfiguration
subclass in the project navigator. In File inspector ‣ Target membership, tick on your UI testing bundle.
In your APLConfiguration
subclass, confirm that your allowInvalidSignatures method returns YES
/true
when running automation tests. (Test schemes are by default run with a DEBUG build).
When the configuration is applied to the application on launch, the standard Appfigurate 'Configuration applied' alert is displayed. It is recommended you add an UIInterruptionMonitor
to your XCTestCase
to automatically dismiss this alert. A good place to do this in the setUp
method.
Get an instance of your APLConfiguration
subclass in your XCTestCase
. A good place to do this in the setUp
method.
Set the properties required to be applied to your app to allow it to be tested correctly.
Apply the result of APLConfiguration
automationLaunchArguments method to XCUIApplication launchArguments
property.
Launch your app.
Once your app is launched, the configuration you set in Create instance of APLConfiguration subclass will be applied before executing each test case.
See also automationLaunchArgumentsReset and automationLaunchArgumentsWithAction methods of APLConfiguration
.
You can apply configuration to the app after it has launched using the automationSendConfiguration, automationSendConfigurationReset and automationSendConfigurationWithAction methods of APLConfiguration
. You can read the configuration from the app under test using the automationSendReadConfiguration method.
Under the hood, the automationSendConfiguration, automationSendConfigurationReset, automationSendConfigurationwithAction and automationSendReadConfiguration methods use the APLAutomationSendMessage and APLAutomationMessageReceivedBlock functions introduced in the next section.
Appfigurate allows you to invoke functionality in the app under test, at runtime, from your XCTestCase
. Example use cases:
Setting mocked HTTP responses for HTTP requests in the app.
Share mocked objects between the XCTestCase
and app.
Read and set the internal state of the app.
Use the APLAutomationMessageReceivedBlock function in the app under test to declare a callback. The callback will be invoked anytime a message is received from the XCTestCase
. Best practice is to wrap the function in #if DEBUG
to ensure it's not included in an App Store build.
Use the APLAutomationSendMessage function in your XCTestCase
to send a message and wait for a reply from the app under test.
The APLAutomationSendMessage and APLAutomationMessageReceivedBlock is compatible with both iOS Simulators and physical iOS devices.
The APLAutomationSendMessage plist
parameter accepts any object that is property list compatible, or nil
. This also applies to the result returned from APLAutomationMessageReceivedBlock. The size of the property list once serialized, must be less than 65535 bytes, otherwise an AppfigurateLibraryException
will be thrown from the XCTestCase
. In practice, keep your property lists to just a few hundred bytes. Larger property lists will result in significant transmission time (tens of seconds).