appium自动化测试框架——封装获取设备信息类

在上一节中,我们已经解决了如何在python中执行cmd,并获取执行结果。下面就小小实战一下,获取设备信息。

一、思路

1、windows上获取设备信息的方法

输入dos命令“adb devices”

通常有如下结果

2、对结果进行处理,获取需要的设备信息

1)通过os.popen(cmd).readlines()获取到所有的行,去掉行尾的‘\n’符,可以得到有效的行信息。

2)找到含有设备信息的行,因为设备号和“device”之间是有‘\t’分隔的,所以可以使用split()进行分隔

二、上代码

 1     def get_devices(self):
 2         '''
 3         获取设备信息
 4         '''
 5         print u"获取设备列表"
 6         devices_list = []
 7         result_list = self.dos.excute_cmd_result('adb devices')
 8         if len(result_list) >= 2:
 9             for i in result_list:
10                 if 'List' in i:
11                     continue
12                 devices_info = i.split('\t')
13                 if devices_info[1] == 'device':
14                     devices_list.append(devices_info[0])
15             return devices_list
16         else:
17             return None

三、测试代码是否有效

猜你喜欢

转载自www.cnblogs.com/loveapple/p/9145143.html