Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import time | |
| 2 from selenium import webdriver | |
| 3 from selenium.webdriver.chrome.options import Options | |
| 4 import xml.etree.ElementTree as ET | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please don't use ET, use the original name, to inc
rchtara
2014/05/14 11:58:04
Done.
| |
| 5 | |
| 6 from website import Website | |
| 7 | |
| 8 | |
| 9 class Environment: | |
| 10 | |
| 11 def __init__(self, passwords_file = ""): | |
|
vabr (Chromium)
2014/05/08 13:53:45
No spaces around "=" when defining default values.
rchtara
2014/05/14 11:58:04
Done.
| |
| 12 options = Options() | |
| 13 """Use random empty folder for profile, otherwise chromedriver is going to | |
| 14 create it's own where saving passwords is disabled. | |
| 15 """ | |
| 16 options.add_argument("enable-automatic-password-saving") | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please comment on why this is needed.
(I still kno
rchtara
2014/05/14 11:58:04
Done.
| |
| 17 #chrome path | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please separate # and the first word with a space.
rchtara
2014/05/14 11:58:04
Done.
| |
| 18 options.binary_location = ( | |
| 19 "/usr/local/google/home/rchtara/chrome/src/out/Debug/chrome") | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please do not hard-code your local path into the u
rchtara
2014/05/14 11:58:04
Done.
| |
| 20 #new profile path | |
| 21 options.add_argument("user-data-dir=/tmp/ChromePasswordManagerTestvvvvvv") | |
| 22 #chromedriver path | |
| 23 self.driver = webdriver.Chrome( | |
| 24 "/usr/local/google/home/rchtara/chrome/src/out/Debug/chromedriver", 0, | |
| 25 options) | |
| 26 self.internals_window = self.driver.current_window_handle | |
| 27 self.websitewindow = None | |
| 28 self.websites = [] | |
| 29 | |
| 30 self.passwords_tree = None | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please comment on what is the |passwords_tree|.
rchtara
2014/05/14 11:58:04
Done.
| |
| 31 if passwords_file != "": | |
| 32 self.passwords_tree = ET.parse(passwords_file).getroot() | |
| 33 | |
| 34 def AddWebsite(self, | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please add a docstring documenting this method,
an
| |
| 35 name, | |
| 36 username = None, | |
| 37 password = None, | |
| 38 username_not_auto=False): | |
| 39 website = ( | |
| 40 Website( | |
| 41 name, username, password, self.driver, self, username_not_auto)) | |
| 42 self.websites.append(website) | |
| 43 return website | |
| 44 | |
| 45 def RemoveAllPasswords(self, websites): | |
| 46 print "RemoveAllPasswords" | |
| 47 self.driver.get("chrome://settings/passwords") | |
| 48 self.driver.switch_to_frame("settings") | |
| 49 | |
| 50 for website in websites: | |
| 51 urls, _ = self.GetPasswordsAndButtons() | |
| 52 website.RemoveAllPasswords(urls) | |
| 53 | |
| 54 def GetPasswordsAndButtons(self): | |
| 55 arr = self.driver.find_elements_by_css_selector( | |
| 56 "#saved-passwords-list .deletable-item") | |
| 57 urls = [] | |
| 58 remove_buttons = [] | |
| 59 for entry in arr: | |
| 60 urls.append(entry.find_element_by_class_name("url").text) | |
| 61 remove_buttons.append( | |
| 62 entry.find_element_by_class_name("row-delete-button")) | |
| 63 return (urls, remove_buttons) | |
|
vabr (Chromium)
2014/05/08 13:53:45
Why do you bother with returning buttons, when you
rchtara
2014/05/14 11:58:04
Done.
| |
| 64 | |
| 65 def NewWindow(self): | |
| 66 if self.websitewindow == None: | |
| 67 self.driver.get("https://google.com") | |
| 68 | |
| 69 """It's not possible to open a new tab to chrome:// urls directly, | |
|
vabr (Chromium)
2014/05/08 13:53:45
Sorry, this sentence is hard to parse, and I actua
rchtara
2014/05/14 11:58:04
There is two issues here:
*There is no straightfor
| |
| 70 this why we go to google.com website then we go to chrome:// | |
| 71 sometime chromedriver doesn't detect that www.google.com is loaded | |
| 72 and the script just stops, this is why you should redo the | |
| 73 tests again. | |
| 74 """ | |
| 75 | |
| 76 a = self.driver.execute_script( | |
| 77 "var d=document; var " | |
| 78 "a=d.createElement('a');a.target='_blank';a.href=arguments[0];" | |
| 79 "a.innerHTML='.';d.body.appendChild(a);" | |
| 80 " return a;", | |
| 81 "https://google.com") | |
| 82 a.click() | |
| 83 time.sleep(1) | |
| 84 | |
| 85 self.websitewindow = self.driver.window_handles[-1] | |
| 86 | |
| 87 self.driver.switch_to_window(self.websitewindow) | |
| 88 | |
| 89 def TestList(self, websites): | |
| 90 self.RemoveAllPasswords(websites) | |
| 91 self.NewWindow() | |
| 92 for website in websites: | |
| 93 website.WrongLoginTest() | |
| 94 website.SuccessfulLoginTest() | |
| 95 website.SuccessfulLoginWithAutofilledPasswordTest() | |
| 96 | |
| 97 self.RemoveAllPasswords(websites) | |
| 98 for website in websites: | |
| 99 website.SuccessfulLoginAfterDeletionTest() | |
| 100 | |
| 101 def AllTests(self): | |
| 102 self.TestList(self.websites) | |
| 103 | |
| 104 def Test(self, tests): | |
| 105 websites = [] | |
| 106 for website in self.websites: | |
| 107 for test in tests: | |
|
vabr (Chromium)
2014/05/08 13:53:45
Use rather:
if website.name in tests:
websites.a
rchtara
2014/05/14 11:58:04
Done.
| |
| 108 if website.name == test: | |
| 109 websites.append(website) | |
| 110 self.TestList(websites) | |
| 111 | |
| 112 def Quit(self): | |
| 113 self.driver.quit() | |
| 114 | |
| 115 | |
| OLD | NEW |