OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import email | 7 import email |
8 import os | 8 import os |
9 import smtplib | 9 import smtplib |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 """ | 23 """ |
24 file_url = test.GetFileURLForDataPath(os.path.join('downloads', file_name)) | 24 file_url = test.GetFileURLForDataPath(os.path.join('downloads', file_name)) |
25 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), | 25 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), |
26 file_name) | 26 file_name) |
27 # Check if file already exists. If so then delete it. | 27 # Check if file already exists. If so then delete it. |
28 if os.path.exists(downloaded_pkg): | 28 if os.path.exists(downloaded_pkg): |
29 RemoveDownloadedTestFile(test, file_name) | 29 RemoveDownloadedTestFile(test, file_name) |
30 test.DownloadAndWaitForStart(file_url) | 30 test.DownloadAndWaitForStart(file_url) |
31 test.WaitForAllDownloadsToComplete() | 31 test.WaitForAllDownloadsToComplete() |
32 | 32 |
33 | 33 |
Nirnimesh
2010/12/08 20:59:17
Remove the extra blank space
sunandt
2010/12/08 22:46:34
Done.
| |
34 def RemoveDownloadedTestFile(test, file_name): | 34 def RemoveDownloadedTestFile(test, file_name): |
35 """Delete a file from the downloads directory. | 35 """Delete a file from the downloads directory. |
36 | 36 |
37 Arg: | 37 Arg: |
38 test: derived from pyauto.PyUITest - base class for UI test cases | 38 test: derived from pyauto.PyUITest - base class for UI test cases |
39 file_name: name of file to remove | 39 file_name: name of file to remove |
40 """ | 40 """ |
41 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), | 41 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), |
42 file_name) | 42 file_name) |
43 pyauto_utils.RemovePath(downloaded_pkg) | 43 pyauto_utils.RemovePath(downloaded_pkg) |
44 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') | 44 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') |
45 | 45 |
46 | 46 |
Nirnimesh
2010/12/08 20:59:17
ditto
sunandt
2010/12/08 22:46:34
Done.
| |
47 def GoogleAccountsLogin(test, url, username, password): | 47 def GoogleAccountsLogin(test, url, username, password, tab_index=0, windex=0): |
48 """Log into Google Accounts. | 48 """Log into Google Accounts. |
49 | 49 |
50 Attempts to login to Google by entering the username/password into the google | 50 Attempts to login to Google by entering the username/password into the google |
51 login page and click submit button. | 51 login page and click submit button. |
52 | 52 |
53 Args: | 53 Args: |
54 test: derived from pyauto.PyUITest - base class for UI test cases. | 54 test: derived from pyauto.PyUITest - base class for UI test cases. |
55 username: users login input. | 55 username: users login input. |
56 password: users login password input. | 56 password: users login password input. |
Nirnimesh
2010/12/08 20:59:17
document the args
sunandt
2010/12/08 22:46:34
Done.
| |
57 """ | 57 """ |
Nirnimesh
2010/12/08 20:59:17
get rid of extra blank spaces
| |
58 test.NavigateToURL('https://www.google.com/accounts/') | 58 test.NavigateToURL(url, windex, tab_index) |
59 email_id = 'document.getElementById("Email").value = \"%s\"; ' \ | 59 email_id = 'document.getElementById("Email").value = "%s"; ' \ |
60 'window.domAutomationController.send("done")' % username | 60 'window.domAutomationController.send("done")' % username |
61 password = 'document.getElementById("Passwd").value = \"%s\"; ' \ | 61 password = 'document.getElementById("Passwd").value = "%s"; ' \ |
62 'window.domAutomationController.send("done")' % password | 62 'window.domAutomationController.send("done")' % password |
63 test.ExecuteJavascript(email_id); | 63 test.ExecuteJavascript(email_id, windex, tab_index); |
64 test.ExecuteJavascript(password); | 64 test.ExecuteJavascript(password, windex, tab_index); |
65 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' | 65 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' |
66 'window.domAutomationController.send("done")') | 66 'window.domAutomationController.send("done")', |
67 windex, tab_index) | |
67 | 68 |
68 | 69 |
69 def VerifyGoogleAccountCredsFilled(test, username, password): | 70 def VerifyGoogleAccountCredsFilled(test, username, password, tab_index=0, |
71 windex=0): | |
70 """Verify stored/saved user and password values to the values in the field. | 72 """Verify stored/saved user and password values to the values in the field. |
71 | 73 |
72 Args: | 74 Args: |
73 test: derived from pyauto.PyUITest - base class for UI test cases. | 75 test: derived from pyauto.PyUITest - base class for UI test cases. |
74 username: user log in input. | 76 username: user log in input. |
75 password: user log in password input. | 77 password: user log in password input. |
76 """ | 78 """ |
77 email_value = test.GetDOMValue('document.getElementById("Email").value') | 79 email_value = test.GetDOMValue('document.getElementById("Email").value', |
78 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value') | 80 windex, tab_index) |
81 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value', | |
82 windex, tab_index) | |
79 test.assertEqual(email_value, username) | 83 test.assertEqual(email_value, username) |
80 test.assertEqual(passwd_value, password) | 84 test.assertEqual(passwd_value, password) |
81 | 85 |
82 | 86 |
Nirnimesh
2010/12/08 20:59:17
remove extra blank spaces
sunandt
2010/12/08 22:46:34
Done.
| |
83 def ClearPasswords(test): | 87 def ClearPasswords(test): |
84 """Clear saved passwords.""" | 88 """Clear saved passwords.""" |
85 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') | 89 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') |
86 | 90 |
87 | 91 |
Nirnimesh
2010/12/08 20:59:17
remove extra blank spaces
sunandt
2010/12/08 22:46:34
Done.
| |
88 def Shell2(cmd_string, bg=False): | 92 def Shell2(cmd_string, bg=False): |
89 """Run a shell command. | 93 """Run a shell command. |
90 | 94 |
91 Args: | 95 Args: |
92 cmd_string: command to run | 96 cmd_string: command to run |
93 bg: should the process be run in background? Default: False | 97 bg: should the process be run in background? Default: False |
94 | 98 |
95 Returns: | 99 Returns: |
96 Output, return code | 100 Output, return code |
97 """ | 101 """ |
98 if not cmd_string: return ('', 0) | 102 if not cmd_string: return ('', 0) |
99 if bg: | 103 if bg: |
100 cmd_string += ' 1>/dev/null 2>&1 &' | 104 cmd_string += ' 1>/dev/null 2>&1 &' |
101 proc = os.popen(cmd_string) | 105 proc = os.popen(cmd_string) |
102 if bg: return ('Background process: %s' % cmd_string, 0) | 106 if bg: return ('Background process: %s' % cmd_string, 0) |
103 out = proc.read() | 107 out = proc.read() |
104 retcode = proc.close() | 108 retcode = proc.close() |
105 if not retcode: # Success | 109 if not retcode: # Success |
106 retcode = 0 | 110 retcode = 0 |
107 return (out, retcode) | 111 return (out, retcode) |
108 | 112 |
109 | 113 |
Nirnimesh
2010/12/08 20:59:17
remove extra blank spaces
sunandt
2010/12/08 22:46:34
Done.
| |
110 def SendMail(send_from, send_to, subject, text, smtp, file_to_send=None): | 114 def SendMail(send_from, send_to, subject, text, smtp, file_to_send=None): |
111 """Send mail to all the group to notify about the crash and uploaded data. | 115 """Send mail to all the group to notify about the crash and uploaded data. |
112 | 116 |
113 Args: | 117 Args: |
114 send_from: from mail id. | 118 send_from: from mail id. |
115 send_to: to mail id. | 119 send_to: to mail id. |
116 subject: mail subject. | 120 subject: mail subject. |
117 text: mail body. | 121 text: mail body. |
118 smtp: The smtp to use. | 122 smtp: The smtp to use. |
119 file_to_send: attachments for the mail. | 123 file_to_send: attachments for the mail. |
(...skipping 10 matching lines...) Expand all Loading... | |
130 if file_to_send is not None: | 134 if file_to_send is not None: |
131 part.set_payload(open(file_to_send,'rb').read()) | 135 part.set_payload(open(file_to_send,'rb').read()) |
132 email.Encoders.encode_base64(part) | 136 email.Encoders.encode_base64(part) |
133 part.add_header('Content-Disposition', | 137 part.add_header('Content-Disposition', |
134 'attachment; filename="%s"' | 138 'attachment; filename="%s"' |
135 % os.path.basename(file_to_send)) | 139 % os.path.basename(file_to_send)) |
136 msg.attach(part) | 140 msg.attach(part) |
137 smtp_obj = smtplib.SMTP(smtp) | 141 smtp_obj = smtplib.SMTP(smtp) |
138 smtp_obj.sendmail(send_from, send_to, msg.as_string()) | 142 smtp_obj.sendmail(send_from, send_to, msg.as_string()) |
139 smtp_obj.close() | 143 smtp_obj.close() |
140 | |
OLD | NEW |