How to check if device is a phone or tablet using Appium on iOS & Android

I need to check if my device is a Tablet or a phone while an Appium script is running (the app behaviour is different on Phone & Tablet, therefore I need to check the device type to execute the right flow).

Is it possible to check using Appium? I am using Appium 1.22.3

What if you got the Window size of the current device and defined tablet/phone by size?

https://appium.io/docs/en/commands/web/window/get-window-size/

Or better, get capabilities and identify by name:

https://appium.io/docs/en/commands/session/get/

try https://github.com/appium/appium-xcuitest-driver#mobile-deviceinfo

the field value of “userInterfaceIdiom” should be equal to 2 if this is an iPad.

Thanks for your help. This worked for me for iOS. I can see that ‘userInterfaceIdiom’ value is 0 for Phone & 1 for a tablet. Is there anything similar for Android?

Android API apparently does not provide any particular APIs to reliably distinguish phones from tablets. See https://stackoverflow.com/questions/9279111/determine-if-the-device-is-a-smartphone-or-tablet

If you still would like to use the screen diagonal size to determine the device type, like it is mentioned in one of the responses above, then the output of https://github.com/appium/appium-uiautomator2-driver#mobile-deviceinfo might be useful.

1 Like

Sounds good. Thanks very much @mykola-mokhnach