1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3""" 4Copyright (c) 2024 Huawei Device Co., Ltd. 5Licensed under the Apache License, Version 2.0 (the "License"); 6you may not use this file except in compliance with the License. 7You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11Unless required by applicable law or agreed to in writing, software 12distributed under the License is distributed on an "AS IS" BASIS, 13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14See the License for the specific language governing permissions and 15limitations under the License. 16 17Description: Scenario test case. 18""" 19 20import logging 21import os 22import time 23 24import pytest 25 26from aw import Application 27from aw import Utils 28 29 30@pytest.mark.hot_reload 31@pytest.mark.timeout(180) 32class TestHotReload03: 33 """ 34 测试用例:热重载_重载页面未启动 35 测试步骤: 36 1、启动应用,加载Index页面 37 2、点击进入Mine页面,点击屏幕,输出日志: 38 Test Application HotReloadPages01::Mine => add(): 3 39 3、触发热重载,输出日志: 40 Test Application HotReloadPages01::Mine => add(): 46 41 4、返回Index页面,重新进入Mine页面,点击屏幕,输出日志: 42 Test Application HotReloadPages01::Mine => add(): 46 43 4、在Mine页面再次触发热重载,输出日志: 44 Test Application HotReloadPages01::Mine => add(): 134 45 46 测试应用代码示例: 47 修改前: 48 Index.ets 49 .fontSize(getFontSize()) 50 .onClick(() => { 51 router.pushUrl({'url': 'pages/Mine'}) 52 }) 53 function getFontSize() { 54 let fontSize = 50 55 console.log("Test Application HotReloadPages01::Index => fontSize:", fontSize); 56 return fontSize 57 } 58 Mine.ets 59 .onClick(() => { 60 console.log("Test Application HotReloadPages01::Mine => add():", add(1, 2)); 61 }) 62 第一次修改:HotReloadPages01.03.hqf 63 Mine.ets 64 .onClick(() => { 65 console.log("Test Application HotReloadPages01::Mine => add():", add(12, 34)); 66 }) 67 第二次修改:HotReloadPages01.04.hqf 68 Mine.ets 69 .onClick(() => { 70 console.log("Test Application HotReloadPages01::Mine => add():", add(56, 78)); 71 }) 72 """ 73 74 def setup_method(self): 75 logging.info('Start running test_hot_reload_03: setup') 76 77 self.log_path = rf'{os.path.dirname(__file__)}\..\log' 78 self.hilog_file_name = 'test_hot_reload_03.hilog.txt' 79 self.hilog_file_path = os.path.join(self.log_path, self.hilog_file_name) 80 self.id_generator = Utils.message_id_generator() 81 82 # receive the hilog before the test start 83 Utils.clear_fault_log() 84 self.hilog_process, self.write_thread = Utils.save_hilog(log_path=self.log_path, 85 file_name=self.hilog_file_name, 86 debug_on=False) 87 88 def teardown_method(self): 89 Application.uninstall(self.config['bundle_name']) 90 91 # terminate the hilog receive process after the test done 92 time.sleep(3) 93 self.hilog_process.stdout.close() 94 self.hilog_process.terminate() 95 self.hilog_process.wait() 96 self.write_thread.join() 97 98 Utils.save_fault_log(log_path=self.log_path) 99 logging.info('test_hot_reload_03 done') 100 101 def test(self, test_suite_hotreload_pages_01): 102 logging.info('Start running test_hot_reload_03: test') 103 self.config = test_suite_hotreload_pages_01 104 ################################################################################################################ 105 # jump to the Mine page 106 ################################################################################################################ 107 Application.click_on_middle() 108 time.sleep(3) 109 Application.click_on_middle() # trigger onclick event 110 time.sleep(3) 111 matched_log = Utils.search_hilog(self.hilog_file_path, 112 key_world=b"Test Application HotReloadPages01::Mine => add(): 3") 113 logging.info(matched_log) 114 assert len(matched_log) == 1 115 ################################################################################################################ 116 # 1st hot reload 117 ################################################################################################################ 118 logging.info(f'{"=" * 30} 1st Hot Reload {"=" * 30}') 119 Utils.hdc_file_send(source=self.config['local_hqf_03_path'], sink=self.config['remote_hqf_03_path']) 120 Application.hot_reload(self.config['remote_hqf_03_path']) 121 time.sleep(3) 122 Application.click_on_middle() # trigger onclick event 123 time.sleep(3) 124 matched_log = Utils.search_hilog(self.hilog_file_path, 125 key_world=b"Test Application HotReloadPages01::Mine => add(): 46") 126 logging.info(matched_log) 127 assert len(matched_log) == 1 128 ################################################################################################################ 129 # back to the Index page, the re-enter the Mine page 130 ################################################################################################################ 131 logging.info(f'{"=" * 30} Back and re-enter the Mine page {"=" * 30}') 132 Application.back() 133 time.sleep(3) 134 Application.click_on_middle() # jump to the Mine page 135 time.sleep(3) 136 Application.click_on_middle() # trigger onclick event 137 time.sleep(3) 138 matched_log = Utils.search_hilog(self.hilog_file_path, 139 key_world=b"Test Application HotReloadPages01::Mine => add(): 46") 140 logging.info(matched_log) 141 assert len(matched_log) == 2 # Counting the previous one. 142 ################################################################################################################ 143 # 2nd hot reload 144 ################################################################################################################ 145 logging.info(f'{"=" * 30} 2nd Hot Reload {"=" * 30}') 146 Utils.hdc_file_send(source=self.config['local_hqf_04_path'], sink=self.config['remote_hqf_04_path']) 147 Application.hot_reload(self.config['remote_hqf_04_path']) 148 time.sleep(3) 149 Application.click_on_middle() # trigger onclick event 150 time.sleep(3) 151 matched_log = Utils.search_hilog(self.hilog_file_path, 152 key_world=b"Test Application HotReloadPages01::Mine => add(): 134") 153 logging.info(matched_log) 154 assert len(matched_log) == 1 155 ################################################################################################################ 156 # check if the application is running normally 157 ################################################################################################################ 158 pid = Application.get_pid(self.config['bundle_name']) 159 assert pid == self.config['pid'], logging.error(f'App is no longer running with pid: {pid}') 160