使用 Appium 的 getDeviceName 和 getVersion 运行时
getDeviceName and getVersion runtime using Appium
考虑一下我 运行 我在多个 Real 设备上使用 Appium 进行测试。
是否可以使用 Appium 获取 getDeviceName 和 getVersion 运行时。
因为我需要截屏并将其保存在具有该设备名称的文件夹中
我可以向您展示如何获取 运行 设备和模拟器的列表,但我没有代码来获取它们的版本 运行。
/**
* Determine already connected physical devices or already running emulators
* @author Bill Hileman
* @return String List of running/connected devices
*/
public List<String> getRunningDevicesList() {
List<String> dev = new ArrayList<String>();
//Location of the Android SDK
String sdkPath = System.getenv("ANDROID_HOME");
if (sdkPath == null) {
System.err.println("ANDROID_HOME is not set in the environment");
Assert.fail();
} else {
//Location of Android Debug Bridge
String adbPath = sdkPath + "/platform-tools/adb.exe";
if (!new File(adbPath).exists()) {
System.err.println(adbPath + " is not found");
Assert.fail();
} else {
try {
String[] commandListAVDs = new String[]{adbPath, "devices"};
System.out.println("Executing command: " + adbPath + " devices");
Process process = new ProcessBuilder(commandListAVDs).start();
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = inputStream.readLine()) != null)
//ignore lines that do not contain device information
if (!(line.trim().equals("") || line.equals("List of devices attached") || line.startsWith("* daemon ")))
dev.add(line.trim());
} catch (Exception e) {
System.err.println("Unable to read device list: " + e);
e.printStackTrace();
}
System.out.println("Running Devices: " + dev.toString());
}
}
return dev;
}
考虑一下我 运行 我在多个 Real 设备上使用 Appium 进行测试。
是否可以使用 Appium 获取 getDeviceName 和 getVersion 运行时。
因为我需要截屏并将其保存在具有该设备名称的文件夹中
我可以向您展示如何获取 运行 设备和模拟器的列表,但我没有代码来获取它们的版本 运行。
/**
* Determine already connected physical devices or already running emulators
* @author Bill Hileman
* @return String List of running/connected devices
*/
public List<String> getRunningDevicesList() {
List<String> dev = new ArrayList<String>();
//Location of the Android SDK
String sdkPath = System.getenv("ANDROID_HOME");
if (sdkPath == null) {
System.err.println("ANDROID_HOME is not set in the environment");
Assert.fail();
} else {
//Location of Android Debug Bridge
String adbPath = sdkPath + "/platform-tools/adb.exe";
if (!new File(adbPath).exists()) {
System.err.println(adbPath + " is not found");
Assert.fail();
} else {
try {
String[] commandListAVDs = new String[]{adbPath, "devices"};
System.out.println("Executing command: " + adbPath + " devices");
Process process = new ProcessBuilder(commandListAVDs).start();
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = inputStream.readLine()) != null)
//ignore lines that do not contain device information
if (!(line.trim().equals("") || line.equals("List of devices attached") || line.startsWith("* daemon ")))
dev.add(line.trim());
} catch (Exception e) {
System.err.println("Unable to read device list: " + e);
e.printStackTrace();
}
System.out.println("Running Devices: " + dev.toString());
}
}
return dev;
}