QQ group 288567073, no commercial advertising, daily dry e-book + video sharing
Lychee FM Mobile Client search for "Play talk show" to subscribe to us
Video Summary home: http://edu.51cto.com/lecturer/index/user_id-4626073.html
What is UI tests?
UI tests is a set of frameworks that Apple provides to us for UI testing.
What is the use of UI tests?
It can be used to write code, or to record the user's operation process and code it, to automatically click on a button, view, or automatically enter text and other functions.
The meaning of UI tests
In the actual project iteration, as the project becomes larger and more functional, it is very difficult to cover all the test cases in a manual way, especially after the new functionality is added, and the old functionality is re-tested, which leads to a test that takes a lot of time to perform regression testing. This creates a lot of repetitive work, and some of these repetitive tasks can be done automatically, and UI tests can help solve this problem.
How to use
First step: Add UI Tests.
In the case of a new project, the Include UI tests option can be checked directly when the project is created, and if it is an existing project, you can add a UI tests by adding a target, such as:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/75/09/wKioL1YxgqaBFFCZAAFWtAX91RM312.jpg "title=" 1.png " alt= "Wkiol1yxgqabffczaafwtax91rm312.jpg"/>
Select the cocoa Touch UI testing Bundle in the test option.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/75/0C/wKiom1Yxgn3DUT5hAAC-IZtn36c004.jpg "title=" 2.png " alt= "Wkiom1yxgn3dut5haac-iztn36c004.jpg"/>
Step Two: Create the test code.
There are two main ways to generate test code:
1. Create the test code manually.
Open the test file and add the test code in the Testxxx () method
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/75/0C/wKiom1YxgovDGf9BAAHzs-lUAAg052.jpg "title=" 3.png " alt= "Wkiom1yxgovdgf9baahzs-luaag052.jpg"/>
2. Generate the test code by recording the script.
After selecting the test file, click the Record button at the bottom left, and start the operation, which will record your steps and generate the test code.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/75/09/wKioL1YxgtGDvR1EAAFBKba_upM936.jpg "title=" 4.png " alt= "Wkiol1yxgtgdvr1eaafbkba_upm936.jpg"/>
Is the test code that is automatically generated after some operation.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/75/09/wKioL1Yxgt6hnuUkAADh4Hs_ppw219.jpg "title=" 5.png " alt= "Wkiol1yxgt6hnuukaadh4hs_ppw219.jpg"/>
With the auto-generated code snippet, we can analyze the structure of the test code and the names of some clickable controls, record these click methods and control names, and then write the test code yourself, knowing that manually created code can be more flexible than the recording method!
Step three: Start the test.
Click the Play button next to the Testexample method and it will start executing your test case, and you will see your test app in action automatically.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/75/09/wKioL1YxguiCxB9dAACpJCSz4Tk614.jpg "title=" 6.png " alt= "Wkiol1yxguicxb9daacpjcsz4tk614.jpg"/>
Introduction to UI tests syntax
Here we mainly introduce the main classes and methods of UI tests.
Xcuiapplication class:
Inherited from Xcuielement, this class governs the life cycle of an application and contains two main methods:
Launch (): Start program
Terminate (): Terminating program
xcuielement class:
inherits from NSObject, implements protocol Xcuielementattributes, Xcuielementtypequeryprovider, which can represent various UI elements of a system, consists of the following methods.
exist: Allows you to determine whether the current UI element exists.
descendantsmatchingtype (Type:xcuielementtype): Takes a certain type of element and its subclass collection.
childrenmatchingtype (Type:xcuielementtype): Takes a collection of elements of a certain type and does not contain its subclasses.
The difference between the two methods is that you only use the system's UIButton, you can use Childrenmatchingtype, if you also want to query your own defined child button, you need to use the Descendantsmatchingtype method.
In addition, UI elements have some interactive methods:
Tap (): Tap.
Doubletap (): Double-click.
Pressforduration (Duration:nstimeinterval): Long press for a period of time.
TypeText (text:string): Used for TextField and TextView input text, make sure the text box gets the input focus before use, you can use the tap () function to get focus.
Of course, here is just to give you a brief introduction of the commonly used functions, how to use the details you need to go further to explore Oh!
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/0C/wKiom1YxgsCj8ZjSAADqcjpg4hg916.jpg "title=" QQ group QR code. PNG "alt=" wkiom1yxgscj8zjsaadqcjpg4hg916.jpg "/>
New features of "dry" iOS9 UI Tests