Hello,
Is there a way to get the device id and run few scripts. for example
if (Deviceid == 4100951cf20c1215")) {
runthismethod();
}
else
{
runAnothermetod();
}
Please help me to get the device id and store it in a variable.
Hello,
Is there a way to get the device id and run few scripts. for example
if (Deviceid == 4100951cf20c1215")) {
runthismethod();
}
else
{
runAnothermetod();
}
Please help me to get the device id and store it in a variable.
Do you mean the uuid? You donāt mention what platform so Iāll give you iOS:
āinstruments -s devicesā
In my test framework I call this, parse the results and match the device name with the one the user put in settings.
Find Android deviceās model name:
adb devices -l
Find Android deviceās version no:
adb shell getprop ro.build.version.release
But how do I add this in the appium code. This I run from the terminal right?
In my framework we run a command like this in the setup, and then start the server using this value. You can make a system call from whatever language you are using to adb. You will probably need to parse the results and store the uuid in a variable.
Connect your android mobile to your computer using USB cable.
Then type below command in the terminal
adb devices -l
It will display all the connected device to your comaputer with device IDs.
And you can pass the device ID to your code using DesiredCapabilities
eg: if your device id is f23a5A83,
DesiredCapabilities Androidcapability=new DesiredCapabilities();
Androidcapability.setCapability(āudidā, āf23a5A83ā);
Below is the code I tried and works fine
java.lang.Runtime rt = java.lang.Runtime.getRuntime();
// Start a new process: UNIX command ls
java.lang.Process p = rt.exec(āadb devicesā);
// Get processā output: its InputStream
java.io.InputStream is = p.getInputStream();
java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is));
// And print each line
String s= (reader.readLine());
while ((s = reader.readLine()) != null) {
System.out.println(s);
if(s.contains("4100951cf20c1215"))
{
System.out.println("+++++++++++++++00000000000000");
}
if(s.contains("LGH815e29d29f9"))
{
System.out.println("___________________0000000000000000000");
}
if(s.contains("TA99301VXY"))
{
System.out.println("xxxxxxxxxxxxxxx0000000000000000000");
}
}
is.close();
There are a couple known ways to retrieve Android device IDs. The first, most straightforward method is already listed in this thread: Spawn a child process that runs āadb devicesā and then parse the results that are returned on the childās standard out. Although this will work, I feel that itās a bit shaky since your parent process will need a PATH environment variable that contains adb, and parsing the results is often frustrating to set up.
For Java, I think a better option is to include the same device library the Android SDK uses into your own test framework. Check out ddmlib and a ddmlib demo to get a feel for how to use it to retrieve devices. The downside is that you still have to be able to find adb, but you wonāt have to deal with parsing the results.
Can any one help to get the version and device id for IOS device.
Hi, Can you show me Example how you do it ? call āinstruments -s devicesā from framwork (Im using JAVA) and, parse the results (UDID) to String Array List ?
Thanks !!!
Here is a tutorial on making a system call in Java:
https://www.mkyong.com/java/how-to-execute-shell-command-from-java/
The example above from @tapanagkumar is a good one.
I will try it,
Thanks !