• 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 Photos(ITestCase):
11    photo_ability_name = 'com.ohos.photos.MainAbility'
12    photo_bundle_name = 'com.ohos.photos'
13    shot_ability_name = 'com.ohos.screenshot.ServiceExtAbility'
14    shot_bundle_name = 'com.ohos.screenshot'
15
16    def __init__(self, controllers):
17        super().__init__(controllers)
18
19    def setup(self):
20        self.step('前置条件1:回到桌面')
21        self.common_oh.goHome(self.Phone1)
22        self.step('前置条件2:检查当前界面是否在桌面')
23        self.common_oh.checkIfTextExist(self.Phone1, '相机')
24
25    def process(self):
26        self.step('步骤1:启动相册app')
27        self.common_oh.startAbility(self.Phone1, self.photo_ability_name, self.photo_bundle_name)
28        # 控件检查
29        self.common_oh.wait(self.Phone1, 2)
30        self.step('步骤2:控件检查')
31        self.common_oh.checkIfTextExist(self.Phone1, '照片')
32        self.common_oh.checkIfTextExist(self.Phone1, '相册')
33        # 截图对比
34        self.step('步骤3:截图对比')
35        photos_pic = 'photos.jpeg'
36        self.take_picture_to_local(photos_pic)
37        self.crop_picture(photos_pic)
38        similarity = self.compare_image_similarity(photos_pic)
39        print_info('相似度为:{}%'.format(similarity))
40        self.asserts.assert_greater_equal(similarity, self.STANDARD_SIMILARITY)
41        self.step('步骤4:medialibrarydata进程检查')
42        process = 'com.ohos.medialibrary.medialibrarydata'
43        self.common_oh.isProcessRunning(self.Phone1, process)
44        self.common_oh.wait(self.Phone1, 1)
45        # sandbox path检查
46        self.step('步骤5:检查sandbox path')
47        pid_num = self.common_oh.shell(self.Phone1, 'pgrep -f {}'.format(process)).strip()
48        self.common_oh.wait(self.Phone1, 1)
49        sanboxf = self.common_oh.shell(self.Phone1, 'echo \"ls /storage/media/local/\"|nsenter -t {} -m sh'.format(pid_num))
50        self.common_oh.wait(self.Phone1, 1)
51        self.asserts.assert_in('files', sanboxf)
52
53    def teardown(self):
54        self.step('收尾1:停掉相册应用')
55        self.common_oh.forceStopAbility(self.Phone1, self.photo_bundle_name)
56