Getting Started with XCUITest
Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to execution in minutes.
|
x
Blog
Getting Started with XCUITest
XCUITest is a test mechanization framework used for UI examination of mobile apps and web applications on iOS devices such as iPads and iPhones. Let & # x27; s discourse how to get depart.
XCUITestis a test automation framework used forUI testof mobile apps and web application on iOS devices such as iPads and iPhones. It is part of Apple ’ s testing framework.
XCUITest was unloose in 2015 as part of the broader XCTest system construct into XCode, Apple ’ s IDE (Integrated Developer Environment). Apple describes XCTest as a way to, “ Create and run unit tests, execution tryout, and UI exam for your Xcode project. ”
XCUITest besides supply a framework that allows developer to programmatically identify and interact with UI elements from other test creature. XCUITest replaced the older UIAutomator technology and is the only supported UI interaction library for iOS as of 2022.
What is UI Testing?
UI stands for “ user interface ” and refers to the variety, button, and other optic components your user interacts with.
To most users, your UIisyour app. Most (if not all) interactions a user has with your app will be via the user interface, so any shortcoming hither will be pronto apparent. Not entirely that, but defects from other parts of your app are often ponder in the UI. Because UI testing aims to insure a positive end-user experience, it can be used to drive farther, functional examination.
Why is UI Testing Important?
UI quizis (or should be) a major constituent of the tryout regimen for any user-oriented coating. While it resemble code/unit testing in overall outline and approach, it differs from functional/code-oriented examination in some fairly specific ways. The goal of UI testing is not to look at the covering & # x27; s internal operation. It is, sooner, to look at the application from the outside, and to test the application & # x27; s response to user actions.
In this way, it is similar toAPI testing—UI testing and API prove both focus on interface-based interactions with your app. In the case of UI testing, however, the interaction are not code-based API calls, but user actions by substance of iOS twist inputs.
Canonical UI test patterns
Most functional UI tests follow a basic pattern:
Do something to the app by way of the UI. For an iOS-based app, this typically involve tip, press, swiping, or early screen-based inputs.
Record or trance the app & # x27; s answer. This can include both screen recording and enchant the state of internal application data.
Measure the response against an expected response (by means of an assertion), then disc or describe the result.
A full UI test typically consists of a episode of UI-based actions, with each following the above pattern.
Performance-based UI tryout follow a somewhat different pattern:
Do something via the UI - an activeness or sequence of actions.
Record the clip ask to finish the activity and expected response.
Repeat the action or episode a set figure of times.
Report the ordinary windup time, plus outliers and former relevant statistic.
XCUITest vs. Appium
and are both tools for automate real and virtual mobile devices, and both can be used as part of a robust exam pipeline.
XCUITest is “ closer to the alloy ” – that is, it ’ s more tightly integrated with iOS apps than Appium. This gives XCUITest a tenuous execution speed advantage over Appium, and get for a simpler, iOS-only DevOps test toolchain. Because XCUITest is written by Apple, users are reliant on Apple for updates and characteristic.
On the other hand, Appium is Open Source package. This gives Appium a turgid community of users providing updates, capabilities and features. Unlike XCUITest, Appium is not restricted to mechanization of iOS applications; it too support Android and even Windows background applications. This makes Appium tooling and acquisition useful throughout the DevOps test toolchain, disregarding of the device being developed for.
XCUITest vs. Espresso
Espressois the testing framework that come built into Android Studio, and is designed specifically for functional examination of Android applications.
Like XCUITest, is popular among developers, as it is easy to set up, more stable than Appium, and gives them the ability to chop-chop test code constituent. With its robotlike synchronism of UI, Espresso allows for faster test performance. It also brings faster feedback for developers, as it does not take a server for communicating. The simplicity and convenience of this model too stanch from the fact that Android UI trial can be compiled into a freestanding APK, which allows for the tryout suites to run next to the app on the device.
Espresso likewise has the same lack of flexibleness that we see with XCUITest. Firstly, Espresso is but compatible with Java and Kotlin, meaning that your exam can exclusively be pen in these languages. Additionally, Espresso can simply be used to screen Android apps, and so if your team is developing an app that will be listed on both iOS and Android, you will postulate to regain another framework to assist ensure compatibility across these different operating systems.
Benefits of XCUITest
XCode consolidation
XCUITest ’ s principal value comes from its nigh consolidation with XCode. With XCUITest, tests can be fulfill directly from XCode itself. Your application and test code can be written in the like language (Objective-C or Swift), edited entirely within XCode, and stored in the like deposit.
This get writing unit, consolidation, and UI tests leisurely for your app developer.
Because XCUITest is so closely coupled with iOS, tests may execute faster compared with other solutions.
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
Test transcription
XCode offers the ability to “ Record ” examination; generating test codification by watching interactions a exploiter has with a connected Simulator or Real Device. This recorded test codification can then be tweaked to give a reliable, repeatable test, saving time during test creation.
Elastic component designation
XCUITest countenance testers to happen element by their title, label, value, or placeholder value. XCUIElements can also have a unique ‘ accessibility identifier ’ specified for use in testing but, which can make finding ingredient tight and easy.
The ‘ accessibility identifier ’ isnotrelated to the availableness label read by tools such as Voice Over, however, Accessibility Testing is possible with XCUITest.
Accessibility testing
Basic accessibility testing is possible in XCUITest by querying elements by their accessibility label and ensuring these labels make sense when read or heard.
There are besides instrument likeA11yUITests, which widen test cases to check for mutual accessibility issues.
Drawbacks of XCUITest
XCode (and thence macOS) is (about) mandatory
XCode need to be instal on every machine where your squad runs XCUITest. This include tester machines and CI/CD environments. Because XCode itself is macOS only, this can place important budgetary and technical constraint on your operating environments, and limit your ability to use SAAS CI/CD solutions… with one exclusion.
The Sauce Labs Continuous Testing Library provides teams tractableness and scale when using XCUITest. For more info, check out the “ XCUITest and SauceCTL ” section, below.
Constrained framework/language choice
Because XCUITest is both the examination fabricandthe device interaction creature, it constrains your options for pen and running your tests.
For starters, XCUITest code can ’ t be written in Java, JavaScript, .Net, Python, or most early languages. In order to read, pen and update tests, your team will involve to use either Objective-C or Swift.
XCUITest code can ’ t be run separately from the XCUITest framework; You must run the tests using the XCUITest runner.
XCUITest may not be full compatible with existing or planned digital confidence tooling. For instance, while a 3rd party integration survive to allow you to use XCUITest with the democratic Cucumber testing framework, it hasn ’ t been updated in overfour years(as of July 2022).
No Android support
XCUITest supports device from one manufacturer: Apple. It ’ s not possible to use XCUITest forAndroid app teston Android tablets, phones, or Wear device. This may result to teams having two completely separate test toolchains for iOS and Android.
5 XCUITest Best Practices
XCUITest includes the canonical features needed to perform UI test follow the practice described above. As is the event with all trial suite, however, the value of the tests depends powerfully on tryout design, implementation, and analysis—all of which are ultimately the responsibility of the testing team. Here are some good praxis for UI testing in the context of the XCUITest framework:
1. UI Recording is your friend
UI recording is one of the near significant built-in features of XCUITest. It grant you to record a exam interaction with your app & # x27; s UI, and save that interaction as test source code. You can then edit/tweak the codification to add test details (including XCTest asseveration), much like recording a macro for later editing and expansion. It may not be butch programming, but it saves time and trouble, and provides you with a dependable fabric of generated codification. The UI test recorder is also useful as an ongoing examination instrument. It furnish information about interactions with the UI, including application internals.
2. Sequence-dependent or sequence-independent
Recognize that UI tryout are mostly sequence-dependent (a given test step may only be capable to proceed if the late footstep is successful), and write test with this in mind. In your test code, self.continueAfterFailure will typically be set to NO to reflect this fact. If you are create UI exam that are not sequence-dependent (for instance, testing radio-button options which create an contiguous GUI response), you can set self.continueAfterFailure to YES, and make the appropriate viands in the trial codification.
3. Test the full range of interactions
XCUITest allows you to set user interactions with considerable preciseness in most cases. You can, for exemplar, specify tap (), doubleTap (), and twoFingerTap (); you can also set the number of lights-out. You can specify press () with a length, and with both a length and a dragging target. These interaction include four directional swipe (leave, flop, up, and down), pinch (), with scale and velocity, and revolve (), with speed. Different user have different UI interaction manner; you can make full use of these features to develop a more detailed painting of the results of such wide-ranging interactions.
4. Don & # x27; t forget availableness
Along with standard UI testing, quiz handicapped/hearing-/visually afflicted accessibility using the UIAccessibility protocol. In piece, this is a matter of good sense and proactive client service, since it maximizes your possible customer base. It may likewise turn out to be a practical necessity. Compliance with accessibility standards is becoming an increasingly common requirement for debut into many significant markets (including package for government use).
5. Go beyond standard functional and performance testing
Along with testing for error and failed responses, exam for unexpected or unwanted event which may not testify up as errors. These could include accidental energizing of unrelated features, actions that resolution in items being hidden or partly obscured, or early responses that interpose with the exploiter experience. Remember: if an app deeds, but is too vex to use, most citizenry won & # x27; t use it.
Getting Started with XCUITest on Sauce Labs
The CLI allows teams to runXCUITeston Windows, Linux and MacOS, at a great scale than would be possible when running trial topically.
By utilizing Sauce Labs ’ extensiveemulators and Real Device Cloud, saucectl afford teams flexibility and leisurely scale for their UI automation testing, along with the rich parallelization, trial history filtering, and analytics of Sauce Labs.
Test codification and the app under tryout are uploaded to a exploiter ’ s choice of regional datacenter and run in serial or parallel. Test videos and screenshots are record and make usable after test, and results are reported “ locally. ”
This allows developer to run the same tryout on their dev machine while do changes as they do at scale when deploying, saving time and guarantee eminent lineament outcomes.
More XCUITest resourcefulness
Jump to content
What is XCUITest?
What is UI Testing?
Why is UI Testing Important?
XCUITest vs. Appium
XCUITest vs. Espresso
Benefits of XCUITest
Drawbacks of XCUITest
Getting Started with XCUITest on Sauce Labs
Topics
Share this place
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free
