Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 test: derived from pyauto.PyUITest - base class for UI test cases | 21 test: derived from pyauto.PyUITest - base class for UI test cases |
| 22 file_name: name of file to download | 22 file_name: name of file to download |
| 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() |
|
Nirnimesh
2010/11/29 22:42:58
leave 2 blank lines at global scope
sunandt
2010/12/07 23:47:45
Done.
| |
| 32 | 32 |
| 33 | |
| 34 def RemoveDownloadedTestFile(test, file_name): | 33 def RemoveDownloadedTestFile(test, file_name): |
| 35 """Delete a file from the downloads directory. | 34 """Delete a file from the downloads directory. |
| 36 | 35 |
| 37 Arg: | 36 Arg: |
| 38 test: derived from pyauto.PyUITest - base class for UI test cases | 37 test: derived from pyauto.PyUITest - base class for UI test cases |
| 39 file_name: name of file to remove | 38 file_name: name of file to remove |
| 40 """ | 39 """ |
| 41 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), | 40 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), |
| 42 file_name) | 41 file_name) |
| 43 pyauto_utils.RemovePath(downloaded_pkg) | 42 pyauto_utils.RemovePath(downloaded_pkg) |
| 44 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') | 43 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') |
|
Nirnimesh
2010/11/29 22:42:58
ditto. and repeat everywhere
sunandt
2010/12/07 23:47:45
Done.
| |
| 45 | 44 |
| 46 | 45 def GoogleAccountsLogin(test, url, username, password, windex=0, tab_index=0): |
|
Nirnimesh
2010/11/29 22:42:58
Please reverse the order. Pass tab_index then wind
sunandt
2010/12/07 23:47:45
Done.
| |
| 47 def GoogleAccountsLogin(test, url, username, password): | |
| 48 """Log into Google Accounts. | 46 """Log into Google Accounts. |
| 49 | 47 |
| 50 Attempts to login to Google by entering the username/password into the google | 48 Attempts to login to Google by entering the username/password into the google |
| 51 login page and click submit button. | 49 login page and click submit button. |
| 52 | 50 |
| 53 Args: | 51 Args: |
| 54 test: derived from pyauto.PyUITest - base class for UI test cases. | 52 test: derived from pyauto.PyUITest - base class for UI test cases. |
| 55 username: users login input. | 53 username: users login input. |
| 56 password: users login password input. | 54 password: users login password input. |
| 57 """ | 55 """ |
| 58 test.NavigateToURL('https://www.google.com/accounts/') | 56 test.NavigateToURL(url, windex, tab_index) |
| 59 email_id = 'document.getElementById("Email").value = \"%s\"; ' \ | 57 email_id = 'document.getElementById("Email").value = "%s"; ' \ |
| 60 'window.domAutomationController.send("done")' % username | 58 'window.domAutomationController.send("done")' % username |
| 61 password = 'document.getElementById("Passwd").value = \"%s\"; ' \ | 59 password = 'document.getElementById("Passwd").value = "%s"; ' \ |
| 62 'window.domAutomationController.send("done")' % password | 60 'window.domAutomationController.send("done")' % password |
| 63 test.ExecuteJavascript(email_id); | 61 test.ExecuteJavascript(email_id, windex, tab_index); |
| 64 test.ExecuteJavascript(password); | 62 test.ExecuteJavascript(password, windex, tab_index); |
| 65 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' | 63 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' |
| 66 'window.domAutomationController.send("done")') | 64 'window.domAutomationController.send("done")', |
| 65 windex, tab_index) | |
| 67 | 66 |
| 68 | 67 def VerifyGoogleAccountCredsFilled(test, username, password, windex=0, |
|
Nirnimesh
2010/11/29 22:42:58
same here
sunandt
2010/12/07 23:47:45
Done.
| |
| 69 def VerifyGoogleAccountCredsFilled(test, username, password): | 68 tab_index=0): |
| 70 """Verify stored/saved user and password values to the values in the field. | 69 """Verify stored/saved user and password values to the values in the field. |
| 71 | 70 |
| 72 Args: | 71 Args: |
| 73 test: derived from pyauto.PyUITest - base class for UI test cases. | 72 test: derived from pyauto.PyUITest - base class for UI test cases. |
| 74 username: user log in input. | 73 username: user log in input. |
| 75 password: user log in password input. | 74 password: user log in password input. |
| 76 """ | 75 """ |
| 77 email_value = test.GetDOMValue('document.getElementById("Email").value') | 76 email_value = test.GetDOMValue('document.getElementById("Email").value', |
| 78 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value') | 77 windex, tab_index) |
| 78 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value', | |
| 79 windex, tab_index) | |
| 79 test.assertEqual(email_value, username) | 80 test.assertEqual(email_value, username) |
| 80 test.assertEqual(passwd_value, password) | 81 test.assertEqual(passwd_value, password) |
| 81 | 82 |
| 82 | |
| 83 def ClearPasswords(test): | 83 def ClearPasswords(test): |
| 84 """Clear saved passwords.""" | 84 """Clear saved passwords.""" |
| 85 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') | 85 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') |
| 86 | 86 |
| 87 | |
| 88 def Shell2(cmd_string, bg=False): | 87 def Shell2(cmd_string, bg=False): |
| 89 """Run a shell command. | 88 """Run a shell command. |
| 90 | 89 |
| 91 Args: | 90 Args: |
| 92 cmd_string: command to run | 91 cmd_string: command to run |
| 93 bg: should the process be run in background? Default: False | 92 bg: should the process be run in background? Default: False |
| 94 | 93 |
| 95 Returns: | 94 Returns: |
| 96 Output, return code | 95 Output, return code |
| 97 """ | 96 """ |
| 98 if not cmd_string: return ('', 0) | 97 if not cmd_string: return ('', 0) |
| 99 if bg: | 98 if bg: |
| 100 cmd_string += ' 1>/dev/null 2>&1 &' | 99 cmd_string += ' 1>/dev/null 2>&1 &' |
| 101 proc = os.popen(cmd_string) | 100 proc = os.popen(cmd_string) |
| 102 if bg: return ('Background process: %s' % cmd_string, 0) | 101 if bg: return ('Background process: %s' % cmd_string, 0) |
| 103 out = proc.read() | 102 out = proc.read() |
| 104 retcode = proc.close() | 103 retcode = proc.close() |
| 105 if not retcode: # Success | 104 if not retcode: # Success |
| 106 retcode = 0 | 105 retcode = 0 |
| 107 return (out, retcode) | 106 return (out, retcode) |
| 108 | 107 |
| 109 | |
| 110 def SendMail(send_from, send_to, subject, text, smtp, file_to_send=None): | 108 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. | 109 """Send mail to all the group to notify about the crash and uploaded data. |
| 112 | 110 |
| 113 Args: | 111 Args: |
| 114 send_from: from mail id. | 112 send_from: from mail id. |
| 115 send_to: to mail id. | 113 send_to: to mail id. |
| 116 subject: mail subject. | 114 subject: mail subject. |
| 117 text: mail body. | 115 text: mail body. |
| 118 smtp: The smtp to use. | 116 smtp: The smtp to use. |
| 119 file_to_send: attachments for the mail. | 117 file_to_send: attachments for the mail. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 130 if file_to_send is not None: | 128 if file_to_send is not None: |
| 131 part.set_payload(open(file_to_send,'rb').read()) | 129 part.set_payload(open(file_to_send,'rb').read()) |
| 132 email.Encoders.encode_base64(part) | 130 email.Encoders.encode_base64(part) |
| 133 part.add_header('Content-Disposition', | 131 part.add_header('Content-Disposition', |
| 134 'attachment; filename="%s"' | 132 'attachment; filename="%s"' |
| 135 % os.path.basename(file_to_send)) | 133 % os.path.basename(file_to_send)) |
| 136 msg.attach(part) | 134 msg.attach(part) |
| 137 smtp_obj = smtplib.SMTP(smtp) | 135 smtp_obj = smtplib.SMTP(smtp) |
| 138 smtp_obj.sendmail(send_from, send_to, msg.as_string()) | 136 smtp_obj.sendmail(send_from, send_to, msg.as_string()) |
| 139 smtp_obj.close() | 137 smtp_obj.close() |
| 140 | |
| OLD | NEW |