1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import logging 6 7 import ap_spec 8 import belkinF9K_ap_configurator 9 from selenium.common.exceptions import TimeoutException as \ 10 SeleniumTimeoutException 11 12 13 class BelkinF5D7234APConfigurator( 14 belkinF9K_ap_configurator.BelkinF9KAPConfigurator): 15 """Class to configure Belkin F5D7234 router.""" 16 17 def __init__(self, ap_config): 18 super(BelkinF5D7234APConfigurator, self).__init__(ap_config) 19 self._dhcp_delay = 0 20 21 22 def save_page(self, page_number): 23 """Save changes and logout from the router. 24 25 @param page_number: the page number to save as an integer. 26 27 """ 28 xpath = '//input[@type="submit" and @value="Apply Changes"]' 29 self.click_button_by_xpath(xpath, alert_handler=self._security_alert) 30 self.set_wait_time(30) 31 try: 32 self.wait.until(lambda _:'setup.htm' in self.driver.title) 33 except SeleniumTimeoutException, e: 34 try: 35 self.wait_for_object_by_xpath(xpath, wait_time=10) 36 logging.info("There are no changes to save") 37 except: 38 dup = '//h1[contains(text(), "Duplicate Administrator")]' 39 if (self.driver.find_element_by_xpath(dup)): 40 logging.debug("We got a 'Duplicate Administrator' page " 41 "when we saved the changes.") 42 finally: 43 self.restore_default_wait_time() 44 45 46 def get_supported_modes(self): 47 return [{'band': ap_spec.BAND_2GHZ, 48 'modes': [ap_spec.MODE_G, ap_spec.MODE_B, 49 ap_spec.MODE_B | ap_spec.MODE_G]}] 50 51 52 def set_mode(self, mode): 53 self.add_item_to_command_list(self._set_mode, (mode,), 1, 900) 54 55 56 def _set_mode(self, mode): 57 mode_mapping = {ap_spec.MODE_G: '802.11g', 58 ap_spec.MODE_B: '802.11b', 59 ap_spec.MODE_B | ap_spec.MODE_G: '802.11b&802.11g'} 60 mode_name = mode_mapping.get(mode) 61 if not mode_name: 62 raise RuntimeError('The mode %d not supported by router %s. ', 63 hex(mode), self.name) 64 xpath = '//select[@name="wbr"]' 65 self.select_item_from_popup_by_xpath(mode_name, xpath, 66 wait_for_xpath=None, 67 alert_handler=self._security_alert) 68 69 70 def _set_security_wpapsk(self, security, shared_key, update_interval=None): 71 key_field = '//input[@name="wpa_key_pass"]' 72 psk = '//select[@name="authentication"]' 73 self.select_item_from_popup_by_xpath('WPA/WPA2-Personal (PSK)', 74 self.security_popup, 75 wait_for_xpath=key_field, 76 alert_handler=self._security_alert) 77 auth_type = 'WPA-PSK' 78 if security == ap_spec.SECURITY_TYPE_WPA2PSK: 79 auth_type = 'WPA2-PSK' 80 self.select_item_from_popup_by_xpath(auth_type, psk, 81 wait_for_xpath=key_field, 82 alert_handler=self._security_alert) 83 self.set_content_of_text_field_by_xpath(shared_key, key_field, 84 abort_check=True) 85