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 26 matching lines...) Expand all Loading... | |
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 |
47 def GoogleAccountsLogin(test, url, username, password): | 47 def GoogleAccountsLogin(test, url, username, password, tab_index=0, windex=0): |
Nirnimesh
2010/12/09 00:25:14
I think the url should be hardcoded. It'll only ev
sunandt
2010/12/09 00:47:46
Done.
| |
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 url: url where user is trying to login. | |
Nirnimesh
2010/12/09 00:25:14
remove this
sunandt
2010/12/09 00:47:46
Done.
| |
55 username: users login input. | 56 username: users login input. |
56 password: users login password input. | 57 password: users login password input. |
58 tab_index: The tab index, default is 0. | |
59 windex: The window index, default is 0. | |
57 """ | 60 """ |
58 test.NavigateToURL('https://www.google.com/accounts/') | 61 test.NavigateToURL(url, windex, tab_index) |
Nirnimesh
2010/12/09 00:25:14
hardcode the url here
sunandt
2010/12/09 00:47:46
Done.
| |
59 email_id = 'document.getElementById("Email").value = \"%s\"; ' \ | 62 email_id = 'document.getElementById("Email").value = "%s"; ' \ |
60 'window.domAutomationController.send("done")' % username | 63 'window.domAutomationController.send("done")' % username |
61 password = 'document.getElementById("Passwd").value = \"%s\"; ' \ | 64 password = 'document.getElementById("Passwd").value = "%s"; ' \ |
62 'window.domAutomationController.send("done")' % password | 65 'window.domAutomationController.send("done")' % password |
63 test.ExecuteJavascript(email_id); | 66 test.ExecuteJavascript(email_id, windex, tab_index); |
64 test.ExecuteJavascript(password); | 67 test.ExecuteJavascript(password, windex, tab_index); |
65 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' | 68 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' |
66 'window.domAutomationController.send("done")') | 69 'window.domAutomationController.send("done")', |
70 windex, tab_index) | |
67 | 71 |
68 | 72 |
69 def VerifyGoogleAccountCredsFilled(test, username, password): | 73 def VerifyGoogleAccountCredsFilled(test, username, password, tab_index=0, |
74 windex=0): | |
70 """Verify stored/saved user and password values to the values in the field. | 75 """Verify stored/saved user and password values to the values in the field. |
71 | 76 |
72 Args: | 77 Args: |
73 test: derived from pyauto.PyUITest - base class for UI test cases. | 78 test: derived from pyauto.PyUITest - base class for UI test cases. |
74 username: user log in input. | 79 username: user log in input. |
75 password: user log in password input. | 80 password: user log in password input. |
81 tab_index: The tab index, default is 0. | |
82 windex: The window index, default is 0. | |
76 """ | 83 """ |
77 email_value = test.GetDOMValue('document.getElementById("Email").value') | 84 email_value = test.GetDOMValue('document.getElementById("Email").value', |
78 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value') | 85 windex, tab_index) |
86 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value', | |
87 windex, tab_index) | |
79 test.assertEqual(email_value, username) | 88 test.assertEqual(email_value, username) |
80 test.assertEqual(passwd_value, password) | 89 test.assertEqual(passwd_value, password) |
81 | 90 |
82 | 91 |
83 def ClearPasswords(test): | 92 def ClearPasswords(test): |
84 """Clear saved passwords.""" | 93 """Clear saved passwords.""" |
85 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') | 94 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') |
86 | 95 |
87 | 96 |
88 def Shell2(cmd_string, bg=False): | 97 def Shell2(cmd_string, bg=False): |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 if file_to_send is not None: | 139 if file_to_send is not None: |
131 part.set_payload(open(file_to_send,'rb').read()) | 140 part.set_payload(open(file_to_send,'rb').read()) |
132 email.Encoders.encode_base64(part) | 141 email.Encoders.encode_base64(part) |
133 part.add_header('Content-Disposition', | 142 part.add_header('Content-Disposition', |
134 'attachment; filename="%s"' | 143 'attachment; filename="%s"' |
135 % os.path.basename(file_to_send)) | 144 % os.path.basename(file_to_send)) |
136 msg.attach(part) | 145 msg.attach(part) |
137 smtp_obj = smtplib.SMTP(smtp) | 146 smtp_obj = smtplib.SMTP(smtp) |
138 smtp_obj.sendmail(send_from, send_to, msg.as_string()) | 147 smtp_obj.sendmail(send_from, send_to, msg.as_string()) |
139 smtp_obj.close() | 148 smtp_obj.close() |
140 | |
OLD | NEW |