SlideShare a Scribd company logo
UI Testing in Xcode 7
Dominique Stranz
UI TESTING IN XCODE 7
Example Test: Successful user login
1) tap my account button
2) tap log in button
3) tap & type e-mail
4) tap & type password
5) tap log in button
UI TESTING IN XCODE 7
Example Test: Successful user login
@interface	Account	:	XCTestCase	
@property	(strong)	TestUser	*user;	
@end	
@implementation	Account	
-	(void)setUp	{	
				[super	setUp];	
				[self	createUser];	//we	are	creating	test	user	account	here,	it	will	be	used	in	all	test	cases	
				self.continueAfterFailure	=	NO;	
}	
-	(void)tearDown	{	
			[super	tearDown];	
}	
-	(void)testLogin_CredentialsAreValid_ShouldLogin	{	
}
RECORDING…
UI TESTING IN XCODE 7
Recording…
Problem with non-ascii characters
Not so useful with localised appsComplicated and not
universal queries
Testability
Quality of Accessibility Data
source: WWDC, Session 406
UI TESTING IN XCODE 7
UIAccessibility identifiers
Unique identifiers allow recorder to use simpler queries
‣ Locale independent
‣ Ignored by Voice Over
UI TESTING IN XCODE 7
How to set UIAccessibility identifiers?
@protocol	UIAccessibilityIdentification	<NSObject>	
@required	
/*	
	A	string	that	identifies	the	user	interface	element.	
	default	==	nil	
*/	
@property(nullable,	nonatomic,	copy)	NSString	*accessibilityIdentifier	
NS_AVAILABLE_IOS(5_0);	
@end
UI TESTING IN XCODE 7
We can choose from several options to find element
We should use more precise query, if our accessibility
identifier or label isn’t unique:
UI TESTING IN XCODE 7
Why not share our identifiers between app & test targets?
…and finally use user credentials created in setUp method.
EXPLANATION
UI TESTING IN XCODE 7
XCUIElement - proxy for all application UI elements
XCUIElement UIButton
UITextField
UITableViewCell
and others…
‣ currentTitle
‣ currentAttributedTitle
‣ text
‣ placeholder
‣ textLabel.text
‣ detailTextLabel.text
‣ title
‣ label
‣ value
‣ placeholderValue
‣ identifier
‣ selected
‣ frame
‣ …
UI TESTING IN XCODE 7
Interactions
XCUIElement
‣ title
‣ label
‣ value
‣ placeholderValue
‣ identifier
‣ selected
‣ frame
‣ …
-	(void)typeText:(NSString	*)text;	
-	(void)tap;	
-	(void)doubleTap;	
-	(void)twoFingerTap;	
-	(void)tapWithNumberOfTaps:(NSUInteger)numberOfTaps		
numberOfTouches:(NSUInteger)numberOfTouches;	
-	(void)pressForDuration:(NSTimeInterval)duration;	
-	(void)pressForDuration:(NSTimeInterval)duration		
thenDragToElement:(XCUIElement	*)otherElement;	
-	(void)swipeUp;	
-	(void)swipeDown;	
-	(void)swipeLeft;	
-	(void)swipeRight;	
-	(void)pinchWithScale:(CGFloat)scale	velocity:(CGFloat)velocity;	
-	(void)rotate:(CGFloat)rotation	withVelocity:(CGFloat)velocity;
UI TESTING IN XCODE 7
Element queries
XCUIElement
‣ title
‣ label
‣ value
‣ placeholderValue
‣ identifier
‣ selected
‣ frame
‣ …
/*!	Returns	a	query	for	all	descendants	of	the	element	matching	the	
specified	type.	*/	
-	(XCUIElementQuery	*)descendantsMatchingType:(XCUIElementType)type;	
/*!	Returns	a	query	for	direct	children	of	the	element	matching	the	
specified	type.	*/	
-	(XCUIElementQuery	*)childrenMatchingType:(XCUIElementType)type;
UI TESTING IN XCODE 7
Element queries
XCUIElement
‣ title
‣ label
‣ value
‣ placeholderValue
‣ identifier
‣ selected
‣ frame
‣ …
/*!	Returns	a	query	for	all	descendants	of	the	element	matching	the	
specified	type.	*/	
-	(XCUIElementQuery	*)descendantsMatchingType:(XCUIElementType)type;	
@property	(readonly,	copy)	XCUIElementQuery	*tables;	
@property	(readonly,	copy)	XCUIElementQuery	*buttons;	
@property	(readonly,	copy)	XCUIElementQuery	*staticTexts;	
@property	(readonly,	copy)	XCUIElementQuery	*textFields;	
@property	(readonly,	copy)	XCUIElementQuery	*secureTextFields;	
@property	(readonly,	copy)	XCUIElementQuery	*textViews;
UI TESTING IN XCODE 7
Element queries
XCUIElement
‣ title
‣ label
‣ value
‣ placeholderValue
‣ identifier
‣ selected
‣ frame
‣ …
[element	descendantsMatchingType:XCUIElementTypeButton];	
element.buttons
UI TESTING IN XCODE 7
Root element - XCUIApplication
@interface	XCUIApplication	:	XCUIElement	
-	(void)launch;	
-	(void)terminate;	
@property	(nonatomic,	copy)	NSArray	<NSString	*>	*launchArguments;	
@property	(nonatomic,	copy)	NSDictionary	<NSString	*,	NSString	*>	*launchEnvironment;	
@end
UI TESTING IN XCODE 7
XCUIElementQuery
@interface	XCUIElementQuery	:	NSObject	<XCUIElementTypeQueryProvider>	
@property	(readonly)	NSUInteger	count;	
-	(XCUIElement	*)elementBoundByIndex:(NSUInteger)index;	
-	(XCUIElement	*)elementMatchingPredicate:(NSPredicate	*)predicate;	
-	(XCUIElement	*)elementMatchingType:(XCUIElementType)elementType	

																	identifier:(nullable	NSString	*)identifier;	
