• 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_POWER_SHELL_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_POWER_SHELL_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        host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn))
73        host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn))
74
75    def test_step(self):
76        Step("hdc shell 下执行power-shell --help")
77        result = self.driver.System.execute_command("power-shell --help")
78
79        CheckPoint("只打印setmode、wakeup、suspend、timeout、help命令,其他不打印,且命令功能正常")
80        assert "setmode :    Set power mode" in result
81        assert "wakeup  :    Wakeup system and turn screen on" in result
82        assert "suspend :    Suspend system and turn screen off" in result
83        assert "timeout :    Override or Restore screen off time" in result
84        assert "help    :    Show this help menu" in result
85
86
87        Step("设备执行pwoer-shell命令:power-shell suspend")
88        self.driver.System.execute_command("power-shell suspend")
89
90        CheckPoint("原本的power-shell命令可以正常使用")
91        self.driver.Screen.check_on(expect_on=False)
92
93        Step("设备执行pwoer-shell命令:power-shell wakeup")
94        self.driver.System.execute_command("power-shell wakeup")
95        self.driver.Screen.check_on()
96
97        Step("设备执行pwoer-shell命令:power-shell timeout -o 5000")
98        self.driver.System.execute_command("power-shell timeout -o 5000")
99        time.sleep(5)
100        self.driver.Screen.check_on(expect_on=False)
101
102        Step("设备执行pwoer-shell命令:power-shell timeout -r")
103        self.driver.System.execute_command("power-shell timeout -r")
104        #恢复超时灭屏时间后唤醒设备
105        self.driver.System.execute_command("power-shell wakeup")
106        #解锁进入桌面
107        self.driver.ScreenLock.unlock()
108        time.sleep(15)
109        #等待15s后灭屏
110        self.driver.Screen.check_on(expect_on=False)
111
112
113    def teardown(self):
114        Step("收尾工作")
115        self.log.info("SUB_POWER_SHELL_TEST down")
116
117        #回到桌面
118        self.driver.go_home()