1fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish# Copyright (c) 2012 The Chromium Authors. All rights reserved. 2fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish# Use of this source code is governed by a BSD-style license that can be 3fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish# found in the LICENSE file. 4fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 5a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal"""Class to control the DlinkAP router.""" 6a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal 7fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambishimport os 8fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 994c3721324b55d312dc3087068ac4da454ef6c25Jason Abeleimport dynamic_ap_configurator 10d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambishimport ap_spec 118a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambishfrom selenium.common.exceptions import TimeoutException as \ 128a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish SeleniumTimeoutException 13fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 1494c3721324b55d312dc3087068ac4da454ef6c25Jason Abeleclass DLinkAPConfigurator( 1594c3721324b55d312dc3087068ac4da454ef6c25Jason Abele dynamic_ap_configurator.DynamicAPConfigurator): 16fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish """Derived class to control the DLink DAP-1522.""" 17fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 18fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _open_landing_page(self): 190d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.get_url('%s/index.php' % self.admin_interface_url, 200d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal page_title='D-Link Corporation') 21fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish page_name = os.path.basename(self.driver.current_url) 22fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if page_name == 'login.php' or page_name == 'index.php': 23fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish try: 24fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.wait_for_object_by_xpath('//*[@name="login"]') 258a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish except SeleniumTimeoutException, e: 26fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Maybe we were re-routed to the configuration page 27fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if (os.path.basename(self.driver.current_url) == 28fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 'bsc_wizard.php'): 29fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish return 308a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish raise SeleniumTimeoutException('Unable to navigate to the ' 318a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish 'login or configuration page. ' 328a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish 'WebDriver exception:%s', str(e)) 33fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish login_button = self.driver.find_element_by_xpath( 34fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish '//*[@name="login"]') 35fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish login_button.click() 36fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 370d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 38fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _open_configuration_page(self): 39fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._open_landing_page() 40fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if os.path.basename(self.driver.current_url) != 'bsc_wizard.php': 418a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish raise SeleniumTimeoutException('Taken to an unknown page %s' % 42fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish os.path.basename(self.driver.current_url)) 43fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 44fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Else we are being logged in automatically to the landing page 45fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wlan = '//*[@name="wlan_wireless"]' 46fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.wait_for_object_by_xpath(wlan) 47fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wlan_button = self.driver.find_element_by_xpath(wlan) 48fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wlan_button.click() 49fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Wait for the main configuration page, look for the radio button 50fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.wait_for_object_by_id('enable') 51fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 520d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 53fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def get_number_of_pages(self): 54fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish return 1 55fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 560d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 57fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def get_supported_bands(self): 58d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish return [{'band': ap_spec.BAND_2GHZ, 59fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 'channels': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]}, 60d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish {'band': ap_spec.BAND_5GHZ, 61fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 'channels': [26, 40, 44, 48, 149, 153, 157, 161, 165]}] 62fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 630d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 64fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def get_supported_modes(self): 65d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish return [{'band': ap_spec.BAND_2GHZ, 66d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish 'modes': [ap_spec.MODE_B, ap_spec.MODE_G, ap_spec.MODE_N, 67d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_B | ap_spec.MODE_G, 68d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_G | ap_spec.MODE_N]}, 69d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish {'band': ap_spec.BAND_5GHZ, 70d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish 'modes': [ap_spec.MODE_A, ap_spec.MODE_N, 71d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_A | ap_spec.MODE_N]}] 72fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 730d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 748a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish def is_security_mode_supported(self, security_mode): 75506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 76506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish Returns if a given security_type is supported. 77506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 78506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @param security_mode: one security modes defined in the APSpec 79506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 80506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @return True if the security mode is supported; False otherwise. 81506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 82506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 838a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish return security_mode in (self.security_disabled, 848a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish self.security_wpapsk, 858a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish self.security_wep) 868a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish 870d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 88fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def navigate_to_page(self, page_number): 89506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 90506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish Navigates to the page corresponding to the given page number. 91506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 92506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish This method performs the translation between a page number and a url to 93506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish load. This is used internally by apply_settings. 94506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 95506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @param page_number: page number of the page to load 96506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 97506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 98fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # All settings are on the same page, so we always open the config page 99fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._open_configuration_page() 100fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 1010d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 102fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def save_page(self, page_number): 103506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 104506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish Saves the given page. 105506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 106506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @param page_number: Page number of the page to save. 107506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 108506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 109fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # All settings are on the same page, we can ignore page_number 110fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish button = self.driver.find_element_by_xpath('//input[@name="apply"]') 111fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish button.click() 112fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # If we did not make changes we are sent to the continue screen. 113fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish continue_screen = True 114fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish button_xpath = '//input[@name="bt"]' 115fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish try: 116fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.wait_for_object_by_xpath(button_xpath) 117641bcd0ddecb0ad43783fcbf2304aa60502cadd7Jason Abele except SeleniumTimeoutException, e: 118fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish continue_screen = False 119fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if continue_screen: 120fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish button = self.driver.find_element_by_xpath(button_xpath) 121fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish button.click() 122fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # We will be returned to the landing page when complete 123fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.wait_for_object_by_id('enable') 124fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 1250d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 126fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_mode(self, mode, band=None): 127fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Mode overrides the band. So if a band change is made after a mode 128fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # change it may make an incompatible pairing. 129fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_mode, (mode, band), 1, 800) 130fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 1310d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 132fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_mode(self, mode, band=None): 133fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Create the mode to popup item mapping 134d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish mode_mapping = {ap_spec.MODE_B: '802.11b Only', 135d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_G: '802.11g Only', 136d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_N: '802.11n Only', 137d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_B | ap_spec.MODE_G: 'Mixed 802.11g and 802.11b', 138d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_N | ap_spec.MODE_G: 'Mixed 802.11n and 802.11g', 139d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_N | ap_spec.MODE_G | ap_spec.MODE_B: 140d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish 'Mixed 802.11n, 802.11g, and 802.11b', 141d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_N | ap_spec.MODE_G | ap_spec.MODE_B: 142d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish 'Mixed 802.11n, 802.11g, and 802.11b', 143d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_A: '802.11a Only', 144d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_N | ap_spec.MODE_A: 'Mixed 802.11n and 802.11a'} 145d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish band_value = ap_spec.BAND_2GHZ 146fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if mode in mode_mapping.keys(): 147fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish popup_value = mode_mapping[mode] 148fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # If the mode contains 802.11a we use 5Ghz 149d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if mode & ap_spec.MODE_A == ap_spec.MODE_A: 150d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish band_value = ap_spec.BAND_5GHZ 151fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # If the mode is 802.11n mixed with 802.11a it must be 5Ghz 152d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish elif (mode & (ap_spec.MODE_N | ap_spec.MODE_A) == 153d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish (ap_spec.MODE_N | ap_spec.MODE_A)): 154d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish band_value = ap_spec.BAND_5GHZ 155fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # If the mode is 802.11n mixed with other than 802.11a its 2Ghz 156d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish elif (mode & ap_spec.MODE_N == ap_spec.MODE_N and 157d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish mode ^ ap_spec.MODE_N > 0): 158d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish band_value = ap_spec.BAND_2GHZ 159fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # If the mode is 802.11n then default to 5Ghz unless there is a band 160d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish elif mode == ap_spec.MODE_N: 161d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish band_value = ap_spec.BAND_5GHZ 162fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if band: 163fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish band_value = band 164fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish else: 1658a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish raise SeleniumTimeoutException('The mode selected %s is not ' 1668a1d1683424252cf0e49f0e9161f7b64653bcd0aKris Rambish 'supported by router %s.' % 167b02e1744df2907cc4c0e7167cd8a52c43a73b155Jason Abele (hex(mode), self.name)) 168fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Set the band first 169fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_band(band_value) 170fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish popup_id = 'mode_80211_11g' 171d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if band_value == ap_spec.BAND_5GHZ: 172fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish popup_id = 'mode_80211_11a' 173fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.select_item_from_popup_by_id(popup_value, popup_id) 174fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 1750d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 176fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_radio(self, enabled=True): 177fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # If we are enabling we are activating all other UI components, do 178fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # it first. Otherwise we are turning everything off so do it last. 179fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if enabled: 180fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish weight = 1 181fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish else: 182fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish weight = 1000 183fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_radio, (enabled,), 1, weight) 184fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 1850d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 186fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_radio(self, enabled=True): 187fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # The radio checkbox for this router always has a value of 1. So we need 188fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # to use other methods to determine if the radio is on or not. Check if 189fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # the ssid textfield is disabled. 190fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish ssid = self.driver.find_element_by_xpath('//input[@name="ssid"]') 191fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if ssid.get_attribute('disabled') == 'true': 192fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish radio_enabled = False 193fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish else: 194fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish radio_enabled = True 195fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if radio_enabled == enabled: 196fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Nothing to do 197fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish return 198fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_check_box_selected_by_id('enable', selected=False, 199fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wait_for_xpath='id("security_type_ap")') 200fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2010d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 202fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_ssid(self, ssid): 203fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # Can be done as long as it is enabled 204fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_ssid, (ssid,), 1, 900) 205fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2060d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 207fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_ssid(self, ssid): 208fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_radio(enabled=True) 209fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_content_of_text_field_by_id(ssid, 'ssid') 210506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish self._ssid = ssid 211fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2120d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 213fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_channel(self, channel): 214fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_channel, (channel,), 1, 900) 215fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2160d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 217fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_channel(self, channel): 21800857090713b50f971e1a863e02c7d61812a483bKris Rambish position = self._get_channel_popup_position(channel) 219fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_radio(enabled=True) 220fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_check_box_selected_by_id('autochann', selected=False) 22100857090713b50f971e1a863e02c7d61812a483bKris Rambish self.select_item_from_popup_by_id(str(position), 'channel_g') 222fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2230d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 224fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def get_band(self): 225a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal """ 226a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal This is experimental 227a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal The radio buttons do more than run a script that adjusts the possible 228a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal channels. We will just check the channel to popup. 229a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal """ 230fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_radioSetting(enabled=True) 231fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish xpath = ('id("channel_g")') 232fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._open_configuration_page() 233fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.wait_for_object_by_xpath(xpath) 234fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish element = self.driver.find_element_by_xpath(xpath) 235fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish if element.find_elements_by_tag_name('option')[0].text == '1': 236d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish return ap_spec.BAND_2GHZ 237d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish return ap_spec.BAND_5GHZ 238fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2390d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 240fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_band(self, band): 241d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if band != ap_spec.BAND_2GHZ or band != ap_spec.BAND_5GHZ: 242fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish raise RuntimeError('Invalid band sent %s' % band) 243fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_band, (band,), 1, 900) 244fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2450d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 246fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_band(self, band): 247fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_radio(enabled=True) 248d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if band == ap_spec.BAND_2GHZ: 249fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish int_value = 0 250fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wait_for_id = 'mode_80211_11g' 251d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish elif band == ap_spec.BAND_5GHZ: 252fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish int_value = 1 253fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wait_for_id = 'mode_80211_11a' 254fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish xpath = ('//*[contains(@class, "l_tb")]/input[@value="%d" ' 255fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 'and @name="band"]' % int_value) 256fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish element = self.driver.find_element_by_xpath(xpath) 257fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish element.click() 258fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.wait_for_object_by_id(wait_for_id) 259fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2600d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 261fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_security_disabled(self): 262fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_security_disabled, (), 1, 900) 263fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2640d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 265fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_security_disabled(self): 266fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_radio(enabled=True) 2670d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal security_disabled = 'Disable Wireless Security (not recommended)' 2680d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.select_item_from_popup_by_id(security_disabled, 'security_type_ap') 2690d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 270fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 271fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_security_wep(self, key_value, authentication): 272fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_security_wep, 273fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish (key_value, authentication), 1, 900) 274fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2750d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 276fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_security_wep(self, key_value, authentication): 277fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_radio(enabled=True) 2780d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.select_item_from_popup_by_id('WEP', 'security_type_ap', 279fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wait_for_xpath='id("auth_type")') 280fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.select_item_from_popup_by_id(authentication, 'auth_type', 281fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wait_for_xpath='id("wep_key_value")') 282fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_content_of_text_field_by_id(key_value, 'wep_key_value') 283fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_content_of_text_field_by_id(key_value, 'verify_wep_key_value') 284fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2850d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 286fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_security_wpapsk(self, shared_key, update_interval=1800): 287fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_security_wpapsk, 288fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish (shared_key, update_interval), 1, 900) 289fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 2900d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 291fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_security_wpapsk(self, shared_key, update_interval=1800): 292fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_radio(enabled=True) 2930d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.select_item_from_popup_by_id('WPA-Personal', 294fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 'security_type_ap', 295fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wait_for_xpath='id("wpa_mode")') 296fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.select_item_from_popup_by_id('WPA Only', 'wpa_mode', 297fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish wait_for_xpath='id("grp_key_interval")') 298fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_content_of_text_field_by_id(str(update_interval), 299fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 'grp_key_interval') 300fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.set_content_of_text_field_by_id(shared_key, 'wpapsk1') 301fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 3020d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 303fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def set_visibility(self, visible=True): 304fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self.add_item_to_command_list(self._set_visibility, (visible,), 1, 900) 305fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 3060d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal 307fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish def _set_visibility(self, visible=True): 308fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish self._set_radio(enabled=True) 309fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish # value=0 is visible; value=1 is invisible 310fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish int_value = int(not visible) 311fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish xpath = ('//*[contains(@class, "l_tb")]/input[@value="%d" ' 312fd29bdabc21eeec6351550bd18476eaa9dd55cd8Kris Rambish 'and @name="visibility_status"]' % int_value) 3130d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.click_button_by_xpath(xpath) 314