1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (C) 2024 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15import pytest 16import re 17from utils import * 18 19class TestScreenshot: 20 21 @pytest.mark.L0 22 def test_screenshot(self): 23 if IsOpenHarmonyVersion(): 24 pytest.skip("this testcase is only support in HO") 25 else: 26 process_hilog = subprocess.Popen(['hdc', 'shell', 'hilog | grep Dumper > /data/local/tmp/screenshot.txt']) 27 time.sleep(1) 28 # 唤醒屏幕 29 subprocess.check_call("hdc shell power-shell wakeup", shell=True) 30 # 设置屏幕常亮 31 subprocess.check_call("hdc shell power-shell setmode 602", shell=True) 32 time.sleep(3) 33 # 解锁屏幕 34 subprocess.check_call("hdc shell uinput -T -g 100 100 500 500", shell=True) 35 # 触发截图 36 subprocess.check_call("hdc shell uinput -T -m 1000 0 1000 1000 500 && hdc shell uinput -T -c 300 2300", shell=True) 37 time.sleep(3) 38 process_hilog.terminate() 39 if process_hilog.poll() is None: 40 process_name = "hilog | grep Dumper" 41 CloseProcess(process_name) 42 time.sleep(3) 43 output = subprocess.check_output(f"hdc shell cat /data/local/tmp/screenshot.txt", text=True, encoding="utf-8") 44 assert "dump fail!ret" not in output 45 assert "dump success, cmd" in output