• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.core.test_case import TestCase, Step, CheckPoint, get_report_dir
18from hypium import UiDriver
19import time
20from hypium import *
21from hypium.action.os_hypium.device_logger import DeviceLogger
22from hypium.action.host import host
23from hypium.model import UiParam
24
25
26class SUB_KILL_FOUNDATION_TEST(TestCase):
27
28    def __init__(self, configs):
29        self.TAG = self.__class__.__name__
30        TestCase.__init__(self, self.TAG, configs)
31        self.tests = [
32            "test_step"
33        ]
34        self.driver = UiDriver(self.device1)
35        self.driver_width, self.driver_height = self.driver.get_display_size()
36        self.sn = self.device1.device_sn
37
38    def setup(self):
39        self.log.info("SUB_KILL_FOUNDATION_TEST start")
40        #处理可能会弹出的USB连接方式弹窗
41        self.driver.touch(BY.text("确定"), EXCEPTION=False)
42
43        Step("预置条件1:设置休眠时长1min")
44        self.driver.Screen.set_sleep_time(60)
45
46        Step("预置条件2:关闭AOD息屏显示")
47        self.driver.start_app("com.huawei.hmos.settings")
48
49        #点击顶部搜索设置项
50        self.driver.touch(BY.type('SearchField'))
51        self.driver.wait(0.5)
52
53        self.driver.wait(2)
54
55        #处理可能会弹出的小艺使用请求
56        self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False)
57        self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False)
58
59        #输入xiping
60        self.driver.input_text(BY.type("SearchField"), "xiping")
61
62        #点击弹出的熄屏显示控件
63        self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置"))
64        self.driver.switch_component_status(BY.type('Toggle'), False)
65
66        #回到桌面
67        self.driver.go_home()
68
69        #清除日志
70        host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn))
71        host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn))
72
73    def test_step(self):
74        Step("kill foundation进程")
75        self.driver.System.execute_command("kill -9 `pidof foundation`")
76
77        Step("等待7s")
78        time.sleep(7)
79
80        Step("7s后解锁进入桌面")
81        self.driver.ScreenLock.unlock()
82
83        Step("按键灭屏")
84        self.driver.press_key(KeyCode.POWER)
85        self.driver.wait(2)
86
87        Step("检查是否为灭屏状态")
88        self.driver.Screen.check_on(expect_on=False)
89
90        time.sleep(2)
91
92        Step("按键亮屏")
93        self.driver.press_key(KeyCode.POWER)
94        self.driver.wait(1)
95
96        Step("检查是否为亮屏状态")
97        self.driver.Screen.check_on()
98
99
100
101    def teardown(self):
102        Step("收尾工作")
103        self.log.info("SUB_KILL_FOUNDATION_TEST down")
104        self.driver.stop_app("com.huawei.hmos.settings")
105
106        #回到桌面
107        self.driver.go_home()