-	(XCUIElement	*)objectForKeyedSubscript:(NSString	*)key;	
@end
UI TESTING IN XCODE 7
XCUIElementQuery
@interface	XCUIElementQuery	:	NSObject	<XCUIElementTypeQueryProvider>	
@property	(readonly)	NSUInteger	count;	
-	(XCUIElement	*)elementBoundByIndex:(NSUInteger)index;	
-	(XCUIElement	*)elementMatchingPredicate:(NSPredicate	*)predicate;	
-	(XCUIElement	*)elementMatchingType:(XCUIElementType)elementType	

																	identifier:(nullable	NSString	*)identifier;	
-	(XCUIElement	*)objectForKeyedSubscript:(NSString	*)key;	
@end	
▸ Evaluates the query
▸ Return the number of matches found
UI TESTING IN XCODE 7
XCUIElementQuery
@interface	XCUIElementQuery	:	NSObject	<XCUIElementTypeQueryProvider>	
@property	(readonly)	NSUInteger	count;	
-	(XCUIElement	*)elementBoundByIndex:(NSUInteger)index;	
-	(XCUIElement	*)elementMatchingPredicate:(NSPredicate	*)predicate;	
-	(XCUIElement	*)elementMatchingType:(XCUIElementType)elementType	

																	identifier:(nullable	NSString	*)identifier;	
-	(XCUIElement	*)objectForKeyedSubscript:(NSString	*)key;	
@end	
▸ Return nth element in query results
▸ Example:
XCUIElement	*firstCell	=	[app.tables.cells	elementBoundByIndex:0];
UI TESTING IN XCODE 7
XCUIElementQuery
@interface	XCUIElementQuery	:	NSObject	<XCUIElementTypeQueryProvider>	
@property	(readonly)	NSUInteger	count;	
-	(XCUIElement	*)elementBoundByIndex:(NSUInteger)index;	
-	(XCUIElement	*)elementMatchingPredicate:(NSPredicate	*)predicate;	
-	(XCUIElement	*)elementMatchingType:(XCUIElementType)elementType	

																	identifier:(nullable	NSString	*)identifier;	
-	(XCUIElement	*)objectForKeyedSubscript:(NSString	*)key;	
@end	
▸ Example:
NSPredicate	*labelPrefixPredicate	=	[NSPredicate	predicateWithFormat:	
																									@"label	BEGINSWITH	%@",	prefix];	
XCUIElement	*label	=	[app.staticTexts		
									elementMatchingPredicate:labelPrefixPredicate];
UI TESTING IN XCODE 7
XCUIElementQuery
@interface	XCUIElementQuery	:	NSObject	<XCUIElementTypeQueryProvider>	
@property	(readonly)	NSUInteger	count;	
-	(XCUIElement	*)elementBoundByIndex:(NSUInteger)index;	
-	(XCUIElement	*)elementMatchingPredicate:(NSPredicate	*)predicate;	
-	(XCUIElement	*)elementMatchingType:(XCUIElementType)elementType	

																	identifier:(nullable	NSString	*)identifier;	
-	(XCUIElement	*)objectForKeyedSubscript:(NSString	*)key;	
@end	
▸ Example:
XCUIElement	*button	=	[app	elementMatchingType:XCUIElementTypeButton	
																											identifier:@"login"];
UI TESTING IN XCODE 7
XCUIElementQuery
@interface	XCUIElementQuery	:	NSObject	<XCUIElementTypeQueryProvider>	
@property	(readonly)	NSUInteger	count;	
-	(XCUIElement	*)elementBoundByIndex:(NSUInteger)index;	
-	(XCUIElement	*)elementMatchingPredicate:(NSPredicate	*)predicate;	
-	(XCUIElement	*)elementMatchingType:(XCUIElementType)elementType	

																	identifier:(nullable	NSString	*)identifier;	
-	(XCUIElement	*)objectForKeyedSubscript:(NSString	*)key;	
@end	
▸ Example:
XCUIElement	*button	=	app.buttons[@"login"];
DEMO
UI TESTING IN XCODE 7
How to asset test results?
▸ We can use all variants of XCTAssert macro
▸ But more accurate for asynchronous UI are expectations
XCUIElement	*loggedInLabel	=	app.tables.staticTexts[Identifier_Account_LoggedInLabel];	
				
