1# Copyright (c) 2012 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 5import logging 6 7import ap_spec 8import netgear_WNDR_dual_band_configurator 9 10 11class NetgearR6200APConfigurator(netgear_WNDR_dual_band_configurator. 12 NetgearDualBandAPConfigurator): 13 """Derived class to control Netgear R6200 router.""" 14 15 16 def _alert_handler(self, alert): 17 """Checks for any modal dialogs which popup to alert the user and 18 either raises a RuntimeError or ignores the alert. 19 20 @param alert: The modal dialog's contents. 21 """ 22 text = alert.text 23 if 'WPS requires SSID broadcasting in order to work' in text: 24 alert.accept() 25 else: 26 super(NetgearR6200APConfigurator, self)._alert_handler(alert) 27 28 29 def navigate_to_page(self, page_number): 30 """Navigates to the default page. 31 32 @param page_number: The page to load. 33 """ 34 super(NetgearR6200APConfigurator, self).navigate_to_page(page_number) 35 self.set_wait_time(30) 36 self.wait.until(lambda _: 37 self.driver.execute_script('return document.readyState') 38 == 'complete') 39 self.restore_default_wait_time() 40 xpath = '//select[@name="opmode"]' 41 if not self.item_in_popup_by_xpath_exist('Up to 54 Mbps', xpath): 42 raise RuntimeError('Router webpage did not load completely.') 43 44 45 def get_supported_modes(self): 46 return [{'band': ap_spec.BAND_2GHZ, 47 'modes': [ap_spec.MODE_B, ap_spec.MODE_G, ap_spec.MODE_N]}, 48 {'band': ap_spec.BAND_5GHZ, 49 'modes': [ap_spec.MODE_A, ap_spec.MODE_N, 50 ap_spec.MODE_AC]}] 51 52 53 def get_supported_bands(self): 54 return [{'band': ap_spec.BAND_2GHZ, 55 'channels': ['Auto', 1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, 11]}, 56 {'band': ap_spec.BAND_5GHZ, 57 'channels': [36, 40, 44, 48, 149, 153, 157, 161]}] 58 59 60 def is_security_mode_supported(self, security_mode): 61 """Returns if the passed in security mode is supported. 62 63 @param security_mode: a security mode that is defined in APSpec 64 """ 65 return security_mode in (ap_spec.SECURITY_TYPE_DISABLED, 66 ap_spec.SECURITY_TYPE_WPA2PSK, 67 ap_spec.SECURITY_TYPE_WEP) 68 69 70 def set_channel(self, channel): 71 self.add_item_to_command_list(self._set_channel, (channel,), 1, 900) 72 73 74 def _set_channel(self, channel): 75 position = self._get_channel_popup_position(channel) 76 channel_choices = ['Auto', '01', '02', '03', '04', '05', '06', '07', 77 '08', '09', '10', '11'] 78 xpath = '//select[@name="w_channel"]' 79 if self.current_band == ap_spec.BAND_5GHZ: 80 xpath = '//select[@name="w_channel_an"]' 81 channel_choices = ['36', '40', '44', '48', '149', '153', 82 '157', '161'] 83 self.select_item_from_popup_by_xpath(channel_choices[position], 84 xpath) 85 86 87 def _set_mode(self, mode, band=None): 88 router_mode = None 89 xpath = '//select[@name="opmode"]' 90 if self.current_band == ap_spec.BAND_2GHZ: 91 if mode == ap_spec.MODE_B: 92 router_mode = 'Up to 54 Mbps' 93 elif mode == ap_spec.MODE_G: 94 router_mode = 'Up to 145 Mbps' 95 elif mode == ap_spec.MODE_N: 96 router_mode = 'Up to 300 Mbps' 97 elif self.current_band == ap_spec.BAND_5GHZ: 98 xpath = '//select[@name="opmode_an"]' 99 if mode == ap_spec.MODE_A: 100 router_mode = 'Up to 173 Mbps' 101 elif mode == ap_spec.MODE_N: 102 router_mode = 'Up to 400 Mbps' 103 elif mode == ap_spec.MODE_AC: 104 router_mode = 'Up to 867 Mbps' 105 if not router_mode: 106 raise RuntimeError('You selected a mode that is not assigned ' 107 'to this router. Select either b, g or n ' 108 'for 2.4Ghz or either a, n, or ac for 5Ghz.') 109 self.wait_for_object_by_xpath(xpath, wait_time=10) 110 self.select_item_from_popup_by_xpath(router_mode, xpath) 111 112 113 def set_security_wep(self, key_value, authentication): 114 if self.current_band == ap_spec.BAND_5GHZ: 115 logging.debug('Cannot set WEP security for 5GHz band in Netgear ' 116 'R6200 router.') 117 return None 118 super(NetgearR6200APConfigurator, self).set_security_wep( 119 key_value, authentication) 120