• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2import os
3
4from devicetest.api import Asserts
5from devicetest.log.logger import print_info
6
7from test_case import ITestCase
8
9
10class DistributedMusicPlayer(ITestCase):
11    ability_name = 'ohos.samples.distributedmusicplayer.MainAbility'
12    bundle_name = 'ohos.samples.distributedmusicplayer'
13
14    def __init__(self, controllers):
15        super().__init__(controllers)
16
17    def setup(self):
18        self.step('前置条件1:回到桌面')
19        self.common_oh.goHome(self.Phone1)
20        self.step('前置条件2:检查当前界面是否在桌面')
21        self.common_oh.checkIfTextExist(self.Phone1, '相机')
22
23
24    def process(self):
25        self.step('步骤1:启动音乐应用')
26        self.common_oh.startAbility(self.Phone1, self.ability_name, self.bundle_name)
27        self.common_oh.wait(self.Phone1, 5)
28        self.step('步骤2:点击弹窗的"允许"')
29        try:
30            self.common_oh.touchByText(self.Phone1, '允许')
31        except:
32            pass
33
34        self.step('步骤3:检查是否进入音乐')
35        # 控件检查
36        self.common_oh.checkIfKeyExist(self.Phone1, 'image1')
37        self.common_oh.checkIfKeyExist(self.Phone1, 'image3')
38
39        self.step('步骤4:截图对比')
40        pic_name = 'distributedmusicplayer.jpeg'
41        self.take_picture_to_local(pic_name)
42        self.crop_picture(pic_name)
43        similarity = self.compare_image_similarity(pic_name)
44        print_info('相似度为:{}%'.format(similarity))
45        # 控件对比和截图对比有一个成功就认为pass
46        self.asserts.assert_greater_equal(similarity, self.STANDARD_SIMILARITY)
47
48    def teardown(self):
49        self.step('收尾1:停掉音乐应用')
50        self.common_oh.forceStopAbility(self.Phone1, self.bundle_name)
51        self.common_oh.cleanApplicationData(self.Phone1, self.bundle_name)