SlideShare a Scribd company logo
UI TESTING : DEALING WITH
PUSH NOTIFICATIONS
NICOLÁS GARCÍA (@NICOONGUITAR)
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
INDEX
▸ Multi-app Testing
▸ Sending a push notification through a UITest
▸ Handling user interactions on a notification in a UITest
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
INDEX
▸ Multi-app Testing
▸ Sending a push notification through a UITest
▸ Handling user interactions on a notification in a UITest
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
INDEX
▸ Multi-app Testing
▸ Sending a push notification through a UITest
▸ Handling user interactions on a notification in a UITest
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
INDEX
▸ Multi-app Testing
▸ Sending a push notification through a UITest
▸ Handling user interactions on a notification in a UITest
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
XCODE 9: UI TESTS CAN TARGET MULTIPLE APPLICATIONS
▸ Apps can interact with other apps (ex: Springboard)
let springboard = XCUIApplication(bundleIdentifier: “com.apple.springboard”)


‣ Accessibility allows us to interact with a received notification
springboard.otherElements["APPSNAME, now, Hello World”].tap()

springboard.otherElements["NotificationShortLookView"].tap()



‣ WWDC 2017 - Session 409 “What's New in Testing”
‣ System apps bundle identifiers list
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
DEMO
▸ Interacting with the Control Center by using a UITest
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
NWPUSHER: THE HERO
▸ Author: Noodlewerk
▸ GitHub NWPusher
▸ Sends Push Notifications (Sandbox and Production
environments).
▸ Allows us to define the notification’s payload.
▸ Original idea by Jörn Schoppe
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
SETTING THINGS UP
▸ Generate a .p12 file from the Keychain APNs app’s
certificate
▸ Add the .p12 file on app’s UITests target
▸ Install NWPusher on app’s UITests target
▸ Write those UITests!
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
INSTALLING NWPUSHER
▸ Install in app’s UITests target
▸ Podfile example (also available for Carthage…)
target 'TestingPushNotifications' do
use_frameworks!
target 'TestingPushNotificationsUITests' do
inherit! :search_paths
pod 'NWPusher', '~> 0.7.0'
end
end
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
WRITING THE UITEST
▸ Getting the Device token
▸ Sending the Push Notification through NWPusher
▸ Using waitForExistence API
▸ Interacting with the received notification
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
GETTING THE PUSH NOTIFICATION’S DEVICE TOKEN
▸ Allow remote notifications permission in app
▸ Dealing with Location Services permission system alert
▸ How to make the Device Token visible to the UITest? 🤔
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
GETTING THE PUSH NOTIFICATION’S DEVICE TOKEN
The current solution:
▸ Use of XCUIApplication’s launchArguments
▸ Add a UILabel on screen with the device token as its text
▸ Device token is now visible to Accessibility framework
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
SENDING A PUSH NOTIFICATION FROM THE UITEST
▸ Requires the .p12 file and its password
▸ Requires a customizable payload

func triggerPushNotification(payload: String, deviceToken: String) {
let uiTestBundle = Bundle(for: TestingPushNotificationsUITests.self)
guard let url = uiTestBundle.url(forResource: "apns_dev.p12", withExtension: nil) else { return }
do {
let data = try Data(contentsOf: url)
let pusher = try NWPusher.connect(withPKCS12Data: data, password: "cocoaheadsnantes", environment: .sandbox)
try pusher.pushPayload(payload, token: deviceToken, identifier: UInt(arc4random_uniform(UInt32(999))))
} catch {
print(error)
}
}
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
DEMO
▸ Sending a push notification from a UITest
▸ Handling the received push notification inside the UITest
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
UNNOTIFICATIONACTION
▸ Notification with actions
▸ Using .swipeDown() on the notification’s XCUIElement
▸ Testing user interactions on the received notification
▸ UNTextInputNotificationAction: answering the message
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
DEMO
▸ User interactions on a received notification with actions in
a UITest
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
SUMMARY
▸ UI Tests can target multiple apps 🚀
▸ Test notifications with actions 🚀
▸ Test analytics code for notification’s user interactions 🚀
▸ Only works with a real device #
▸ UITests stability 🤕
▸ Dealing with APNs 🤕
UI TESTING : DEALING WITH PUSH NOTIFICATIONS
THANK YOU!
@NicoonGuitar on Twitter 

iOS @VelcoBike %



Thanks to…

* Jörn Schoppe (for the cool idea!).

* CocoaHeads Nantes.

More Related Content

DOCX
Java assgn
PDF
Cygwin+and+open ssl+install+guide
PPTX
Develop for Windows 10 (Preview)
PPTX
2015 dan ardelean develop for windows 10
PDF
2011 py con
PPT
WinRunner Training
PPT
Introduction to OS
PDF
Java assgn
Cygwin+and+open ssl+install+guide
Develop for Windows 10 (Preview)
2015 dan ardelean develop for windows 10
2011 py con
WinRunner Training
Introduction to OS

Similar to Ui testing dealing with push notifications (20)

PDF
2010 bb dev con
PPTX
Hieu Xamarin iOS9, Android M 3-11-2015
PDF
Puppet camp Portland 2015: -windows (1)
PDF
Tutorial ranorex
PDF
Notifications
PDF
Distributing information on iOS
PPT
Eclipse Summit Europe '10 - Test UI Aspects of Plug-ins
PPT
Developing Multi Touch Applications
PDF
The Ring programming language version 1.5 book - Part 12 of 31
PDF
Cloud Native: Designing Change-tolerant Software
PDF
Android 103 - Firebase and Architecture Components
PDF
Petr Dvořák: Push notifikace ve velkém
PPTX
Session #8 adding magic to your app
PDF
The Ring programming language version 1.3 book - Part 49 of 88
PPTX
Azure push notification hub
PDF
Declarative presentations UIKonf
PDF
MAF push notifications
PDF
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
PDF
Vista uipi.ppt (1)
PPTX
Low level hookup
2010 bb dev con
Hieu Xamarin iOS9, Android M 3-11-2015
Puppet camp Portland 2015: -windows (1)
Tutorial ranorex
Notifications
Distributing information on iOS
Eclipse Summit Europe '10 - Test UI Aspects of Plug-ins
Developing Multi Touch Applications
The Ring programming language version 1.5 book - Part 12 of 31
Cloud Native: Designing Change-tolerant Software
Android 103 - Firebase and Architecture Components
Petr Dvořák: Push notifikace ve velkém
Session #8 adding magic to your app
The Ring programming language version 1.3 book - Part 49 of 88
Azure push notification hub
Declarative presentations UIKonf
MAF push notifications
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
Vista uipi.ppt (1)
Low level hookup
Ad

More from CocoaHeads France (20)

PDF
Mutation testing for a safer Future
PDF
iOS App Group for Debugging
PDF
Asynchronous swift
PDF
Visual accessibility in iOS11
PDF
My script - One year of CocoaHeads
PDF
CONTINUOUS DELIVERY WITH FASTLANE
PDF
L'intégration continue avec Bitrise
PDF
Super combinators
PDF
Design like a developer
PDF
Handle the error
PDF
Quoi de neuf dans iOS 10.3
PDF
IoT Best practices
PDF
SwiftyGPIO
PDF
Présentation de HomeKit
PDF
Programme MFI retour d'expérience
PDF
How to communicate with Smart things?
PDF
Build a lego app with CocoaPods
PDF
Let's migrate to Swift 3.0
PDF
Project Entourage
PDF
What's new in iOS9
Mutation testing for a safer Future
iOS App Group for Debugging
Asynchronous swift
Visual accessibility in iOS11
My script - One year of CocoaHeads
CONTINUOUS DELIVERY WITH FASTLANE
L'intégration continue avec Bitrise
Super combinators
Design like a developer
Handle the error
Quoi de neuf dans iOS 10.3
IoT Best practices
SwiftyGPIO
Présentation de HomeKit
Programme MFI retour d'expérience
How to communicate with Smart things?
Build a lego app with CocoaPods
Let's migrate to Swift 3.0
Project Entourage
What's new in iOS9
Ad

Recently uploaded (20)

PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPT
Introduction Database Management System for Course Database
PDF
top salesforce developer skills in 2025.pdf
PDF
System and Network Administration Chapter 2
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
AI in Product Development-omnex systems
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Nekopoi APK 2025 free lastest update
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Odoo Companies in India – Driving Business Transformation.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction Database Management System for Course Database
top salesforce developer skills in 2025.pdf
System and Network Administration Chapter 2
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Which alternative to Crystal Reports is best for small or large businesses.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
ai tools demonstartion for schools and inter college
AI in Product Development-omnex systems
Navsoft: AI-Powered Business Solutions & Custom Software Development
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ManageIQ - Sprint 268 Review - Slide Deck
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
Upgrade and Innovation Strategies for SAP ERP Customers
Nekopoi APK 2025 free lastest update
Odoo POS Development Services by CandidRoot Solutions
Odoo Companies in India – Driving Business Transformation.pdf

Ui testing dealing with push notifications

  • 1. UI TESTING : DEALING WITH PUSH NOTIFICATIONS NICOLÁS GARCÍA (@NICOONGUITAR)
  • 2. UI TESTING : DEALING WITH PUSH NOTIFICATIONS INDEX ▸ Multi-app Testing ▸ Sending a push notification through a UITest ▸ Handling user interactions on a notification in a UITest
  • 3. UI TESTING : DEALING WITH PUSH NOTIFICATIONS INDEX ▸ Multi-app Testing ▸ Sending a push notification through a UITest ▸ Handling user interactions on a notification in a UITest
  • 4. UI TESTING : DEALING WITH PUSH NOTIFICATIONS INDEX ▸ Multi-app Testing ▸ Sending a push notification through a UITest ▸ Handling user interactions on a notification in a UITest
  • 5. UI TESTING : DEALING WITH PUSH NOTIFICATIONS INDEX ▸ Multi-app Testing ▸ Sending a push notification through a UITest ▸ Handling user interactions on a notification in a UITest
  • 6. UI TESTING : DEALING WITH PUSH NOTIFICATIONS XCODE 9: UI TESTS CAN TARGET MULTIPLE APPLICATIONS ▸ Apps can interact with other apps (ex: Springboard) let springboard = XCUIApplication(bundleIdentifier: “com.apple.springboard”) 
 ‣ Accessibility allows us to interact with a received notification springboard.otherElements["APPSNAME, now, Hello World”].tap()
 springboard.otherElements["NotificationShortLookView"].tap()
 
 ‣ WWDC 2017 - Session 409 “What's New in Testing” ‣ System apps bundle identifiers list
  • 7. UI TESTING : DEALING WITH PUSH NOTIFICATIONS DEMO ▸ Interacting with the Control Center by using a UITest
  • 8. UI TESTING : DEALING WITH PUSH NOTIFICATIONS NWPUSHER: THE HERO ▸ Author: Noodlewerk ▸ GitHub NWPusher ▸ Sends Push Notifications (Sandbox and Production environments). ▸ Allows us to define the notification’s payload. ▸ Original idea by Jörn Schoppe
  • 9. UI TESTING : DEALING WITH PUSH NOTIFICATIONS SETTING THINGS UP ▸ Generate a .p12 file from the Keychain APNs app’s certificate ▸ Add the .p12 file on app’s UITests target ▸ Install NWPusher on app’s UITests target ▸ Write those UITests!
  • 10. UI TESTING : DEALING WITH PUSH NOTIFICATIONS INSTALLING NWPUSHER ▸ Install in app’s UITests target ▸ Podfile example (also available for Carthage…) target 'TestingPushNotifications' do use_frameworks! target 'TestingPushNotificationsUITests' do inherit! :search_paths pod 'NWPusher', '~> 0.7.0' end end
  • 11. UI TESTING : DEALING WITH PUSH NOTIFICATIONS WRITING THE UITEST ▸ Getting the Device token ▸ Sending the Push Notification through NWPusher ▸ Using waitForExistence API ▸ Interacting with the received notification
  • 12. UI TESTING : DEALING WITH PUSH NOTIFICATIONS GETTING THE PUSH NOTIFICATION’S DEVICE TOKEN ▸ Allow remote notifications permission in app ▸ Dealing with Location Services permission system alert ▸ How to make the Device Token visible to the UITest? 🤔
  • 13. UI TESTING : DEALING WITH PUSH NOTIFICATIONS GETTING THE PUSH NOTIFICATION’S DEVICE TOKEN The current solution: ▸ Use of XCUIApplication’s launchArguments ▸ Add a UILabel on screen with the device token as its text ▸ Device token is now visible to Accessibility framework
  • 14. UI TESTING : DEALING WITH PUSH NOTIFICATIONS SENDING A PUSH NOTIFICATION FROM THE UITEST ▸ Requires the .p12 file and its password ▸ Requires a customizable payload
 func triggerPushNotification(payload: String, deviceToken: String) { let uiTestBundle = Bundle(for: TestingPushNotificationsUITests.self) guard let url = uiTestBundle.url(forResource: "apns_dev.p12", withExtension: nil) else { return } do { let data = try Data(contentsOf: url) let pusher = try NWPusher.connect(withPKCS12Data: data, password: "cocoaheadsnantes", environment: .sandbox) try pusher.pushPayload(payload, token: deviceToken, identifier: UInt(arc4random_uniform(UInt32(999)))) } catch { print(error) } }
  • 15. UI TESTING : DEALING WITH PUSH NOTIFICATIONS DEMO ▸ Sending a push notification from a UITest ▸ Handling the received push notification inside the UITest
  • 16. UI TESTING : DEALING WITH PUSH NOTIFICATIONS UNNOTIFICATIONACTION ▸ Notification with actions ▸ Using .swipeDown() on the notification’s XCUIElement ▸ Testing user interactions on the received notification ▸ UNTextInputNotificationAction: answering the message
  • 17. UI TESTING : DEALING WITH PUSH NOTIFICATIONS DEMO ▸ User interactions on a received notification with actions in a UITest
  • 18. UI TESTING : DEALING WITH PUSH NOTIFICATIONS SUMMARY ▸ UI Tests can target multiple apps 🚀 ▸ Test notifications with actions 🚀 ▸ Test analytics code for notification’s user interactions 🚀 ▸ Only works with a real device # ▸ UITests stability 🤕 ▸ Dealing with APNs 🤕
  • 19. UI TESTING : DEALING WITH PUSH NOTIFICATIONS THANK YOU! @NicoonGuitar on Twitter 
 iOS @VelcoBike %
 
 Thanks to…
 * Jörn Schoppe (for the cool idea!).
 * CocoaHeads Nantes.