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_MUSIC_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_MUSIC_TEST start") 41 #处理可能会弹出的USB连接方式弹窗 42 self.driver.touch(BY.text("确定"), EXCEPTION=False) 43 44 #清除日志 45 host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) 46 host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) 47 48 #回到桌面 49 self.driver.go_home() 50 51 def test_step(self): 52 Step("启动音乐应用") 53 app = Launcher.find.app(self.driver, "音乐") 54 host.check(app is not None, fail_msg='找不到音乐应用') 55 self.driver.touch(app) 56 self.driver.wait(0.5) 57 58 #处理第一次弹出的同意使用app的选项 59 self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) 60 self.driver.wait(0.5) 61 62 #通过相对位置点击控件,开始播放音乐 63 self.driver.touch(BY.isAfter(BY.key('uiplus_cover')).isBefore(BY.key('uiplus_title_right')).key('uiplus_rl_play').type('SymbolGlyph')) 64 self.driver.wait(0.5) 65 66 67 self.driver.wait(100) 68 self.driver.Audio.start_check_audio_in_background(VolumeType.MEDIA, 100) 69 self.driver.Audio.check_audio_result_in_background(VolumeType.MEDIA, expect_play=True) 70 71 72 def teardown(self): 73 Step("收尾工作") 74 self.log.info("SUB_MUSIC_TEST down") 75 self.driver.stop_app("com.huawei.hmsapp.music") 76 77 #回到桌面 78 self.driver.go_home()