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
122
123
124
125
|
#!/usr/bin/python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import time
import pyauto_functional
import pyauto
class NetflixTest(pyauto.PyUITest):
"""Test case for Netflix player"""
# Netflix player states
_is_playing = '4'
_title_homepage = 'http://movies.netflix.com/WiHome'
_signout_page = 'https://account.netflix.com/Logout'
# 30 Rock
_test_title = 'http://movies.netflix.com/WiPlayer?'+ \
'movieid=70136124&trkid=2361637&t=30+Rock'
def tearDown(self):
self._SignOut()
pyauto.PyUITest.tearDown(self)
def _IsNetflixPluginEnabled(self):
"""Determine Netflix plugin availability and its state"""
return [x for x in self.GetPluginsInfo().Plugins() \
if x['name'] == 'Netflix' and x['enabled']]
def _LoginToNetflix(self):
"""Login to Netflix"""
credentials = self.GetPrivateInfo()['test_netflix_acct']
self.NavigateToURL(credentials['login_url'])
login_js = """
document.getElementById('email').value='%s';
document.getElementById('password').value='%s';
document.getElementById('login-form').submit()
window.domAutomationController.send('ok');
""" % (credentials['username'], credentials['password'])
self.assertEqual(self.ExecuteJavascript(login_js), 'ok',
msg='Login to Netflix failed')
def _HandleInfobars(self):
"""Manage infobars, come up during the test.
We expect password and Netflix infobars. Processing only Netflix infobar,
since to start a vidoe, pressing the OK button is a must. We can keep other
inforbars open."""
self.WaitForInfobarCount(2)
tab_info = self.GetBrowserInfo()['windows'][0]['tabs'][0]
infobars = tab_info['infobars']
index = 0
netflix_infobar_status = False
for infobar in infobars:
if infobar['buttons'][0] == 'OK':
self.PerformActionOnInfobar('accept', infobar_index=index)
netflix_infobar_status = True
index = index + 1
self.assertTrue(netflix_infobar_status,
msg='Netflix infobar did not show up')
def _CurrentPlaybackTime(self):
"""Returns the current playback time in seconds"""
time = self.ExecuteJavascript("""
time = nrdp.video.currentTime;
window.domAutomationController.send(time + '');
""")
return int(float(time))
def _SignOut(self):
"""Sing out from Netflix Login"""
self.NavigateToURL(self._signout_page)
def _LoginAndStartPlaying(self):
"""Login and start playing the video"""
self.assertTrue(self._IsNetflixPluginEnabled(),
msg='Netflix plugin is disabled or not available')
self._LoginToNetflix()
self.assertTrue(self.WaitUntil(
lambda:self.GetActiveTabURL().spec(),
expect_retval=self._title_homepage),
msg='Login to Netflix failed')
self.NavigateToURL(self._test_title)
self._HandleInfobars()
self.assertTrue(self.WaitUntil(
lambda: self.ExecuteJavascript("""
player_status = nrdp.video.readyState;
window.domAutomationController.send(player_status + '');
"""), expect_retval=self._is_playing),
msg='Player did not start playing the title')
def testPlayerLoadsAndPlays(self):
"""Test that Netflix player loads and plays the title"""
self._LoginAndStartPlaying()
def testPlaying(self):
"""Test that title playing progresses"""
self._LoginAndStartPlaying()
title_length = self.ExecuteJavascript("""
time = nrdp.video.duration;
window.domAutomationController.send(time + '');
""")
title_length = int(float(title_length))
prev_time = 0
current_time = 0
count = 0
while current_time < title_length:
# We want to test playing only for five seconds
count = count + 1
if count == 5:
break
current_time = self._CurrentPlaybackTime()
self.assertTrue(prev_time <= current_time,
msg='Prev playing time %s is greater than current time %s'
% (prev_time, current_time))
prev_time = current_time
# play video for some time
time.sleep(1)
if __name__ == '__main__':
pyauto_functional.Main()
|