How to call the methods based on the devices used

I am testing the scripts against many devices.
I am facing a problem with virtual keyboard,for samsung devices the virtual keyboard is getting closed after entering the text in the field but for Nexus it is remaining opened till i close it using the hidekeyboard() method.
If i call the hidekeyboard() method in the script then its working on nexes devices but its failing for all samsung device.
how to handle this case.

The way our Android team does this (and we do this to a lesser extent on iOS) is to have an object that represents the device under test, and then wrap the method you are calling so that you can make a decision based on the device under test. You don’t say what language you are using, so pseudocode:

def enter_text_and_dismiss_keyboard(device, "text")
  # code to enter text here
1 Like

@wreed Kindly clarify some queries I have. I am using scripting language JAVA

Query 1: here in pseudocode line" ") this means we need to read device name from cmd by executing command adb devices or we have an API also to get it in easy way ?

Query 2 : if we are performing parallel execution on multiple android devices then adb devices will return multiple devices then how we can make sure which device test case is running into ?


Yes, I think it would be appropriate to get the device name from adb (although now that I think about it, device type or manufacturer would be more appropriate here) and then parse that data into the data structure of the device under test object. I think our Android group has abstracted the system calls to adb into a library. I don’t know if there is an easier way to get this info.

Yes, that’s the trick isn’t it! So the way we do this is by leveraging a setting in the testing framework. So you would set (in Java I would create settings as a hashmap, YMMV):

deviceUnderTestName: "Wreed's Nexus 7"

Each test run would need a setting like this (if you are using TestNg, you could leverage a data provider for this info) And then when you make the initial ‘adb list devices’ you can parse the list to get UUID & such & then make specific queries against that device (if needed). Once you have that info, your testing framework can make the correct decisions in it’s methods.

Thanks everyone for the reply .