1# -*- coding: utf-8 -*- 2import os 3 4from devicetest.api import Asserts 5from devicetest.log.logger import print_info 6 7from test_case import ITestCase 8 9 10class Contacts(ITestCase): 11 ability_name = 'com.ohos.contacts.MainAbility' 12 bundle_name = 'com.ohos.contacts' 13 14 def __init__(self, controllers): 15 super().__init__(controllers) 16 17 def setup(self): 18 self.step('前置条件1:回到桌面') 19 self.common_oh.goHome(self.Phone1) 20 self.step('前置条件2:检查当前界面是否在桌面') 21 self.common_oh.checkIfTextExist(self.Phone1, '相机') 22 23 24 def process(self): 25 self.step('步骤1:启动联系人应用') 26 self.common_oh.startAbility(self.Phone1, self.ability_name, self.bundle_name) 27 # self.common_oh.wait(self.Phone1, 5) 28 # 控件检查 29 self.step('步骤2:检查是否进入联系人') 30 self.common_oh.checkIfTextExist(self.Phone1, '电话') 31 self.common_oh.checkIfTextExist(self.Phone1, '5') 32 self.common_oh.checkIfTextExist(self.Phone1, '联系人') 33 self.step('步骤3:联系人截图对比') 34 # 截图对比 35 contacts_pic = 'contacts.jpeg' 36 self.take_picture_to_local(contacts_pic) 37 self.crop_picture(contacts_pic) 38 similarity = self.compare_image_similarity(contacts_pic) 39 print_info('相似度为:{}%'.format(similarity)) 40 self.asserts.assert_greater_equal(similarity, self.STANDARD_SIMILARITY) 41 42 def teardown(self): 43 self.step('收尾1:停掉联系人应用') 44 self.common_oh.forceStopAbility(self.Phone1, self.bundle_name) 45