How To Automate 3D/Force Touch with Appium
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
A few weeks ago a customer from the Netherlands asked me if there is a possibility to automate the quick navigation menu with Appium. He explain that if you would use a 3D/Force Touch on the app image, it would show a quick navigation menu that a customer could use to go to a sure screen in the app (see picture 1).

Image 1: Speedy piloting carte
My answer was that I ’ d never done it, but that I thought it would be possible. In this blog post I ’ m move to explain how you can use Appium to automatise the quick navigation carte on iOS and Android. But before we plunk into the details, let ’ s first look at what 3D/Force Touch can do.
What is 3D/Force Touch?
Apple introduced 3D Touch on their iPhone 6S (Plus) which meant that as of so they provided their iPhones with a pressure-sensitive blind. The idea was that the harder you press, the more would “ happen ” on the blind. But if you hold been following the modish news of Apple, you might also be wondering why we are going to write about 3D/Force Touch while Apple stopped using pressure-sensitive screens and introduced “ Haptic Touch ” screens (they already introduced it with the iPhone XR). Well, the end result of 3D/Force/Haptic Touch is just the same, it will provide you a menu with quick piloting menu selection.
But while we talk about iOS, we should also view how this impacts Android devices. Android announced support for 3D Touch in Android Q, but we need to be aware that Android is not building their own devices and screens (except for the Pixel phones) —meaning that you never know if manufacturers like Samsung, LG and many more will implement a pressure-sensitive screen on their phones. But to get rearwards to the basics, Android has already supported a quick navigation menu option, without using 3D/Force Touch, for a long clip. And in the end, that is what we require to automate with Appium.
Building spry navigation menu support
To understand how to automate 3D/Force Touch with Appium, we firstly added the quick navigation card option to our own so everybody can use it as a demo.
Because we are utilize React Native to build our sample app, we could easily integrate this. We append two quick navigation card items, including:
The “ Open Swag Items ” to hop the login page and now open the Swag Items page
The “ Open Webview ” to skip the login page and go directly to the Webview selection page.
Please check the where you can freely download the and say how to use it.
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
It ’ s only a touch activeness
When I believe roughly how to automate the 3D/Force Touch I was immediately thinking about the touch actions we can use with Appium. With a touch activeness you are capable to mimic the behaviour of how a user istouchingthe blind in pocket-sized steps. So in steps the touch action should contain something like this:
Press the blind (with pressure for iOS, not for Android)
Hold down for x amount of bit
Release the hold when the menu appears
When I begin cypher this I found out that this was the way to go with Android, so the first part was already solved. I also found out that thelonginsistency for iOS was not plenty. I needed to do some more investigation about how to ply the pressure as an option.
After look theAppium docsfor “ 3D/Force Touch ” and “ pressing ” I plant nothing. What I unremarkably do when I can ’ t regain it in the DoC is search the Appium repository on certain words. I ultimately came up with thisresultand after reading all the results I found out that the choicepressurewas the one I needed to get, I also found out that the value needed to be 0 for no and 1 for a normal pressure.
Automating 3D/Force Touch
People who know me a bit longer know that I ’ m a JavaScript and WebdriverIO fan, so I hope I won ’ t surprise you with a WebdriverIO below.
The example below will demo you how to use it with:
iOS 12 and below, for the iPhones that support 3D/Force Touch (this still works with iPhones and iOS 13+ that don ’ t have 3D/Force Touch, but Haptic Touch
Android devices
The locator that are used here are the accessibilityIDs, they are cross-platform and easy to read (more information about this can be found in my blog abouthow to speed up your iOS Appium tests).
import InventoryListScreen from & # x27; .. / .. /screenObjects/inventoryList & # x27;;
significance {DEFAULT_TIMEOUT} from & # x27; .. / .. /helpers/e2eConstants & # x27;;
describe (& # x27; Test 3D Touch & # x27;, () = & gt; {
it (& # x27; should be able to open the Safari 3D touch menu & # x27;, () = & gt; {
// Go to home
driver.background (-1);
if (driver.isIOS) {
// Check Dock is shown
$ (& # x27; ~Dock & # x27;) .waitForDisplayed (DEFAULT_TIMEOUT);
// Open the 3D touch menu with a strength ghost
driver.touchPerform ([
{
activity: & # x27; insistence & # x27;,
options: {
ingredient: $ (& # x27; ~SwagLabsMobileApp & # x27;) .elementId,
pressure: 1,
},
},
{
action: & # x27; wait & # x27;,
alternative: {ms: 2000},
},
{
action: & # x27; release & # x27;,
},
]);
// Verify the 3D menu is opened
expect ($ (& # x27; ~Open Swag Items, Open the Swag Items & # x27;) .waitForDisplayed (15000)) .toEqual (true, & # x27; 3D Touch menu did not open & # x27;);
$ (& # x27; ~Open Swag Items, Open the Swag Items & # x27;) .click ();
} else {
// Open the menu
$ (& # x27; ~Apps list & # x27;) .click ();
// Check if the app is there
$ (& # x27; ~Swag Labs Mobile App & # x27;) .waitForDisplayed (DEFAULT_TIMEOUT);
// Open the 3D touch menu with a force touch
driver.touchPerform ([
{
activeness: & # x27; press & # x27;,
options: {
constituent: $ (& # x27; ~Swag Labs Mobile App & # x27;) .elementId,
},
},
{
activeness: & # x27; wait & # x27;,
pick: {ms: 2000},
},
{
activeness: & # x27; release & # x27;,
},
]);
// Wait for the menu to open and click on it
$ (& # x27; ~Open Swag Items & # x27;) .waitForDisplayed (DEFAULT_TIMEOUT);
$ (& # x27; ~Open Swag Items & # x27;) .click ();
}
expect (InventoryListScreen.waitForIsShown ()) .toEqual (true, & # x27; Inventory List blind was not testify & # x27;);
});
});
Conclusion
I hope you found this tech tip useful. If you ’ re appear for a spry and easy way to test 3D/Force Touch with your own app, you cantry for freewith Sauce Labs. Until next time ... happy examination!
Wim Selles helps solve automation challenge by day—and practice his warmth for front-end test mechanisation at dark. Wim enjoys make his own node.js modules and contributing to open rootage projection. You can find Wim on LinkedIn and Twittter @ wswebcreation
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