1# Copyright (c) 2014 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 6import linksyse2100_ap_configurator 7import ap_spec 8 9from selenium.common.exceptions import WebDriverException 10 11 12class LinksysWRT54GLAPConfigurator( 13 linksyse2100_ap_configurator.Linksyse2100APConfigurator): 14 """Base class for objects to configure Linksys WRT 54GL access points 15 using webdriver.""" 16 17 18 def get_supported_modes(self): 19 return [{'band': ap_spec.BAND_2GHZ, 20 'modes': [ap_spec.MODE_M, ap_spec.MODE_B, ap_spec.MODE_G]}] 21 22 23 def get_supported_bands(self): 24 return [{'band': ap_spec.BAND_2GHZ, 25 'channels': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]}] 26 27 28 def save_page(self, page_number): 29 submit_btn = '//a[@href="javascript:to_submit(document.forms[0])"]' 30 continue_btn = '//input[@value="Continue" and @onclick="to_submit()"]' 31 try: 32 self.click_button_by_xpath(submit_btn, 33 alert_handler=self._sec_alert) 34 self.wait_for_object_by_xpath(continue_btn, wait_time=10) 35 self.click_button_by_xpath(continue_btn, 36 alert_handler=self._sec_alert) 37 except WebDriverException, e: 38 self._check_for_alert_in_message(str(e), 39 alert_handler=self._sec_alert) 40 41 42 def _set_mode(self, mode, band=None): 43 mode_mapping = {ap_spec.MODE_M:'Mixed', ap_spec.MODE_G:'G-Only', 44 ap_spec.MODE_B:'B-Only', 'Disabled':'Disabled'} 45 mode_name = mode_mapping.get(mode) 46 if not mode_name: 47 raise RuntimeError('The mode %d not supported by router %s. ', 48 hex(mode), self.name) 49 xpath = '//select[@name="wl_net_mode"]' 50 self.select_item_from_popup_by_xpath(mode_name, xpath, 51 alert_handler=self._sec_alert) 52 53 54 55 def _set_channel(self, channel): 56 position = self._get_channel_popup_position(channel) 57 xpath = '//select[@name="wl_channel"]' 58 channels = ['1 - 2.412GHZ', '2 - 2.417GHZ', '3 - 2.422GHZ', 59 '4 - 2.427GHZ', '5 - 2.432GHZ', '6 - 2.437GHZ', 60 '7 - 2.442GHZ', '8 - 2.447GHZ', '9 - 2.452GHZ', 61 '10 - 2.457GHZ', '11 - 2.462GHZ'] 62 self.select_item_from_popup_by_xpath(channels[position], xpath) 63 64 65 def _set_security_wpapsk(self, security, shared_key, update_interval=None): 66 """Common method to set wpapsk and wpa2psk modes.""" 67 popup = '//select[@name="security_mode2"]' 68 self.wait_for_object_by_xpath(popup) 69 if security == ap_spec.SECURITY_TYPE_WPAPSK: 70 wpa_item = 'WPA Personal' 71 else: 72 wpa_item = 'WPA2 Personal' 73 self.select_item_from_popup_by_xpath(wpa_item, popup, 74 alert_handler=self._sec_alert) 75 text = '//input[@name="wl_wpa_psk"]' 76 self.set_content_of_text_field_by_xpath(shared_key, text, 77 abort_check=True) 78 interval = '//input[@name="wl_wpa_gtk_rekey"]' 79 if update_interval: 80 self.set_content_of_text_field_by_xpath(interval, update_interval, 81 abort_check=True) 82 83 84 def is_update_interval_supported(self): 85 """ 86 Returns True if setting the PSK refresh interval is supported. 87 88 @return True is supported; False otherwise 89 """ 90 return True 91