appium - 使用 Appium 的 getDeviceName 和 getVersion 运行时
问题描述
考虑我在多个 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;
}
推荐阅读
- jsf - 未设置 omnifaces.ListConverter 中的列表
- sql - 使用 SQL 脚本的条件 SQL 查询
- javascript - 哪种语法对 React 更典型,如果有的话(版本 16)?
- c# - 将二进制文件的前 X 个字节读入新文件
- excel - 如何将保存到特定文件夹的多个文本文件导入到Excel中的一个工作表一列,每个文件的不同行?
- google-bigquery - 在 BigQuery 中加入数组字段
- apache-spark - 从 Spark DataSet 中的单个列派生多个列并在新列上分组
- vba - 如何使用具有 2 个条件的 VBA 过滤日期列?
- windows - 在 Windows 10 中无法使用 PyUSB 从 USB 读取信息。(连接正常)
- c# - 如果键不存在,则用于添加的 IDictionary 扩展方法