1#!/usr/bin/env python3 2#-*- coding: utf-8 -*- 3 4# Copyright (c) 2024 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from devicetest.utils.file_util import get_resource_path 18from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir 19from hypium import UiDriver 20import time 21from hypium import * 22from hypium.action.os_hypium.device_logger import DeviceLogger 23from hypium.action.host import host 24from hypium.model import UiParam 25 26 27class SUB_RUNNINGLOCK_TIMEOUT_TEST(TestCase): 28 29 def __init__(self, configs): 30 self.TAG = self.__class__.__name__ 31 TestCase.__init__(self, self.TAG, configs) 32 self.tests = [ 33 "test_step" 34 ] 35 self.driver = UiDriver(self.device1) 36 self.driver_width, self.driver_height = self.driver.get_display_size() 37 self.sn = self.device1.device_sn 38 39 def setup(self): 40 self.log.info("SUB_RUNNINGLOCK_TIMEOUT_TEST start") 41 42 #清除日志 43 host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) 44 host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) 45 self.driver.install_app(package_path=power_hap_path) 46 self.driver.ScreenLock.unLock() 47 48 #回到桌面 49 self.driver.go_home() 50 51 def test_step(self): 52 device_logger = DeviceLogger(self.driver).set_filter_string("powermgr") 53 device_logger.start_log(get_report_dir() + '//runninglock_timeout.txt') 54 55 Step("点击运行锁") 56 self.driver.start_app(package_name="ohos.power.powermanager") 57 # 通过相对位置点击控件 58 self.driver.touch(BY.isAfter(BY.text('运行锁相关功能')).isBefore(BY.text('耗电统计')).type('Image')) 59 60 self.driver.wait(0.5) 61 62 # 输入超时时间10000 63 self.driver.input_text(BY.type('TextInput'), '10000') 64 self.driver.wait(0.5) 65 66 self.driver.touch(BY.type('Image').isBefore(BY.key('keyboardRightButton'))) 67 self.driver.wait(0.5) 68 69 self.driver.touch(BY.type('Button').text('持锁')) 70 self.driver.wait(10) 71 device_logger.stop_log() 72 73 log_check_result = device_logger.check_log("try Lock, name: power_sample_timeout", EXCEPTION=True) 74 self.driver.Assert.equal(log_check_result, True) 75 76 log_check_result = device_logger.check_log("try UnLock, name: power_sample_timeout", EXCEPTION=True) 77 self.driver.Assert.equal(log_check_result, True) 78 79 80 def teardown(self): 81 Step("收尾工作") 82 self.log.info("SUB_RUNNINGLOCK_TIMEOUT_TEST down") 83 self.driver.stop_app(package_name="ohos.power.powermanager") 84 #回到桌面 85 self.driver.go_home()