NSPredicate	*exists	=	[NSPredicate	predicateWithFormat:@"exists	==	1"];	
[self	expectationForPredicate:exists	evaluatedWithObject:loggedInLabel	handler:nil];	
[self	waitForExpectationsWithTimeout:15	handler:nil];
UI TESTING IN XCODE 7
Performance test
-	(void)testLogin_CredentialsAreValid_ShouldLogin	{	
[self	measureBlock:^{	
//UITest	code	
}];	
}
▸ Xcode executes each test 10 times and compare average execution
time with baseline (selected from previous results)
▸ Test will fail if new average has increased from baseline by 10% or
more, but it will ignore regressions of less than a tenth of a second
TIPS & TRICKS
UI TESTING IN XCODE 7
Handle UI interruptions
▸ Setup interruptions monitor
[self	addUIInterruptionMonitorWithDescription:@"Location	Permission"		
handler:^BOOL(XCUIElement	*element)	{	
								XCUIElement	*button	=	alert.buttons[@"Allow"];	
								if	(button.exists)	{	
												[button	tap];	
												return	true;	
								}	
								return	false;	
				}];	
▸ Handlers are invoked in reverse order
until one of them return true
1 2
UI TESTING IN XCODE 7
Handle UI interruptions
▸ By default, XCode 7.2 will try to find &
tap elements matching predicate:
userTestingAttributes	CONTAINS	"cancel-button"
userTestingAttributes	CONTAINS	"default-button"
1 2
UI TESTING IN XCODE 7
Handle UI interruptions
▸ By default, XCode 7.2 will try to find &
tap elements matching predicate:
userTestingAttributes	CONTAINS	"cancel-button"
userTestingAttributes	CONTAINS	"default-button"
2▸ Do you prefer confirm button as first
choice? Add your own monitor:
NSPredicate	*predicate	=	[NSPredicate	predicateWithFormat:	
									@"userTestingAttributes	CONTAINS	"default-button""];	
XCUIElement	*button	=	[alert.buttons	elementMatchingPredicate:predicate];	
if	(button.exists)	{	
				[button	tap];	
				return	true;	
}
UI TESTING IN XCODE 7
Typing in secure text field doesn’t work
▸ Workaround: Disconnect Hardware Keyboard in Simulator
▸ „Neither element or any descendant has keyboard focus”
error occurs when you are trying to type in secure UITextField
▸ Instead, we should check if element is hittable:
UI TESTING IN XCODE 7
Why your test is not waiting for hidden elements?
▸ Hidden elements fulfil exists predicate:
			[NSPredicate	predicateWithFormat:@"exists	==	1"]
			[NSPredicate	predicateWithFormat:@"hittable	==	1"]
UI TESTING IN XCODE 7
How to detect that app is in test mode?
				XCUIApplication	*	app	=	[[XCUIApplication	alloc]	init];	
				[app	setLaunchArguments:@[@"UITESTS"]];	
				[app	launch];	
				NSArray	*arguments	=	[[NSProcessInfo	processInfo]	arguments];	
				if	([arguments	containsObject:@"UITESTS"])	{	
								//Customize	app	for	tests	
				}
▸ In test file:
▸ In application:
UI TESTING IN XCODE 7
How to speed up tests?
▸ Disable animations in AppDelegate:
				NSArray	*arguments	=	[[NSProcessInfo	processInfo]	arguments];	
				if	([arguments	containsObject:@"UITESTS"])	{	
									[UIView	setAnimationsEnabled:NO];	
				}
