From d06d4c539132ff9e4e8173af0e2f762e6a44c70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=B9=BF=E7=94=9F?= Date: Fri, 4 Jul 2025 07:46:11 +0000 Subject: [PATCH] =?UTF-8?q?add=20helloworld=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 马广生 --- .../screenshot32/new_script/testcases.json | 4 ++ .../new_script/testcases/test_hap.py | 37 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 cases/smoke/basic/screenshot32/new_script/testcases/test_hap.py diff --git a/cases/smoke/basic/screenshot32/new_script/testcases.json b/cases/smoke/basic/screenshot32/new_script/testcases.json index ce74b5f..249b9b9 100644 --- a/cases/smoke/basic/screenshot32/new_script/testcases.json +++ b/cases/smoke/basic/screenshot32/new_script/testcases.json @@ -50,5 +50,9 @@ { "case_file": "testcases/test_note.py", "description": "备忘录应用测试" + }, + { + "case_file": "testcases/test_hap.py", + "description": "hap包测试" } ] \ No newline at end of file diff --git a/cases/smoke/basic/screenshot32/new_script/testcases/test_hap.py b/cases/smoke/basic/screenshot32/new_script/testcases/test_hap.py new file mode 100644 index 0000000..7140237 --- /dev/null +++ b/cases/smoke/basic/screenshot32/new_script/testcases/test_hap.py @@ -0,0 +1,37 @@ +import logging +import os.path +import time + +import pytest + +from utils.images import compare_image_similarity, crop_picture + + +@pytest.fixture(autouse=True) +def uninstall_hap(device): + yield + try: + device.uninstall_hap('com.example.helloworld') + except: + pass + + +class Test: + ability_name = 'EntryAbility' + bundle_name = 'com.example.helloworld' + + @pytest.mark.parametrize('setup_teardown', [None], indirect=True) + def test(self, setup_teardown, device): + logging.info('install hap') + hap_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(device.resource_path))), 'entry-default-signed.hap') + device.install_hap(hap_path) + time.sleep(1) + logging.info('start app') + device.start_ability(self.bundle_name, self.ability_name) + time.sleep(2) + main_page = device.save_snapshot_to_local('{}_hap.jpeg'.format(device.sn)) + crop_picture(picture=main_page, x1=0, y1=72, x2=297, y2=290) + stand_pic = os.path.join(device.resource_path, 'hap.jpeg') + + similarity = compare_image_similarity(main_page, stand_pic) + assert similarity > 0.8, '截图对比失败' -- Gitee