1# -*- coding: utf-8 -*- 2import time 3import threading 4import re 5from devicetest.core.test_case import TestCase 6from devicetest.aw.OpenHarmony import CommonOH 7from testcases.orc import Orc 8 9 10class DistributedTest(TestCase): 11 def __init__(self, controllers): 12 self.TAG = self.__class__.__name__ 13 self.tests = [ 14 # 设备组网 15 "sub_distributed_smoke_testcase_0100", 16 # pin码连接 17 "sub_distributed_smoke_testcase_0200", 18 # 结果校验 19 "sub_distributed_smoke_testcase_0300" 20 ] 21 TestCase.__init__(self, self.TAG, controllers) 22 23 def setup(self): 24 print("预置工作:初始化设备开始...........................") 25 print(self.devices[0].device_id) 26 print(self.devices[1].device_id) 27 28 def sub_distributed_smoke_testcase_0100(self): 29 t1 = threading.Thread(target=self.net_connect1) 30 t2 = threading.Thread(target=self.net_connect2) 31 t1.start() 32 t2.start() 33 t1.join() 34 t2.join() 35 36 def sub_distributed_smoke_testcase_0200(self): 37 CommonOH.startAbility(self.Phone1, "ohos.samples.distributedcalc.MainAbility", "ohos.samples.distributedcalc") 38 time.sleep(2) 39 # 授权 40 CommonOH.click(self.Phone1, 500, 1130) 41 CommonOH.click(self.Phone1, 500, 1130) 42 CommonOH.hdc_std(self.Phone1, "shell snapshot_display -f /data/distributedcalc_step1.png") 43 CommonOH.hdc_std(self.Phone1, "file recv /data/distributedcalc_step1.png testcases\\distributedcalc_step1.png") 44 CommonOH.click(self.Phone1, 610, 110) 45 time.sleep(3) 46 CommonOH.click(self.Phone1, 380, 1150) 47 CommonOH.click(self.Phone1, 610, 110) 48 time.sleep(3) 49 CommonOH.hdc_std(self.Phone1, "shell snapshot_display -f /data/distributedcalc_step2.png") 50 CommonOH.hdc_std(self.Phone1, "file recv /data/distributedcalc_step2.png testcases\\distributedcalc_step2.png") 51 CommonOH.click(self.Phone1, 580, 1090) 52 time.sleep(1) 53 CommonOH.hdc_std(self.Phone2, "shell snapshot_display -f /data/distributedcalc_step3.png") 54 CommonOH.hdc_std(self.Phone2, "file recv /data/distributedcalc_step3.png testcases\\distributedcalc_step3.png") 55 #确定 56 CommonOH.click(self.Phone2, 520, 520) 57 CommonOH.click(self.Phone2, 520, 520) 58 CommonOH.hdc_std(self.Phone2, "shell snapshot_display -f /data/distributedcalc_step4.png") 59 CommonOH.hdc_std(self.Phone2, "file recv /data/distributedcalc_step4.png testcases\\distributedcalc_step4.png") 60 time.sleep(1) 61 code = Orc("testcases\\distributedcalc_step4.png") 62 self.code = re.findall("[0-9]{6}", code)[0] 63 #输pin码 64 CommonOH.click(self.Phone1, 300, 535, downtime=500) 65 time.sleep(1) 66 #切换至数字输入 67 CommonOH.click(self.Phone1, 60, 1145) 68 time.sleep(1) 69 for i in self.code: 70 if i == "0": 71 CommonOH.click(self.Phone1, 676, 778) 72 else: 73 j = int(i) - 1 74 CommonOH.click(self.Phone1, 46 + j * 70, 778) 75 time.sleep(1) 76 CommonOH.click(self.Phone1, 60, 1145) 77 # 确定 78 CommonOH.click(self.Phone1, 500, 600) 79 80 def sub_distributed_smoke_testcase_0300(self): 81 # 切入后台,结束进程 82 CommonOH.click(self.Phone1, 512, 1246) 83 CommonOH.click(self.Phone1, 360, 1168) 84 # 重启计算器应用 85 CommonOH.startAbility(self.Phone1, "ohos.samples.distributedcalc.MainAbility", "ohos.samples.distributedcalc") 86 time.sleep(2) 87 # 拉起远端设备 88 CommonOH.click(self.Phone1, 610, 110) 89 time.sleep(3) 90 CommonOH.hdc_std(self.Phone1, "shell snapshot_display -f /data/distributedcalc_step5.png") 91 CommonOH.hdc_std(self.Phone1, "file recv /data/distributedcalc_step5.png testcases\\distributedcalc_step5.png") 92 CommonOH.click(self.Phone1, 580, 1090) 93 CommonOH.click(self.Phone1, 580, 1090) 94 # 设备二授权 95 time.sleep(2) 96 CommonOH.click(self.Phone2, 500, 1130) 97 CommonOH.click(self.Phone2, 500, 1130) 98 # 校验远端计算器是否被拉起 99 CommonOH.hdc_std(self.Phone2, "shell snapshot_display -f /data/distributedcalc_step6.png") 100 CommonOH.hdc_std(self.Phone2, "file recv /data/distributedcalc_step6.png testcases\\distributedcalc_step6.png") 101 CommonOH.hdc_std(self.Phone2, 'shell "aa dump -a | grep distributedcalc > /data/report.txt"') 102 CommonOH.hdc_std(self.Phone2, "file recv /data/report.txt testcases\\report.txt") 103 time.sleep(1) 104 CommonOH.hdc_std(self.Phone1, "file send testcases\\report.txt /data/report.txt") 105 106 def net_connect1(self): 107 # 点亮屏幕 108 CommonOH.wake(self.Phone1) 109 # 设置不息屏 110 CommonOH.hdc_std(self.Phone1, 'shell "power-shell setmode 602"') 111 112 def net_connect2(self): 113 # 点亮屏幕 114 CommonOH.wake(self.Phone2) 115 # 设置不息屏 116 CommonOH.hdc_std(self.Phone2, 'shell "power-shell setmode 602"') 117 118 def teardown(self): 119 # 切入后台,结束进程 120 CommonOH.hdc_std(self.Phone1, "shell killall ohos.samples.distributedcalc") 121 CommonOH.hdc_std(self.Phone2, "shell killall ohos.samples.distributedcalc")