▸ Waiting for element is one of the most cases in UI tests,
why not use convenient helper?
UI TESTING IN XCODE 7
Waiting for elements shortcuts
NSPredicate	*exists	=	[NSPredicate	predicateWithFormat:@"exists	==	1"];	
[self	expectationForPredicate:exists	evaluatedWithObject:element	handler:nil];	
[self	waitForExpectationsWithTimeout:15	handler:nil];	
[self	waitForElement:element];
[self	waitForElement:button	withTimeout:60];
▸ Waiting for element is one of the most cases in UI tests,
why not use convenient helper?
UI TESTING IN XCODE 7
Waiting for elements shortcuts
NSPredicate	*exists	=	[NSPredicate	predicateWithFormat:@"hittable	==	1"];	
[self	expectationForPredicate:exists	evaluatedWithObject:element	handler:nil];	
[self	waitForExpectationsWithTimeout:15	handler:nil];	
[self	waitForElementHittable:element];
[self	waitForElementHittable:button	withTimeout:60];
▸ Waiting for element is one of the most cases in UI tests,
why not use convenient helper?
UI TESTING IN XCODE 7
Waiting for elements shortcuts
NSPredicate	*exists	=	[NSPredicate	predicateWithFormat:@"hittable	==	1"];	
[self	expectationForPredicate:exists	evaluatedWithObject:element	handler:nil];	
[self	waitForExpectationsWithTimeout:15	handler:nil];	
[self	waitForElementHittable:element];
[self	waitForElementHittable:button	withTimeout:60];
https://github.com/dstranz/XCUITestsAdditions
pod	"XCUITestsAdditions"
UI TESTING IN XCODE 7
Change device orientation
[[XCUIDevice	sharedDevice]	setOrientation:UIDeviceOrientationLandscapeRight];	
[[XCUIDevice	sharedDevice]	setOrientation:UIDeviceOrientationLandscapeLeft];	
▸ Landscape
[[XCUIDevice	sharedDevice]	setOrientation:UIDeviceOrientationPortraitFaceUp];	
[[XCUIDevice	sharedDevice]	setOrientation:UIDeviceOrientationPortraitFaceDown];
▸ Portait
UI TESTING IN XCODE 7
Simulates the user pressing a physical button
[[XCUIDevice	sharedDevice]	pressButton:XCUIDeviceButtonHome];
[[XCUIDevice	sharedDevice]	pressButton:XCUIDeviceButtonVolumeUp];
[[XCUIDevice	sharedDevice]	pressButton:XCUIDeviceButtonVolumeDown];
▸ Home button
▸ Volume up
▸ Volume down
▸ Volume up & down doesn’t work on simulator
UI TESTING IN XCODE 7
Test coverage
UI TESTING IN XCODE 7
How to reset simulator state before each test?
It’s not possible to force launching app on clean simulator
(rdar://22455111).
What are workarounds?
UI TESTING IN XCODE 7
How to reset simulator state before each test?
▸ If you are using CI, you can run xcrun simctl erase all
between each test cases
▸ You can clean NSUserDefaults and Keychain in
AppDelegate, when app is in UITests mode
▸ …or rollback changes in tearDown method 

(for example logout user after login test)
THANK YOU

More Related Content

What's hot

JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
維佋 唐
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
Rafael Winterhalter
 
Real World Dependency Injection - phpday
Real World Dependency Injection - phpdayReal World Dependency Injection - phpday
Real World Dependency Injection - phpdayStephan Hochdörfer
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
Rabble .
 
Android development with Scala and SBT
Android development with Scala and SBTAndroid development with Scala and SBT
Android development with Scala and SBT
Anton Yalyshev
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
Jeado Ko
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
Antonio Goncalves
 
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Anna Shymchenko
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
Rodica Dada
 
Productive Debugging
Productive DebuggingProductive Debugging
Productive Debugging
iThink
 
XCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with XcodeXCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with Xcode
pCloudy
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
GDG Korea
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpdayStephan Hochdörfer
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayCodecademy Ren
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
epamspb
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
Lilia Sfaxi
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
Apptension
 
Are app servers still fascinating
Are app servers still fascinatingAre app servers still fascinating
Are app servers still fascinating
Antonio Goncalves
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applicationsDmitry Matyukhin
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
David Rodenas
 

What's hot (20)

JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Real World Dependency Injection - phpday
Real World Dependency Injection - phpdayReal World Dependency Injection - phpday
Real World Dependency Injection - phpday
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
 
Android development with Scala and SBT
Android development with Scala and SBTAndroid development with Scala and SBT
Android development with Scala and SBT
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
Productive Debugging
Productive DebuggingProductive Debugging
Productive Debugging
 
XCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with XcodeXCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with Xcode
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpday
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ay
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
 
Are app servers still fascinating
Are app servers still fascinatingAre app servers still fascinating
Are app servers still fascinating
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applications
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 

Viewers also liked

Migrating from Objective-C to Swift
Migrating from Objective-C to SwiftMigrating from Objective-C to Swift
Migrating from Objective-C to Swift
Dominique Stranz
 
E book introducing_microsoft_social_engagement_source
E book  introducing_microsoft_social_engagement_sourceE book  introducing_microsoft_social_engagement_source
E book introducing_microsoft_social_engagement_source
Imix Colombia
 
Looking into the Future of Wealth Management - A Sawtooth Solutions White Paper
Looking into the Future of Wealth Management - A Sawtooth Solutions White PaperLooking into the Future of Wealth Management - A Sawtooth Solutions White Paper
Looking into the Future of Wealth Management - A Sawtooth Solutions White Paper
Rich Conley
 
Diversity and Recruitment for the City of Boulder
Diversity and Recruitment for the City of BoulderDiversity and Recruitment for the City of Boulder
Diversity and Recruitment for the City of Boulder
Alan Murdock
 
Juhlat spring
Juhlat  springJuhlat  spring
Juhlat spring
Terttu Lajunen
 
II World War
II World WarII World War
II World War
Wikiteacher
 
Technology Vision 2017 - Tendencia 4
Technology Vision 2017 - Tendencia 4Technology Vision 2017 - Tendencia 4
Technology Vision 2017 - Tendencia 4
AccentureChile
 
Phenq coupon
Phenq couponPhenq coupon
Phenq coupon
phenqcoupon coupon
 
Grafike - Graphics and digital print
Grafike - Graphics and digital print Grafike - Graphics and digital print
Grafike - Graphics and digital print Branko Jovanović
 
Plan palomino de pelicula
Plan palomino de peliculaPlan palomino de pelicula
Plan palomino de pelicula
Eduardo Granados Marquez
 
Impact Investing Nieuws 1 April 2017
Impact Investing Nieuws 1 April 2017Impact Investing Nieuws 1 April 2017
Impact Investing Nieuws 1 April 2017
Drs Alcanne Houtzaager MA
 
Benefits of CRM for Higher Education Institutes
Benefits of CRM for Higher Education InstitutesBenefits of CRM for Higher Education Institutes
Benefits of CRM for Higher Education Institutes
Rolustech - Dynamic IT Solutions
 
Bajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieli
Bajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieliBajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieli
Bajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieli
Mariusz Kanicki
 
Inesting: aplicação de inovação evolutiva
Inesting: aplicação de inovação evolutivaInesting: aplicação de inovação evolutiva
Inesting: aplicação de inovação evolutiva
Francesco Berrettini
 
An Integration-Oriented Ontology to Govern Evolution in Big Data Ecosytems
An Integration-Oriented Ontology to Govern Evolution in Big Data EcosytemsAn Integration-Oriented Ontology to Govern Evolution in Big Data Ecosytems
An Integration-Oriented Ontology to Govern Evolution in Big Data Ecosytems
Supersede
 
SECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDS
SECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDSSECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDS
SECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDS
Gyan Prakash
 
Le demenze.
Le demenze. Le demenze.
Le demenze.
Gabriele Carbone
 
Russian system
Russian systemRussian system
Russian system
Dergalev Leonid
 
Google blogger
Google bloggerGoogle blogger
Google blogger
Maikku Sarvas
 

Viewers also liked (19)

Migrating from Objective-C to Swift
Migrating from Objective-C to SwiftMigrating from Objective-C to Swift
Migrating from Objective-C to Swift
 
E book introducing_microsoft_social_engagement_source
E book  introducing_microsoft_social_engagement_sourceE book  introducing_microsoft_social_engagement_source
E book introducing_microsoft_social_engagement_source
 
Looking into the Future of Wealth Management - A Sawtooth Solutions White Paper
Looking into the Future of Wealth Management - A Sawtooth Solutions White PaperLooking into the Future of Wealth Management - A Sawtooth Solutions White Paper
Looking into the Future of Wealth Management - A Sawtooth Solutions White Paper
 
Diversity and Recruitment for the City of Boulder
Diversity and Recruitment for the City of BoulderDiversity and Recruitment for the City of Boulder
Diversity and Recruitment for the City of Boulder
 
Juhlat spring
Juhlat  springJuhlat  spring
Juhlat spring
 
II World War
II World WarII World War
II World War
 
Technology Vision 2017 - Tendencia 4
Technology Vision 2017 - Tendencia 4Technology Vision 2017 - Tendencia 4
Technology Vision 2017 - Tendencia 4
 
Phenq coupon
Phenq couponPhenq coupon
Phenq coupon
 
Grafike - Graphics and digital print
Grafike - Graphics and digital print Grafike - Graphics and digital print
Grafike - Graphics and digital print
 
Plan palomino de pelicula
Plan palomino de peliculaPlan palomino de pelicula
Plan palomino de pelicula
 
Impact Investing Nieuws 1 April 2017
Impact Investing Nieuws 1 April 2017Impact Investing Nieuws 1 April 2017
Impact Investing Nieuws 1 April 2017
 
Benefits of CRM for Higher Education Institutes
Benefits of CRM for Higher Education InstitutesBenefits of CRM for Higher Education Institutes
Benefits of CRM for Higher Education Institutes
 
Bajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieli
Bajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieliBajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieli
Bajki giełdowe czyli jak inwestorzy na wezwanie odpowiedzieć nie chcieli
 
Inesting: aplicação de inovação evolutiva
Inesting: aplicação de inovação evolutivaInesting: aplicação de inovação evolutiva
Inesting: aplicação de inovação evolutiva
 
An Integration-Oriented Ontology to Govern Evolution in Big Data Ecosytems
An Integration-Oriented Ontology to Govern Evolution in Big Data EcosytemsAn Integration-Oriented Ontology to Govern Evolution in Big Data Ecosytems
An Integration-Oriented Ontology to Govern Evolution in Big Data Ecosytems
 
SECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDS
SECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDSSECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDS
SECURE & EFFICIENT AUDIT SERVICE OUTSOURCING FOR DATA INTEGRITY IN CLOUDS
 
Le demenze.
Le demenze. Le demenze.
Le demenze.
 
Russian system
Russian systemRussian system
Russian system
 
Google blogger
Google bloggerGoogle blogger
Google blogger
 

Similar to UI testing in Xcode 7

7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS
Jorge Ortiz
 
Unit testing on mobile apps
Unit testing on mobile appsUnit testing on mobile apps
Unit testing on mobile apps
Buşra Deniz, CSM
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
Automated Xcode 7 UI Testing
Automated Xcode 7 UI TestingAutomated Xcode 7 UI Testing
Automated Xcode 7 UI Testing
Jouni Miettunen
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
iOS
iOSiOS
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
 
WinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test AutomationWinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test Automation
Jeremy Kao
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu
 
Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web Developers
Joris Verbogt
 
Quick Start to iOS Development
Quick Start to iOS DevelopmentQuick Start to iOS Development
Quick Start to iOS DevelopmentJussi Pohjolainen
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative versionWO Community
 
Testable JavaScript: Application Architecture
Testable JavaScript:  Application ArchitectureTestable JavaScript:  Application Architecture
Testable JavaScript: Application Architecture
Mark Trostler
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
Matteo Manchi
 
Beginning iPhone Development
Beginning iPhone DevelopmentBeginning iPhone Development
Beginning iPhone Development
sgleadow
 
Cross Platform Appium Tests: How To
Cross Platform Appium Tests: How ToCross Platform Appium Tests: How To
Cross Platform Appium Tests: How To
GlobalLogic Ukraine
 
iOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEiOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEE
Hendrik Ebel
 
iOS testing
iOS testingiOS testing
iOS testing
Tomasz Janeczko
 
From C++ to Objective-C
From C++ to Objective-CFrom C++ to Objective-C
From C++ to Objective-C
corehard_by
 

Similar to UI testing in Xcode 7 (20)

7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS
 
Unit testing on mobile apps
Unit testing on mobile appsUnit testing on mobile apps
Unit testing on mobile apps
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 
Automated Xcode 7 UI Testing
Automated Xcode 7 UI TestingAutomated Xcode 7 UI Testing
Automated Xcode 7 UI Testing
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
iOS
iOSiOS
iOS
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
WinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test AutomationWinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test Automation
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web Developers
 
Quick Start to iOS Development
Quick Start to iOS DevelopmentQuick Start to iOS Development
Quick Start to iOS Development
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
 
Testable JavaScript: Application Architecture
Testable JavaScript:  Application ArchitectureTestable JavaScript:  Application Architecture
Testable JavaScript: Application Architecture
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
Beginning iPhone Development
Beginning iPhone DevelopmentBeginning iPhone Development
Beginning iPhone Development
 
Cross Platform Appium Tests: How To
Cross Platform Appium Tests: How ToCross Platform Appium Tests: How To
Cross Platform Appium Tests: How To
 
iOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEiOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEE
 
iOS testing
iOS testingiOS testing
iOS testing
 
From C++ to Objective-C
From C++ to Objective-CFrom C++ to Objective-C
From C++ to Objective-C
 

UI testing in Xcode 7

  • 1. UI Testing in Xcode 7 Dominique Stranz
  • 2.
  • 3. UI TESTING IN XCODE 7 Example Test: Successful user login 1) tap my account button 2) tap log in button 3) tap & type e-mail 4) tap & type password 5) tap log in button
  • 4. UI TESTING IN XCODE 7 Example Test: Successful user login @interface Account : XCTestCase @property (strong) TestUser *user; @end @implementation Account - (void)setUp { [super setUp]; [self createUser]; //we are creating test user account here, it will be used in all test cases self.continueAfterFailure = NO; } - (void)tearDown { [super tearDown]; } - (void)testLogin_CredentialsAreValid_ShouldLogin { }
  • 6. UI TESTING IN XCODE 7 Recording… Problem with non-ascii characters Not so useful with localised appsComplicated and not universal queries
  • 7. Testability Quality of Accessibility Data source: WWDC, Session 406
  • 8. UI TESTING IN XCODE 7 UIAccessibility identifiers Unique identifiers allow recorder to use simpler queries ‣ Locale independent ‣ Ignored by Voice Over
  • 9. UI TESTING IN XCODE 7 How to set UIAccessibility identifiers? @protocol UIAccessibilityIdentification <NSObject> @required /* A string that identifies the user interface element. default == nil */ @property(nullable, nonatomic, copy) NSString *accessibilityIdentifier NS_AVAILABLE_IOS(5_0); @end
  • 10. UI TESTING IN XCODE 7 We can choose from several options to find element We should use more precise query, if our accessibility identifier or label isn’t unique:
  • 11. UI TESTING IN XCODE 7 Why not share our identifiers between app & test targets? …and finally use user credentials created in setUp method.
  • 13. UI TESTING IN XCODE 7 XCUIElement - proxy for all application UI elements XCUIElement UIButton UITextField UITableViewCell and others… ‣ currentTitle ‣ currentAttributedTitle ‣ text ‣ placeholder ‣ textLabel.text ‣ detailTextLabel.text ‣ title ‣ label ‣ value ‣ placeholderValue ‣ identifier ‣ selected ‣ frame ‣ …
  • 14. UI TESTING IN XCODE 7 Interactions XCUIElement ‣ title ‣ label ‣ value ‣ placeholderValue ‣ identifier ‣ selected ‣ frame ‣ … - (void)typeText:(NSString *)text; - (void)tap; - (void)doubleTap; - (void)twoFingerTap; - (void)tapWithNumberOfTaps:(NSUInteger)numberOfTaps numberOfTouches:(NSUInteger)numberOfTouches; - (void)pressForDuration:(NSTimeInterval)duration; - (void)pressForDuration:(NSTimeInterval)duration thenDragToElement:(XCUIElement *)otherElement; - (void)swipeUp; - (void)swipeDown; - (void)swipeLeft; - (void)swipeRight; - (void)pinchWithScale:(CGFloat)scale velocity:(CGFloat)velocity; - (void)rotate:(CGFloat)rotation withVelocity:(CGFloat)velocity;
  • 15. UI TESTING IN XCODE 7 Element queries XCUIElement ‣ title ‣ label ‣ value ‣ placeholderValue ‣ identifier ‣ selected ‣ frame ‣ … /*! Returns a query for all descendants of the element matching the specified type. */ - (XCUIElementQuery *)descendantsMatchingType:(XCUIElementType)type; /*! Returns a query for direct children of the element matching the specified type. */ - (XCUIElementQuery *)childrenMatchingType:(XCUIElementType)type;
  • 16. UI TESTING IN XCODE 7 Element queries XCUIElement ‣ title ‣ label ‣ value ‣ placeholderValue ‣ identifier ‣ selected ‣ frame ‣ … /*! Returns a query for all descendants of the element matching the specified type. */ - (XCUIElementQuery *)descendantsMatchingType:(XCUIElementType)type; @property (readonly, copy) XCUIElementQuery *tables; @property (readonly, copy) XCUIElementQuery *buttons; @property (readonly, copy) XCUIElementQuery *staticTexts; @property (readonly, copy) XCUIElementQuery *textFields; @property (readonly, copy) XCUIElementQuery *secureTextFields; @property (readonly, copy) XCUIElementQuery *textViews;
  • 17. UI TESTING IN XCODE 7 Element queries XCUIElement ‣ title ‣ label ‣ value ‣ placeholderValue ‣ identifier ‣ selected ‣ frame ‣ … [element descendantsMatchingType:XCUIElementTypeButton]; element.buttons
  • 18. UI TESTING IN XCODE 7 Root element - XCUIApplication @interface XCUIApplication : XCUIElement - (void)launch; - (void)terminate; @property (nonatomic, copy) NSArray <NSString *> *launchArguments; @property (nonatomic, copy) NSDictionary <NSString *, NSString *> *launchEnvironment; @end
  • 19. UI TESTING IN XCODE 7 XCUIElementQuery @interface XCUIElementQuery : NSObject <XCUIElementTypeQueryProvider> @property (readonly) NSUInteger count; - (XCUIElement *)elementBoundByIndex:(NSUInteger)index; - (XCUIElement *)elementMatchingPredicate:(NSPredicate *)predicate; - (XCUIElement *)elementMatchingType:(XCUIElementType)elementType 
 identifier:(nullable NSString *)identifier; - (XCUIElement *)objectForKeyedSubscript:(NSString *)key; @end
  • 20. UI TESTING IN XCODE 7 XCUIElementQuery @interface XCUIElementQuery : NSObject <XCUIElementTypeQueryProvider> @property (readonly) NSUInteger count; - (XCUIElement *)elementBoundByIndex:(NSUInteger)index; - (XCUIElement *)elementMatchingPredicate:(NSPredicate *)predicate; - (XCUIElement *)elementMatchingType:(XCUIElementType)elementType 
 identifier:(nullable NSString *)identifier; - (XCUIElement *)objectForKeyedSubscript:(NSString *)key; @end ▸ Evaluates the query ▸ Return the number of matches found
  • 21. UI TESTING IN XCODE 7 XCUIElementQuery @interface XCUIElementQuery : NSObject <XCUIElementTypeQueryProvider> @property (readonly) NSUInteger count; - (XCUIElement *)elementBoundByIndex:(NSUInteger)index; - (XCUIElement *)elementMatchingPredicate:(NSPredicate *)predicate; - (XCUIElement *)elementMatchingType:(XCUIElementType)elementType 
 identifier:(nullable NSString *)identifier; - (XCUIElement *)objectForKeyedSubscript:(NSString *)key; @end ▸ Return nth element in query results ▸ Example: XCUIElement *firstCell = [app.tables.cells elementBoundByIndex:0];
  • 22. UI TESTING IN XCODE 7 XCUIElementQuery @interface XCUIElementQuery : NSObject <XCUIElementTypeQueryProvider> @property (readonly) NSUInteger count; - (XCUIElement *)elementBoundByIndex:(NSUInteger)index; - (XCUIElement *)elementMatchingPredicate:(NSPredicate *)predicate; - (XCUIElement *)elementMatchingType:(XCUIElementType)elementType 
 identifier:(nullable NSString *)identifier; - (XCUIElement *)objectForKeyedSubscript:(NSString *)key; @end ▸ Example: NSPredicate *labelPrefixPredicate = [NSPredicate predicateWithFormat: @"label BEGINSWITH %@", prefix]; XCUIElement *label = [app.staticTexts elementMatchingPredicate:labelPrefixPredicate];
  • 23. UI TESTING IN XCODE 7 XCUIElementQuery @interface XCUIElementQuery : NSObject <XCUIElementTypeQueryProvider> @property (readonly) NSUInteger count; - (XCUIElement *)elementBoundByIndex:(NSUInteger)index; - (XCUIElement *)elementMatchingPredicate:(NSPredicate *)predicate; - (XCUIElement *)elementMatchingType:(XCUIElementType)elementType 
 identifier:(nullable NSString *)identifier; - (XCUIElement *)objectForKeyedSubscript:(NSString *)key; @end ▸ Example: XCUIElement *button = [app elementMatchingType:XCUIElementTypeButton identifier:@"login"];
  • 24. UI TESTING IN XCODE 7 XCUIElementQuery @interface XCUIElementQuery : NSObject <XCUIElementTypeQueryProvider> @property (readonly) NSUInteger count; - (XCUIElement *)elementBoundByIndex:(NSUInteger)index; - (XCUIElement *)elementMatchingPredicate:(NSPredicate *)predicate; - (XCUIElement *)elementMatchingType:(XCUIElementType)elementType 
 identifier:(nullable NSString *)identifier; - (XCUIElement *)objectForKeyedSubscript:(NSString *)key; @end ▸ Example: XCUIElement *button = app.buttons[@"login"];
  • 25. DEMO
  • 26. UI TESTING IN XCODE 7 How to asset test results? ▸ We can use all variants of XCTAssert macro ▸ But more accurate for asynchronous UI are expectations XCUIElement *loggedInLabel = app.tables.staticTexts[Identifier_Account_LoggedInLabel]; NSPredicate *exists = [NSPredicate predicateWithFormat:@"exists == 1"]; [self expectationForPredicate:exists evaluatedWithObject:loggedInLabel handler:nil]; [self waitForExpectationsWithTimeout:15 handler:nil];
  • 27. UI TESTING IN XCODE 7 Performance test - (void)testLogin_CredentialsAreValid_ShouldLogin { [self measureBlock:^{ //UITest code }]; } ▸ Xcode executes each test 10 times and compare average execution time with baseline (selected from previous results) ▸ Test will fail if new average has increased from baseline by 10% or more, but it will ignore regressions of less than a tenth of a second
  • 29. UI TESTING IN XCODE 7 Handle UI interruptions ▸ Setup interruptions monitor [self addUIInterruptionMonitorWithDescription:@"Location Permission" handler:^BOOL(XCUIElement *element) { XCUIElement *button = alert.buttons[@"Allow"]; if (button.exists) { [button tap]; return true; } return false; }]; ▸ Handlers are invoked in reverse order until one of them return true 1 2
  • 30. UI TESTING IN XCODE 7 Handle UI interruptions ▸ By default, XCode 7.2 will try to find & tap elements matching predicate: userTestingAttributes CONTAINS "cancel-button" userTestingAttributes CONTAINS "default-button" 1 2
  • 31. UI TESTING IN XCODE 7 Handle UI interruptions ▸ By default, XCode 7.2 will try to find & tap elements matching predicate: userTestingAttributes CONTAINS "cancel-button" userTestingAttributes CONTAINS "default-button" 2▸ Do you prefer confirm button as first choice? Add your own monitor: NSPredicate *predicate = [NSPredicate predicateWithFormat: @"userTestingAttributes CONTAINS "default-button""]; XCUIElement *button = [alert.buttons elementMatchingPredicate:predicate]; if (button.exists) { [button tap]; return true; }
  • 32. UI TESTING IN XCODE 7 Typing in secure text field doesn’t work ▸ Workaround: Disconnect Hardware Keyboard in Simulator ▸ „Neither element or any descendant has keyboard focus” error occurs when you are trying to type in secure UITextField
  • 33. ▸ Instead, we should check if element is hittable: UI TESTING IN XCODE 7 Why your test is not waiting for hidden elements? ▸ Hidden elements fulfil exists predicate: [NSPredicate predicateWithFormat:@"exists == 1"] [NSPredicate predicateWithFormat:@"hittable == 1"]
  • 34. UI TESTING IN XCODE 7 How to detect that app is in test mode? XCUIApplication * app = [[XCUIApplication alloc] init]; [app setLaunchArguments:@[@"UITESTS"]]; [app launch]; NSArray *arguments = [[NSProcessInfo processInfo] arguments]; if ([arguments containsObject:@"UITESTS"]) { //Customize app for tests } ▸ In test file: ▸ In application:
  • 35. UI TESTING IN XCODE 7 How to speed up tests? ▸ Disable animations in AppDelegate: NSArray *arguments = [[NSProcessInfo processInfo] arguments]; if ([arguments containsObject:@"UITESTS"]) { [UIView setAnimationsEnabled:NO]; }
  • 36. ▸ Waiting for element is one of the most cases in UI tests, why not use convenient helper? UI TESTING IN XCODE 7 Waiting for elements shortcuts NSPredicate *exists = [NSPredicate predicateWithFormat:@"exists == 1"]; [self expectationForPredicate:exists evaluatedWithObject:element handler:nil]; [self waitForExpectationsWithTimeout:15 handler:nil]; [self waitForElement:element]; [self waitForElement:button withTimeout:60];
  • 37. ▸ Waiting for element is one of the most cases in UI tests, why not use convenient helper? UI TESTING IN XCODE 7 Waiting for elements shortcuts NSPredicate *exists = [NSPredicate predicateWithFormat:@"hittable == 1"]; [self expectationForPredicate:exists evaluatedWithObject:element handler:nil]; [self waitForExpectationsWithTimeout:15 handler:nil]; [self waitForElementHittable:element]; [self waitForElementHittable:button withTimeout:60];
  • 38. ▸ Waiting for element is one of the most cases in UI tests, why not use convenient helper? UI TESTING IN XCODE 7 Waiting for elements shortcuts NSPredicate *exists = [NSPredicate predicateWithFormat:@"hittable == 1"]; [self expectationForPredicate:exists evaluatedWithObject:element handler:nil]; [self waitForExpectationsWithTimeout:15 handler:nil]; [self waitForElementHittable:element]; [self waitForElementHittable:button withTimeout:60]; https://github.com/dstranz/XCUITestsAdditions pod "XCUITestsAdditions"
  • 39. UI TESTING IN XCODE 7 Change device orientation [[XCUIDevice sharedDevice] setOrientation:UIDeviceOrientationLandscapeRight]; [[XCUIDevice sharedDevice] setOrientation:UIDeviceOrientationLandscapeLeft]; ▸ Landscape [[XCUIDevice sharedDevice] setOrientation:UIDeviceOrientationPortraitFaceUp]; [[XCUIDevice sharedDevice] setOrientation:UIDeviceOrientationPortraitFaceDown]; ▸ Portait
  • 40. UI TESTING IN XCODE 7 Simulates the user pressing a physical button [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome]; [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonVolumeUp]; [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonVolumeDown]; ▸ Home button ▸ Volume up ▸ Volume down ▸ Volume up & down doesn’t work on simulator
  • 41. UI TESTING IN XCODE 7 Test coverage
  • 42. UI TESTING IN XCODE 7 How to reset simulator state before each test? It’s not possible to force launching app on clean simulator (rdar://22455111). What are workarounds?
  • 43. UI TESTING IN XCODE 7 How to reset simulator state before each test? ▸ If you are using CI, you can run xcrun simctl erase all between each test cases ▸ You can clean NSUserDefaults and Keychain in AppDelegate, when app is in UITests mode ▸ …or rollback changes in tearDown method 
 (for example logout user after login test)