forked from JonHylands/power-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_camera.py
122 lines (90 loc) · 4.11 KB
/
test_camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from gaiatest import GaiaTestCase
from gaiatest.apps.lockscreen.app import LockScreen
from gaiatest.apps.camera.app import Camera
from marionette_driver.marionette import Actions
from marionette_driver.by import By
from powertests import TestPower
from powertool.mozilla import MozillaAmmeter
from datetime import datetime
import time
import json
import sys
import os
import subprocess
PICTURE_INTERVAL_TIME = 5 # seconds between photos
class TestCameraPower(TestPower):
_camera_frame_locator = (By.CSS_SELECTOR, 'iframe[src*="camera"][src*="/index.html"]')
def setUp(self):
TestPower.setUp(self)
def take_picture(self):
self.camera.take_photo()
def test_camera_preview(self):
"""https://moztrap.mozilla.org/manage/case/1296/"""
lock_screen = LockScreen(self.marionette)
homescreen = lock_screen.unlock()
self.wait_for_condition(lambda m: self.apps.displayed_app.name == homescreen.name)
# Turn off the geolocation prompt, and then launch the camera app
self.apps.set_permission('Camera', 'geolocation', 'deny')
self.camera = Camera(self.marionette)
self.camera.launch()
while (self.camera.current_flash_mode != 'off'):
self.camera.tap_toggle_flash_button();
time.sleep(2)
self.marionette.switch_to_frame()
self.wait_for_element_present(*self._camera_frame_locator)
camera_frame = self.marionette.find_element(*self._camera_frame_locator)
camera_frame.tap()
self.marionette.switch_to_frame(camera_frame)
print ""
print "Running Camera Preview Test"
self.runPowerTest("camera_preview", "Camera", "camera")
def test_camera_video(self):
"""https://moztrap.mozilla.org/manage/case/1296/"""
lock_screen = LockScreen(self.marionette)
homescreen = lock_screen.unlock()
self.wait_for_condition(lambda m: self.apps.displayed_app.name == homescreen.name)
# Turn off the geolocation prompt, and then launch the camera app
self.apps.set_permission('Camera', 'geolocation', 'deny')
self.camera = Camera(self.marionette)
self.camera.launch()
while (self.camera.current_flash_mode != 'off'):
self.camera.tap_toggle_flash_button();
time.sleep(2)
time.sleep(5)
self.camera.tap_switch_source()
time.sleep(5)
self.marionette.switch_to_frame()
self.wait_for_element_present(*self._camera_frame_locator)
camera_frame = self.marionette.find_element(*self._camera_frame_locator)
camera_frame.tap()
self.marionette.switch_to_frame(camera_frame)
self.camera.tap_capture()
print ""
print "Running Camera Video Test"
self.runPowerTest("camera_video", "Camera", "camera")
self.camera.tap_capture()
def test_camera_picture(self):
"""https://moztrap.mozilla.org/manage/case/1296/"""
lock_screen = LockScreen(self.marionette)
homescreen = lock_screen.unlock()
self.wait_for_condition(lambda m: self.apps.displayed_app.name == homescreen.name)
# Turn off the geolocation prompt, and then launch the camera app
self.apps.set_permission('Camera', 'geolocation', 'deny')
self.camera = Camera(self.marionette)
self.camera.launch()
while (self.camera.current_flash_mode != 'off'):
self.camera.tap_toggle_flash_button();
time.sleep(2)
self.marionette.switch_to_frame()
self.wait_for_element_present(*self._camera_frame_locator)
camera_frame = self.marionette.find_element(*self._camera_frame_locator)
camera_frame.tap()
self.marionette.switch_to_frame(camera_frame)
print ""
print "Running Camera Picture Test"
self.runPowerTest("camera_picture", "Camera", "camera", PICTURE_INTERVAL_TIME, self.take_picture)
def tearDown(self):
TestPower.tearDown(self)