• 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.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_SHUTDOWN_REBOOT_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_SHUTDOWN_REBOOT_TEST start")
41        #处理可能会弹出的USB连接方式弹窗
42        self.driver.touch(BY.text("确定"), EXCEPTION=False)
43
44        Step("预置条件1:设置休眠时长15s")
45        self.driver.Screen.set_sleep_time(15)
46
47        Step("预置条件2:关闭AOD息屏显示")
48        self.driver.start_app("com.huawei.hmos.settings")
49
50        #点击顶部搜索设置项
51        self.driver.touch(BY.type('SearchField'))
52        self.driver.wait(0.5)
53
54        self.driver.wait(2)
55
56        #处理可能会弹出的小艺使用请求
57        self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False)
58        self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False)
59
60        #输入xiping
61        self.driver.input_text(BY.type("SearchField"), "xiping")
62
63        #点击弹出的熄屏显示控件
64        self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置"))
65        self.driver.switch_component_status(BY.type('Toggle'), False)
66
67
68        #回到桌面
69        self.driver.go_home()
70
71        #点亮屏幕
72        self.driver.Screen.wake_up()
73
74        #清除日志
75        host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn))
76        host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn))
77
78
79
80    def test_step(self):
81        #解锁进桌面
82        self.driver.ScreenLock.unlock()
83        self.driver.wait(3)
84
85        Step("步骤1:长按power键")
86        self.driver.press_key(KeyCode.POWER, mode=UiParam.LONG, duration=5)
87        self.driver.wait(1)
88
89        CheckPoint("检测点:可弹出关机重启按钮")
90        self.driver.check_component_exist(BY.type('Text').text('重启'), expect_exist=True)
91        self.driver.check_component_exist(BY.type('Text').text('关机'), expect_exist=True)
92
93        Step("步骤2:点击关机按钮")
94        com = self.driver.find_all_components(BY.type('Button'), index=1)
95        self.driver.touch(com, wait_time=1.5)
96
97        CheckPoint("检测点:单独显示关机按钮 用于再次确认")
98        self.driver.check_component_exist(BY.type('Text').text('点击关机'), expect_exist=True)
99        #点击空白处,回到上一个页面
100        self.driver.touch((500, 1800), wait_time=1.5)
101
102        Step("步骤3:点击重启按钮")
103        com = self.driver.find_all_components(BY.type('Button'), index=0)
104        self.driver.touch(com, wait_time=1.5)
105
106        CheckPoint("检测点:单独显示重启按钮 用于再次确认")
107        self.driver.check_component_exist(BY.type('Text').text('点击重启'), expect_exist=True)
108
109        Step("步骤4:点击重启按钮")
110        self.driver.touch(BY.type('Image'), wait_time=1.5)
111
112        #等待启动完成
113        self.driver.System.wait_for_boot_complete()
114
115
116
117    def teardown(self):
118        Step("收尾工作")
119        self.log.info("SUB_SHUTDOWN_REBOOT_TEST down")
120        self.driver.stop_app("com.huawei.hmos.settings")
121
122        #回到桌面
123        self.driver.go_home()