class CLOUD(object): # TODO: # - based on reply from qa team, the access url should be full qualified # name or ip address base on auth conf. since the web server might not be # resolved in testing environment or against certain conf which may cause # problem when verifying traffic pass-through successfully or not. pre_url # is temporary solution which is used to trigger the auth process. for # example, pre_url in full qualified name to trigger auth process while # url in ip address to verify traffic. def __init__(self, url, title, pre_url=None): self.url = url self.title = title self.pre_url = pre_url if pre_url else url self.w = WebUI() self.mode = None self.popup = None def check_cloud_on(self, locator, displayed): for i in range(4): try: self.w.wait_until_element_displayed(displayed) break except Exception, e: self.w.warn('Fail to find element %s, before check %s, will try again' \ %(str(displayed), str(locator)), True) if i == 3: raise WebUIException('Fail to find element %s, before check %s' \ %(str(displayed), str(locator))) check_element = self.w.find_element(locator) if not check_element.is_selected(): check_element.click()
def hshao_login(): wui = WebUI() cloud = CLOUD(wui.d("visit.url"), wui.d("visit.title"), wui.d("visit.pre_url")) if wui.session_id is None: wui.info('trying to access %s before login' % wui.d("visit.url")) cloud.try_again_get(wui.d("visit.url"), LoginPage.get('login_page_title')) wui.wait_until_element_displayed(LoginPage.get('login_btn')) wui.input(LoginPage.get('username_txt'), wui.d("login.username")) wui.input(LoginPage.get('password_txt'), wui.d("login.password")) wui.info('handle login form', True) wui.click(LoginPage.get('login_btn')) try: wui.wait_until_title_present(LoginSuccessfulPage.get('login_successful_page_title'), info=True) wui.info('login success', True) except Exception, e: wui.s.execute_script('return window.onbeforeunload=null') wui.warn('Fail to get login_successful_page after login, will try again', True) wui.s.refresh() wui.wait_until_title_present(LoginSuccessfulPopupPage.get('login_successful_popup_page_title'), info=True) #---------------------------------is device connected ------------------------------------ wui.click(myHome.get('Devices_button')) wui.info('go to add device page', True) #ckeck if the device is connected and ap_sn = wui.d("device.ap_SN") click_hostname_devicepage(wui, ap_sn) connection_status_element = myHome.get('Device_connect_status') new_connection_status_element = wui.find_element(connection_status_element).text device_connection_status_str = "Connected" if device_connection_status_str == new_connection_status_element: wui.info('The device status on is Connected', True) else: wui.error('The device status is not Connected', True) wui.click(myHome.get('Devices_button')) wui.info('go to add device page', True) remove_device_devicepage(wui, ap_sn) wui.click(myHome.get('Conform_to_remove_device_button')) wui.info('confirm to remove device', True)
class HM(object): def __init__(self): self.w = WebUI() self.mode = None self.configer = Configuration() def admin_mode(self): self.mode = 'admin' def vhm_mode(self): self.mode = 'vhm' def is_admin_mode(self): return self.mode == 'admin' def is_vhm_mode(self): return self.mode == 'vhm' def _login(self, server, user, passwd): self.server = server self.user = user self.passwd = passwd self.w.info('trying to login %s as %s:%s' % (self.server, self.user, self.passwd)) self.w.get(self.server) self.w.wait_until_element_displayed(LoginPage.get('login_btn')) self.w.check_title(LoginPage.get('login_page_title'), 'check title after open') self.w.input(LoginPage.get('username_txt'), self.user) self.w.input(LoginPage.get('password_txt'), self.passwd) self.w.info('login', True) self.w.click(LoginPage.get('login_btn')) def login(self, server, user, passwd): self.admin_mode() self._login(server, user, passwd) self.w.wait_until_element_displayed(MainPage.get('monitor_lnk')) self.w.register_cleanup(self.logout) def login_by_vhm(self, server, vhm_user, vhm_passwd, hive_name=None, hive_mgt_passwd=None, quick_ssid_passwd=None): self.vhm_mode() self._login(server, vhm_user, vhm_passwd) def __tmp(w): return w.s.title != LoginPage.get('login_page_title') self.w.wait_until(__tmp, msg='login page navigated') if self.w.title == EULAPage.get('eula_page_title'): self.w.wait_until_element_displayed(EULAPage.get('agree_btn')) self.w.info('agree with EUAL', True) self.w.click(EULAPage.get('agree_btn')) self.w.wait_until_element_displayed(WelcomePage.get('continue_btn')) self.w.check_title(WelcomePage.get('welcome_page_title')) self.w.input(WelcomePage.get('hive_name_txt'), hive_name) self.w.input(WelcomePage.get('hive_mgt_passwd_txt'), hive_mgt_passwd) self.w.input(WelcomePage.get('hive_mgt_passwd_confirm_txt'), hive_mgt_passwd) self.w.check(WelcomePage.get('enterprise_mode_radio')) self.w.wait_until_element_displayed(WelcomePage.get('quick_ssid_passwd_txt')) self.w.input(WelcomePage.get('quick_ssid_passwd_txt'), quick_ssid_passwd) self.w.input(WelcomePage.get('quick_ssid_passwd_confirm_txt'), quick_ssid_passwd) self.w.info('handle initial configuration', True) self.w.click(WelcomePage.get('continue_btn')) self.w.check_title(MainPage.get('main_page_title'), 'check title after login') time.sleep(5) self.w.register_cleanup(self.logout) def to_hiveaps_table(self, type='all'): self.w.click(MainPage.get('monitor_lnk')) self.w.wait_until_title_present(HiveAPsPage.get('allAPs_page_title')) if type == 'all': self.w.click(HiveAPsPage.get('hive_aps_lnk')) self.w.wait_until_title_present(HiveAPsPage.get('hiveAPs_page_title')) self.w.click(HiveAPsPage.get('auto_refresh_off')) selecter = self.w.get_selecter(HiveAPsPage.get('device_per_page_sel')) if selecter.first_selected_option.text != '500': selecter.select_by_value('500') self.w.debug('after select page size', True) elif type == 'rogue': self.w.click(RogueAPsPage.get('rogue_aps_lnk')) self.w.wait_until_title_present(RogueAPsPage.get('rogueAPs_page_title')) selecter = self.w.get_selecter(RogueAPsPage.get('device_per_page_sel')) if selecter.first_selected_option.text != '500': selecter.select_by_value('500') def select_ap(self, text='', by='default'): if by == 'default': try: self.w.wait_until_element_displayed(APsTablePage.locate_checkbox(text)) except Exception, e: self.w.warn('Cannot find: %s' % text, True) checkbox_disabled = self.w.find_element(APsTablePage.locate_checkbox(text)).get_attribute('disabled') if checkbox_disabled == 'true': self.w.warn('not selectable AP: %s' % text, True) else: self.w.check(APsTablePage.locate_checkbox(text)) self.w.info('after select AP: %s' % text, True) elif by == 'linktext': try: self.w.wait_until_element_displayed(APsTablePage.locate_checkbox_by_linktext(text)) except Exception, e: self.w.warn('Cannot find: %s' % text, True)