def test_003_Statistics(self): u'''统计:用户流量统计、应用流量统计、端口流量统计、VPN流量统计''' sysStatic1A = getAssertText('sysStatic1A') sysStatic2A = getAssertText('sysStatic2A') sysStatic3A = getAssertText('sysStatic3A') sysStatic4A = getAssertText('sysStatic4A') sysStatic5A = getAssertText('sysStatic5A') sysstatic = sysStaticPage(self.driver, self.url) sysstatic.click_systemWatch() time.sleep(0.5) sysstatic.click_sysStatic() time.sleep(1) tips1 = str(sysstatic.getText_byXpath(sysstatic.tips1)) self.assertEqual(tips1, sysStatic1A, msg='带宽 表名不一致') tips2 = str(sysstatic.getText_byXpath(sysstatic.tips2)) self.assertEqual(tips2, sysStatic2A, msg='系统负载 表名不一致') tips3 = str(sysstatic.getText_byXpath(sysstatic.tips3)) self.assertEqual(tips3, sysStatic3A, msg='今日应用流量排名 表名不一致') tips4 = str(sysstatic.getText_byXpath(sysstatic.tips4)) self.assertEqual(tips4, sysStatic4A, msg='今日用户网络流量排名 表名不一致') L2tpP = getParameter('L2tpP') pptpP = getParameter('pptpP') SupportL = getExcelValue(L2tpP) SupportP = getExcelValue(pptpP) ipsecP = getParameter('ipsecP') SupportI = getExcelValue(ipsecP) if (SupportL or SupportP or SupportI) == '√': logger.info(u'参数支持VPN') tips5 = str(sysstatic.getText_byXpath(sysstatic.tips5)) self.assertEqual(tips5, sysStatic5A, msg='VPN状态 表名不一致') self.driver.quit() logger.info('test_003_Statistics passed')
def test_002_AppPriority(self): u'''应用优先 模板''' RuleName = getAssertText('RuleName') RuleName2 = getAssertText('RuleName2') #进入流量管理-应用优先 appPriority = AppPriorityPage(self.driver, self.url) appPriority.click_TrafficManagement() time.sleep(0.5) appPriority.click_AppPriority() time.sleep(1) #选择办公优先 selappType = appPriority.selelement_byName(appPriority.appType) Select(selappType).select_by_value('exp0') time.sleep(1) appPriority.click_changeAppType() time.sleep(5) #验证 规则名称 中的第一项值是否是‘办公优先’,来判断是否应用正常 rule_name1 = appPriority.getText_byXpath(appPriority.list_name1) self.assertEqual(rule_name1, RuleName, msg='办公优先模板应用错误') # time.sleep(1) #选择娱乐优先 selappType = self.driver.find_element_by_name('appType') time.sleep(1) Select(selappType).select_by_value('exp1') time.sleep(1) appPriority.click_changeAppType() time.sleep(3) rule_name1 = appPriority.getText_byXpath(appPriority.list_name1) # print(rule_name1) self.assertEqual(rule_name1, RuleName2, msg='模板应用错误') logger.info('test_002_AppPriority passed')
def test_002_PortMirror(self): u'''端口镜像(某些设备可能不支持)''' Monitorport = getAssertText('Monitorport') Monitoredport = getAssertText('Monitoredport') portmirrorP = getParameter('portmirrorP') Support = getExcelValue(portmirrorP) switchconfig = switchConfigPage(self.driver, self.url) if Support == '√': try: self.driver.implicitly_wait(2) switchconfig.find_switchConfig() except NoSuchElementException: CapPic(self.driver) logger.info(u'不支持交换配置,则不支持端口镜像,与参数表不相符') raise Exception('不支持交换配置,则不支持端口镜像,与参数表不相符') else: time.sleep(1) try: switchconfig.find_portMirror() except NoSuchElementException: raise Exception('不支持端口镜像,与参数表不相符') else: logger.info(u'支持端口镜像,与参数表相符') MirrorEns = str( switchconfig.getAttribute_byXpath( switchConfigPage.MirrorEns, 'checked')) self.assertEqual(MirrorEns, 'true', msg='端口镜像 默认未关闭') line1 = str( switchconfig.getText_byXpath(switchconfig.Monitorport)) self.assertEqual(line1, Monitorport, msg='监控端口 名称不一致') line2 = str( switchconfig.getText_byXpath( switchconfig.Monitoredport)) self.assertEqual(line2, Monitoredport, msg='被监控端口 名称不一致') elif Support == '×': try: self.driver.implicitly_wait(2) switchconfig.find_switchConfig() except NoSuchElementException: logger.info('不支持交换配置,则不支持端口镜像,与参数表相符') else: time.sleep(1) try: switchconfig.find_portMirror() except NoSuchElementException: logger.info(u'不支持 端口镜像,与参数表相符') else: CapPic(self.driver) logger.info(u'软件支持端口镜像,与参数表不符') raise Exception(u'软件支持端口镜像,与参数表不符') else: logger.info(u'参数表读取异常') logger.info(u'参数表读取值为:', Support) raise Exception(u'参数表读取异常') self.driver.quit() logger.info('test_002_PortMirror passed')
def test_002_update(self): u'''固件升级''' UpgradeA = getAssertText('UpgradeA') SelectFileA = getAssertText('SelectFileA') software = MaintenancePage(self.driver, self.url) handOnChange = str(software.getText_byID(software.handOnChange1)) update = str(software.getText_byID(software.update1)) self.assertEqual(handOnChange, SelectFileA, msg='选择文件 按钮有误') self.assertEqual(update, UpgradeA, msg='升级 按钮有误') self.driver.quit() logger.info('test_002_update passed')
def test_008_license(self): u'''电子授权(某些型号可能不支持)''' dayA = getAssertText('dayA') day2A = getAssertText('day2A') SelectFileA = getAssertText('SelectFileA') ImportA = getAssertText('ImportA') licenseP = getParameter('licenseP') Support = getExcelValue(licenseP) maintenance = MaintenancePage(self.driver, self.url) time.sleep(1) if Support == '√': try: self.driver.implicitly_wait(2) maintenance.click_license() time.sleep(1) except NoSuchElementException: CapPic(self.driver) logger.info(u'软件不支持电子授权,与参数表不相符') raise Exception('软件不支持电子授权,与参数表不相符') else: try: days1 = maintenance.getText_byXpath(maintenance.days1) self.assertIn(day2A, days1, msg='剩余时间 显示不为永久 ') except AssertionError: try: days = maintenance.getText_byXpath(maintenance.days2) self.assertIn(dayA, days, msg='剩余时间 显示不为 天数') except AssertionError: raise Exception('剩余时间不显示') chooseFile = str( maintenance.getText_byID(maintenance.chooseFile1)) innerput = str(maintenance.getText_byID(maintenance.innerput1)) self.assertEqual(chooseFile, SelectFileA, msg='选择文件 按钮有误') self.assertEqual(innerput, ImportA, msg='导入 按钮有误') elif Support == '×' or '--': try: self.driver.implicitly_wait(2) maintenance.click_license() except NoSuchElementException: logger.info('软件不支持电子授权,与参数表相符') else: CapPic(self.driver) logger.info(u'软件支持电子授权,与参数表不符') raise Exception(u'软件支持电子授权,与参数表不符') else: logger.info(u'参数表读取异常') logger.info(u'参数表读取值为:', Support) raise Exception(u'参数表读取异常') self.driver.quit() logger.info('test_008_license passed')
def test_001_AccountSettings(self): u'''账号设置:新建、删除、修改''' reachMaxA = getAssertText('reachMaxA') roleA = getAssertText('roleA') account = NetworkSharingPage(self.driver, self.url) #新建 n = 2 while n < 6: n += 1 if n < 6: account.click_add() time.sleep(1) account.input_username(n) account.input_passwd1(n) account.input_passwd2(n) authority = account.selelement_byName(account.authority) Select(authority).select_by_value('1') #0 读 1 读写 account.click_save() time.sleep(1) else: account.click_add() time.sleep(1) account.input_username(n) account.input_passwd1(n) account.input_passwd2(n) authority = account.selelement_byName(account.authority) Select(authority).select_by_value('0') # 0 读 1 读写 account.click_save() time.sleep(1) tips = str(account.getText_byClass(account.tips_show_in)) self.assertEqual(tips, reachMaxA, msg='最大账号为5个 验证失败') account.click_modal_hide() time.sleep(1) Acc3 = str(account.getText_byXpath(account.Acc3)) auth3 = str(account.getText_byXpath(account.auth3)) self.assertEqual(Acc3, '3', msg='新增账号失败') self.assertEqual(auth3, roleA, msg='新增账号权限失败') Acc4 = str(account.getText_byXpath(account.Acc4)) auth4 = str(account.getText_byXpath(account.auth4)) self.assertEqual(Acc4, '4', msg='新增账号名失败') self.assertEqual(auth4, roleA, msg='新增账号权限失败') Acc5 = str(account.getText_byXpath(account.Acc5)) auth5 = str(account.getText_byXpath(account.auth5)) self.assertEqual(Acc5, '5', msg='新增账号名失败') self.assertEqual(auth5, roleA, msg='新增账号权限失败') self.driver.quit() logger.info('test_001_AccountSettings passed')
def test_errorSoftware(self): u'''软件升级 - 验证错误型号''' errversion = getweb('errversion') updataWarnTips = getAssertText('updataWarnTips') errSoftware = (str(tmppath) + str(errversion) + '.bin') # 更新一个错误型号 验证无法升级 及提示信息 software = MaintenancePage(self.driver, self.url) #选择文件上传 self.driver.find_element_by_name('updatesoftware').send_keys( errSoftware) # software.input_updatesoftware(errSoftware) #定位不到 time.sleep(1) software.click_update() time.sleep(1) software.click_ok() time.sleep(2) # 断言提示信息内容正确:代表该项正常 pageTip = software.getText_byClass(software.pageTip_warn) if pageTip != updataWarnTips: CapPic(self.driver) logger.info(u"升级错误型号 提示信息异常") raise Exception('升级错误型号 提示信息异常') else: print('更新 错误型号版本 验证通过') self.driver.quit()
def test_003_delAccNumber(self): u'''认证账号 - 删除''' nodata = getAssertText('nodata') login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) pppoeauth = Organization_userAuthPage(self.driver, self.url) # 打开用户管理 - 用户认证 pppoeauth.click_UserManage() time.sleep(0.5) pppoeauth.click_userAuth() time.sleep(1) pppoeauth.click_account() time.sleep(1) pppoeauth.click_selAll() time.sleep(0.5) pppoeauth.click_deleteAll() time.sleep(1) pppoeauth.click_ok() time.sleep(1) list_tips=pppoeauth.getText_byXpath(pppoeauth.list_tips) self.assertEqual(str(list_tips),nodata,msg='账号删除失败') print('认证账号 - 账号删除 验证通过') self.driver.quit() organization_group.group_delete(self) # 删除组 logger.info('test_003_delAccNumber passed')
def tearDown(self): # 关闭行为管理,删除禁止策略 nodata = getAssertText('nodata') login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) actionManage = actionManagePage(self.driver, self.url) # 配置行为管理 actionManage.click_BehaviorManagement() time.sleep(0.5) actionManage.click_BehaviorManagement2() time.sleep(1) actionManage.click_checkOpen() time.sleep(1) checkOpenS = actionManage.getAttribute_byId( actionManage.checkOpens, 'checktype') # checktype 0未开启,1开启 self.assertEqual(checkOpenS, '0', msg='行为管理 未关闭') print('行为管理 已关闭') actionManage.click_delete() time.sleep(1) actionManage.click_ok() time.sleep(1) # 断言 listnodata = str(actionManage.getText_byXpath(actionManage.listnodata)) self.assertEqual(listnodata, nodata, msg='策略删除失败') print('策略已删除') self.driver.quit() logger.info('tearDown over') logger.info('%s' % ('=' * 50))
def test_001_information(self): u'''默认关闭,网络名称、设备管理页面提示正确''' wirelessTipsA = getAssertText('wirelessTipsA') netname = netNamePage(self.driver, self.url) #网络名称页面的提示 netname.click_netName() time.sleep(1) boxtips = netname.getText_byClass(netname.u_cfm_boxT) if wirelessTipsA not in boxtips: CapPic(self.driver) logger.info(u'网络名称页面 无线扩展提示有误') raise Exception('网络名称页面 无线扩展提示有误') netname.click_u_cfm_nox() #提示窗右上角×号 time.sleep(1) #确认按钮默认关闭 checkOpens = netname.getAttribute_byId(netname.checkOpens, 'checktype') self.assertEqual(checkOpens, '0', msg='无限扩展默认未关闭') #0关闭,1打开 # 设备管理页面的提示 device = deviceMgmtPage(self.driver, self.url) device.click_deviceMgmt() time.sleep(1) boxtips = netname.getText_byClass(netname.u_cfm_boxT) if wirelessTipsA not in boxtips: CapPic(self.driver) logger.info(u'设备管理页面 无线扩展提示有误') raise Exception('设备管理页面 无线扩展提示有误') device.click_no() #取消按钮 time.sleep(1) self.driver.quit() logger.info('test_001_information passed')
def test_001_test1(self): u'''添加管理员账号''' roleA = getAssertText('roleA') # 添加管理员账号test/test,读写权限 login.loginWeb(self) #admin账号登录 self.driver.implicitly_wait(10) administrator = ManagementPolicyPage(self.driver, self.url) #进入系统配置-网管策略-系统管理员 administrator.click_sysConfig() time.sleep(0.5) administrator.click_ManagementPolicy() time.sleep(1) # 添加管理员账号test/test administrator.click_add() time.sleep(1) administrator.input_username('test') administrator.input_passwd1('test') administrator.input_passwd2('test') #设置权限变量,选择 读写 权限 selrole = administrator.selelement_byName(administrator.role) Select(selrole).select_by_value('adm') administrator.click_save() time.sleep(1) # 断言 再点击编辑 确认元素不为空(账号确实是test):代表账号确实是test list_name1 = administrator.getText_byXpath(administrator.list_name1) list_role1 = administrator.getText_byXpath(administrator.list_role1) self.assertEqual(list_name1, 'test', msg='新建账号不为test') self.assertEqual(list_role1, roleA, msg='新建账号权限不为读写') #注销当前登录 login.logoutWeb(self) time.sleep(1) self.driver.quit()
def test_003_test3(self): u'''已删除账号验证 只读权限验证''' pageTipWarnA = getAssertText('pageTipWarnA') #使用test账号不能登陆管理DUT login.test_unableLoginWeb(self, username='******', password='******') self.driver.implicitly_wait(10) self.driver.quit() #使用test1账号可以登陆管理DUT login.test_enableLoginWeb(self, username='******', password='******') self.driver.implicitly_wait(10) # 只读权限test1 尝试删除test1/test1账号,应该不成功 administrator = ManagementPolicyPage(self.driver, self.url) administrator.click_sysConfig() time.sleep(0.5) administrator.click_ManagementPolicy() time.sleep(1) #尝试删除test1/test1账号,应该不成功 administrator.click_listDelete1() time.sleep(1) administrator.click_ok() time.sleep(1) # 断言删除时候提示信息(logout_span)元素不为空:代表无法删除 pageTip_warn = administrator.getText_byClass( administrator.pageTip_warn) if pageTip_warn != pageTipWarnA: CapPic(self.driver) logger.info(u'只读权限删除提示有误') raise Exception('只读权限删除提示有误') else: print('已删除账号验证、只读权限验证 通过') self.driver.quit()
def test_reboot1(self): u'''重启 - 页面上方''' WillReboottips = getAssertText('WillReboottips') login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) reboot = MaintenancePage(self.driver, self.url) reboot.click_headerReboot() time.sleep(0.5) reboot.click_ok() time.sleep(2) tips = str(reboot.getText_byClass(reboot.u_tim_str)) self.assertEqual(tips, WillReboottips, msg='点击页面上方重启 操作失败') #设备重启时间不一致,做个判断 time.sleep(30) i = 0 while i < 20: now_url = str(self.driver.current_url) # print(now_url,i) if '/noAuth/login.html' not in now_url: # 如果不同 time.sleep(5) else: break i += 1 else: raise Exception('设备重启未正常启动') self.driver.quit() #待重启后验证 登录是否正常 login.loginWeb(self) #admin账号登录 time.sleep(1) self.driver.quit() logger.info('test_reboot1 passed')
def tearDown(self): nodata = getAssertText('nodata') # 关闭防火墙,删除禁止策略 login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) firewall = AccessControlPage(self.driver, self.url) firewall.click_FireWall() time.sleep(0.5) firewall.click_AccessControl() time.sleep(1) firewall.click_checkTraffic() time.sleep(1) checkTrafficS = firewall.getAttribute_byId( firewall.checkTrafficS, 'checktype') # checktype 0未开启,1开启 self.assertEqual(checkTrafficS, '0', msg='访问控制 未关闭') print('访问控制策略 已关闭') firewall.click_delete() time.sleep(1) firewall.click_ok() time.sleep(1) # 断言 listnodata = str(firewall.getText_byXpath(firewall.listnodata)) self.assertEqual(listnodata, nodata, msg='策略删除失败') print('策略已删除') self.driver.quit() logger.info('tearDown over') logger.info('%s' % ('=' * 50))
def test_003_AppLibrary(self): u'''应用特征库升级''' AppUpgradeP = getParameter('AppUpgradeP') Support = getExcelValue(AppUpgradeP) policyVerA = getAssertText('policyVerA') priorityTempA = getAssertText('priorityTempA') versionsA = getAssertText('versionsA') policylib = MaintenancePage(self.driver, self.url) if Support == '√': logger.info(u'参数支持应用特征库升级') try: self.driver.implicitly_wait(2) policylib.click_policylib() except NoSuchElementException: CapPic(self.driver) logger.info(u'不支持应用特征库升级,与参数表不相符') raise Exception('不支持应用特征库升级,与参数表不相符') else: time.sleep(1) self.driver.implicitly_wait(10) policyVer1 = str( policylib.getText_byXpath(policylib.policyVer1)) priorityTemp1 = str( policylib.getText_byXpath(policylib.priorityTemp1)) versions1 = str(policylib.getText_byXpath(policylib.versions1)) self.assertEqual(policyVer1, policyVerA, msg='应用策略库版本 按钮有误') self.assertEqual(priorityTemp1, priorityTempA, msg='应用优先模板版本 按钮有误') self.assertEqual(versions1, versionsA, msg='版本状态 按钮有误') elif Support == '×': logger.info(u'参数不支持应用特征库升级') try: self.driver.implicitly_wait(2) policylib.click_policylib() except AttributeError: logger.info('不支持应用特征库升级,与参数表相符') else: CapPic(self.driver) logger.info(u'支持应用特征库升级,与参数表不相符') raise Exception('支持应用特征库升级,与参数表不相符') else: logger.info(u'参数表读取异常') logger.info(u'参数表读取值为:', Support) raise Exception(u'参数表读取异常') self.driver.quit() logger.info('test_003_AppLibrary passed')
def test_009_DiagnosticTest(self): u'''诊断测试''' pingsA = getAssertText('pingsA') MaxTTLA = getAssertText('MaxTTLA') tools = ToolsPage(self.driver, self.url) tools.click_Tools() time.sleep(1) ping = (tools.getText_byXpath(tools.ping)) self.assertEqual(ping, pingsA, 'ping页面按钮有误') tools.click_TraceRoute() time.sleep(1) maxTTL = (tools.getText_byXpath(tools.maxTTL1)) self.assertEqual(maxTTL, MaxTTLA, 'TraceRoute页面按钮有误') self.driver.quit() logger.info('test_009_DiagnosticTest passed')
def test_ElectronicsNotice(self): u'''电子通告:首次访问外网会接收到通告''' message = getAssertText('ElectronicsNotice') httptitle = getAssertText('httptitle') # 打开行为管理 - 电子通告 login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) electronicsNotice = ElectronicsNoticePage(self.driver,self.url) electronicsNotice.click_BehaviorManagement() time.sleep(0.5) electronicsNotice.click_ElectronicsNotice() time.sleep(1) #开启电子通告 electronicsNotice.input_rulename('EleNoticetest1') electronicsNotice.click_swEn() electronicsNotice.click_save() time.sleep(1) # 断言 提示信息是否有误 time.sleep(1) status = str(electronicsNotice.getAttribute_byXpath(electronicsNotice.swEs,'checked')) time.sleep(1) print(status) self.assertEqual(status,'true',msg='电子通告开启出错') self.driver.quit() print('电子通告开启 成功') time.sleep(5) self.driver = webdriver.Chrome() # self.driver.maximize_window() self.driver.implicitly_wait(10) #打开网页测试 self.driver.get('http://' + httpWebUrl + '/') time.sleep(1) title1=self.driver.title print(title1) self.assertEqual(title1, message, msg='未跳转到 电子通告页面') time.sleep(1) self.driver.get('http://' + httpWebUrl + '/') time.sleep(1) title2 = self.driver.title print(title2) self.assertIn(httptitle,title2, msg='通告第二次未跳转到正确页面') self.driver.quit() logger.info('test_ElectronicsNotice passed')
def test_004_ElectronicsNotice(self): u'''电子通告''' nodata = getAssertText('nodata') electronicsNotice = ElectronicsNoticePage(self.driver, self.url) electronicsNotice.click_BehaviorManagement() time.sleep(0.5) electronicsNotice.click_ElectronicsNotice() time.sleep(1) status = str( electronicsNotice.getAttribute_byXpath(electronicsNotice.swCs, 'checked')) self.assertEqual(status, 'true', msg='电子通告 默认未关闭') electronicsNotice.input_rulename('test') electronicsNotice.click_swEn() electronicsNotice.input_remarks('test') electronicsNotice.click_edipage() time.sleep(1) electronicsNotice.click_NoticePageName() electronicsNotice.input_NoticePageNote('test') electronicsNotice.input_NoticePageTitle('test') electronicsNotice.input_SkipUrl('test') electronicsNotice.input_SkipTime('3') electronicsNotice.input_NoticeBody('test') electronicsNotice.click_modalhide() time.sleep(0.5) electronicsNotice.click_applyUser() time.sleep(1) electronicsNotice.click_usergroup() time.sleep(0.3) electronicsNotice.click_userip() time.sleep(0.3) electronicsNotice.click_userall() time.sleep(0.5) electronicsNotice.click_saveW1() time.sleep(1) seltime = electronicsNotice.selelement_byName( electronicsNotice.seltime) Select(seltime).select_by_value('TimePlan') time.sleep(0.5) print('电子通告 验证通过') # 删除时间计划 timePlan = timePlanPage(self.driver, self.url) timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) timePlan.click_delete() time.sleep(1) timePlan.click_ok() time.sleep(1) # 断言 listtips2 = str(timePlan.getText_byXpath(timePlan.listnodata)) self.assertEqual(listtips2, nodata, msg='时间计划删除失败') print('时间计划已删除') self.driver.quit() logger.info('test_004_ElectronicsNotice passed')
def test_001_language(self): #待后续调整,目前只有一个 u'''网管策略 语言管理''' languageA = getAssertText('languageA') language = ManagementPolicyPage(self.driver, self.url) #判断语言 显示 languageText = str(language.getText_byXpath(language.languageText)) self.assertEqual(languageText, languageA, msg='语言 显示字符异常') self.driver.quit() logger.info('test_001_language passed')
def tearDown(self): nodata = getAssertText('nodata') #删除ipsec login.loginWeb(self) self.driver.implicitly_wait(10) ipsec = IPsecPage(self.driver, self.url) ipsec.click_VPNConfig() time.sleep(0.5) ipsec.click_IPSec() time.sleep(1) ipsec.click_selall() time.sleep(0.2) ipsec.click_delall() time.sleep(1) ipsec.click_ok() time.sleep(2) list_nodata = ipsec.getText_byXpath(ipsec.list_nodata) if list_nodata == nodata: logger.info(u'R1 ipsec 已删除') else: CapPic(self.driver) logger.info(u'R1 ipsec删除失败') raise Exception(u'R1 ipsec删除失败') self.driver.quit() login.test_enableLoginWeb(self, url=vpnRouteUrl) ipsec = IPsecPage(self.driver, self.url) ipsec.click_VPNConfig() time.sleep(0.5) ipsec.click_IPSec() time.sleep(1) ipsec.click_selall() time.sleep(0.2) ipsec.click_delall() time.sleep(1) ipsec.click_ok() time.sleep(2) try: #VPN 路由器是中文简体,在测试其他语言版本时,删除的nodata会不一致 ipsec.find_list_nodataX() except NoSuchElementException: CapPic(self.driver) logger.info(u'R2 ipsec删除失败') raise Exception(u'R2 ipsec删除失败') else: logger.info(u'R2 ipsec 已删除') # list_nodata = ipsec.getText_byXpath(ipsec.list_nodata) # if list_nodata == nodata: # logger.info(u'R2 ipsec 已删除') # else: # CapPic(self.driver) # logger.info(u'R2 ipsec删除失败') # raise Exception(u'R2 ipsec删除失败') logger.info('tearDown over') logger.info('%s' % ('=' * 50))
def test_001_backup_resert(self): u'''配置备份及还原''' ExportA = getAssertText('ExportA') ImportA = getAssertText('ImportA') SelectFileA = getAssertText('SelectFileA') ResetA = getAssertText('ResetA') config = MaintenancePage(self.driver, self.url) config.click_configuration() time.sleep(1) output = str(config.getText_byID(config.output1)) chooseFile = str(config.getText_byID(config.chooseFile1)) innerput = str(config.getText_byID(config.innerput1)) restore = str(config.getText_byID(config.restore1)) self.assertEqual(output, ExportA, msg='导出 按钮有误') self.assertEqual(chooseFile, SelectFileA, msg='选择文件 按钮有误') self.assertEqual(innerput, ImportA, msg='导入 按钮有误') self.assertEqual(restore, ResetA, msg='恢复出厂设置 按钮有误') self.driver.quit() logger.info('test_001_backup_resert passed')
def test_003_LanMultiIP(self): u'''Lan口多IP''' reachMax3A = getAssertText('reachMax3A') User = getweb('User') Passwd = getweb('Passwd') lanpage = NetworkConfig_LANpage(self.driver, self.url) lanpage.click_NetworkConfig() time.sleep(0.5) lanpage.click_LANconfig() time.sleep(1) # 新增lan口 num = 1 while num < 5: num += 1 lanpage.click_add() time.sleep(1) lanpage.input_lanIpName('lan%s' % num) lanpage.input_lanIp('213.18.%s.1' % num) lanpage.click_save() if num < 5: time.sleep(5) i = 0 while i < 10: now_url = str(self.driver.current_url) if '/noAuth/login.html' not in now_url: time.sleep(2) else: break i += 1 print(now_url, i) self.driver.quit() login.loginWeb(self) self.driver.implicitly_wait(10) loginPage = LoginPage(self.driver, self.url) lanpage = NetworkConfig_LANpage(self.driver, self.url) lanpage.click_NetworkConfig() time.sleep(0.5) lanpage.click_LANconfig() time.sleep(1) elif num >= 5: time.sleep(1) tips = (lanpage.getText_byClass(lanpage.tipsshowin)) self.assertIn(reachMax3A, tips, msg='提示信息有误') print('lan口数量最大为4 验证通过') time.sleep(1) lanpage.click_modalhide() time.sleep(0.5) lanpage.click_allsel() time.sleep(0.2) lanpage.click_delete() time.sleep(1) lanpage.click_ok() time.sleep(15) #删除接口要等等 self.driver.quit() logger.info('test_003_LanMultiIP passed')
def test_002_systemAccount(self): u'''系统账号不能删除/不能修改账号名''' CannotdeleteA = getAssertText('CannotdeleteA') Cannotdelete2A = getAssertText('Cannotdelete2A') UnableChangeA = getAssertText('UnableChangeA') account = NetworkSharingPage(self.driver, self.url) #系统账号不能删除 account.click_listdel1() time.sleep(1) tips = str(account.getText_byClass(account.tips_show_in)) self.assertEqual(tips, CannotdeleteA, msg='admin账号不能删除 异常') account.click_listdel2() time.sleep(1) tips = str(account.getText_byClass(account.tips_show_in)) self.assertEqual(tips, Cannotdelete2A, msg='guest账号不能删除 异常') #系统账号名不能修改 account.click_listedit1() time.sleep(1) try: account.input_username('1') except InvalidElementStateException: print('admin账号不可修改 验证通过') account.click_modal_hide() time.sleep(1) else: raise Exception('admin账号可修改') account.click_listedit2() time.sleep(1) account.input_username('guest1') account.click_save() time.sleep(1) try: tips = str(account.getText_byClass(account.tips_show_in)) self.assertEqual(tips, UnableChangeA, msg='guest账号修改提示信息 异常') except NoSuchElementException: raise Exception('guest账号可修改') account.click_modal_hide() time.sleep(1) self.driver.quit() logger.info('test_002_systemAccount passed')
def del_config_xml(self): #删除配置文件路径中的 xml文件 config_xml = getAssertText('config_xml') config_xml3 = getAssertText('config_xml3') path_xml = os.path.dirname( os.path.abspath('.')) + '/tmp/' #配置文件存放(下载)路径 sys.path.append(r'%s' % path_xml) files_xml = os.listdir( r'%s' % path_xml) #os.listdir(path) 返回path指定的文件夹包含的文件或文件夹的名字的列表 for filename_xml in files_xml: portion_xml = os.path.splitext( filename_xml) #splitext()用于返回 文件名和扩展名 元组 # print(portion_xml) if config_xml in portion_xml[0]: #如果文件名包含"系统配置20" if portion_xml[1] == '.xml': #后缀是 .xml #重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下 filenamedir_xml = (r'%s' % path_xml) + filename_xml os.remove(filenamedir_xml) if config_xml3 in portion_xml[0]: #如果文件名包含"系统配置3333" if portion_xml[1] == '.xml': #后缀是 .xml #重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下 filenamedir_xml = (r'%s' % path_xml) + filename_xml os.remove(filenamedir_xml)
def del_apconfig_gz(self): #删除AP配置文件路径中的 gz文件 apconfig_gz = getAssertText('apconfig_gz') apconfig_gz3 = getAssertText('apconfig_gz3') path_gz = os.path.dirname( os.path.abspath('.')) + '/tmp/' #配置文件存放(下载)路径 sys.path.append(r'%s' % path_gz) files_gz = os.listdir( r'%s' % path_gz) #os.listdir(path) 返回path指定的文件夹包含的文件或文件夹的名字的列表 for filename_gz in files_gz: portion_gz = os.path.splitext( filename_gz) #splitext()用于返回 文件名和扩展名 元组 # print(portion_cvs) if apconfig_gz in portion_gz[0]: #如果文件名包含"apUpdateConf_20" if portion_gz[1] == '.gz': #后缀是 .gz #重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下 filenamedir_gz = (r'%s' % path_gz) + filename_gz os.remove(filenamedir_gz) if apconfig_gz3 in portion_gz[0]: #如果文件名包含"apUpdateConf3333" if portion_gz[1] == '.gz': #后缀是 .gz #重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下 filenamedir_gz = (r'%s' % path_gz) + filename_gz os.remove(filenamedir_gz)
def del_flowWatch_csv(self): #删除流量监控路径中的 csv文件 flowWatch_csv = getAssertText('flowWatch_csv') flowWatch_csv3 = getAssertText('flowWatch_csv3') path_cvs = os.path.dirname( os.path.abspath('.')) + '/tmp/' #配置文件存放(下载)路径 sys.path.append(r'%s' % path_cvs) files_cvs = os.listdir( r'%s' % path_cvs) #os.listdir(path) 返回path指定的文件夹包含的文件或文件夹的名字的列表 for filename_cvs in files_cvs: portion_cvs = os.path.splitext( filename_cvs) #splitext()用于返回 文件名和扩展名 元组 # print(portion_cvs) if flowWatch_csv in portion_cvs[0]: #如果文件名包含"流量监控20" if portion_cvs[1] == '.csv': #后缀是 .csv #重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下 filenamedir_cvs = (r'%s' % path_cvs) + filename_cvs os.remove(filenamedir_cvs) if flowWatch_csv3 in portion_cvs[0]: #如果文件名包含“流量监控3333” if portion_cvs[1] == '.csv': #后缀是 .csv #重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下 filenamedir_cvs = (r'%s' % path_cvs) + filename_cvs os.remove(filenamedir_cvs)
def test_001_ntpClockServer(self): u'''时钟管理''' ntpServer = getweb('ntpServer') i = 0 while i < 80: p = pingTestIP('www.baidu.com') if p != 'Y': time.sleep(1) else: break login.loginWeb(self) self.driver.implicitly_wait(10) config = MaintenancePage(self.driver, self.url) # 进入系统配置-系统维护 config.click_sysConfig() time.sleep(0.5) config.click_Maintenance() time.sleep(1) TimeInternetA = getAssertText('TimeInternetA') sysTime = sysTimePage(self.driver, self.url) sysTime.click_SystemTime() time.sleep(1) switch = str(sysTime.getAttribute_byXpath(sysTime.SntpEns, 'checked')) tips = str(sysTime.getText_byXpath(sysTime.withInternet1)) self.assertEqual(switch, 'true', msg='网络时间同步 默认开启 有误') self.assertEqual(tips, TimeInternetA, msg='网络时间同步 按钮有误') #判断页面时间 日期 dates = sysTime.getText_byID(sysTime.dates) now = time.strftime("%Y-%m-%d") if dates != now: #判断默认配置下是否能同步 不同同步则更改ntp server使同步 同时报默认不能同步错 sysTime.input_NTPServerIP(ntpServer) sysTime.click_save() time.sleep(2) i = 0 while i < 20: sysTime.click_SystemTime() time.sleep(1) dates = sysTime.getText_byID(sysTime.dates) if dates == now: break else: i += 1 else: raise Exception('时间不同步,输入新ntp sever依旧不能更新') raise Exception('默认配置下ntp 时间不同步') self.driver.quit() logger.info('test_001_ntpClockServer passed')
def test_001_addWebAccNumber(self): u'''认证账号 - web账号''' AccountingType = getAssertText('AccountingType') organization_group.import_empty_template(self) # 判断组织架构是否有其他组 有则清空 # 调用新增组 “SelfComputerTest” organization_group.group_add(self) # 新增web认证账号 login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) webauth = Organization_userAuthPage(self.driver, self.url) # 打开用户管理 - 用户认证 webauth.click_UserManage() time.sleep(0.5) webauth.click_userAuth() time.sleep(1) webauth.click_account() time.sleep(1) webauth.click_addUser() time.sleep(1) webauth.input_name('webtest1') # 仅有一个用户组,这里省略 select = webauth.selelement_byName(webauth.authType) Select(select).select_by_value('Web') time.sleep(1) webauth.input_authAccount('webtest1') webauth.input_authPassword('webtest1') webauth.click_save() time.sleep(2) # 断言 添加的账号 认证方式和认证账号 是否正常 list_authtype = webauth.getText_byXpath(webauth.list_authtype) list_authAcc = webauth.getText_byXpath(webauth.list_authAcc) self.assertEqual(str(list_authtype), 'Web', msg='认证方式显示不为“Web”') self.assertEqual(str(list_authAcc), 'webtest1', msg='认证账号不为“webtest1”') print('认证账号 - 新增web账号 验证成功') # 修改web账号的计费方式为日期计费 time.sleep(1) webauth.click_listedit1() time.sleep(1) webauth.click_accountBillEn() time.sleep(0.5) webauth.click_save() time.sleep(1) # 断言 编辑的账号 计费方式是否已开启 list_AccountingType = str(webauth.getText_byXpath(webauth.list_AccountingType)) self.assertEqual(list_AccountingType, AccountingType, msg='web认证账号 修改成功') self.driver.quit() logger.info('test_001_addWebAccNumber passed')
def test_005_dnsProxy(self): u'''dns代理可以上网''' baidutitle = getAssertText('baidutitle') # 开dns代理 login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) dhcpserver = DHCPserverpage(self.driver, self.url) dhcpserver.click_NetworkConfig() time.sleep(0.5) dhcpserver.click_DHCPserver() time.sleep(1) dhcpserver.click_GlobalConfig() time.sleep(1) dhcpserver.click_dnspEn() dhcpserver.click_save() time.sleep(1) # 断言 开启提示信息是否有误 tips = str(dhcpserver.getText_byClass(dhcpserver.tips)) time.sleep(1) self.assertEqual(tips, saveSucess, msg='"DNS代理" 开启出错') print('DNS代理 已开启') # 将IP改回自动获取(设置dns为自动获取) # 调用bat脚本 os.system(('%s' % batpath + 'changeDhcpIp.bat')) time.sleep(5) n = 0 while n < 30: # 获取本机ip 默认有线地址,有线断开会显示无线 pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname())) print(pcaddr, n) if '192.168.' not in str(pcaddr): time.sleep(2) n += 1 else: print('IP地址已自动获取成功', n) break else: raise Exception('未获取到地址') pingTestIP('www.baidu.com') #避免失误 self.driver.get('http://www.baidu.com') time.sleep(2) title3 = self.driver.title print(title3) self.assertEqual(title3, baidutitle, msg='dns代理 无法打开网页') self.driver.quit() logger.info('test_005_dnsProxy passed')
def test_001_open(self): u'''开启即插即用 错误的IP,依旧上网''' plug = NetworkConfig_LANpage(self.driver, self.url) saveSucess = getAssertText('saveSucess') #开启UPNP plug.click_upnpEN() time.sleep(0.5) plug.click_save() time.sleep(1) # 断言 开启提示信息是否有误 tips = str(plug.getText_byClass(plug.tips)) time.sleep(1) self.assertEqual(tips, saveSucess, msg='即插即用 开启出错') print('即插即用 已开启') # 判断联网 ,不能上网则报错 pingTestIP('www.163.com') # 避免失误 p = pingTestIP('www.163.com') if p == 'N': raise Exception('connect failed.') # 调用bat脚本 地址修改为 192.168.189.39 网关192.168.189.1 os.system('%s' % (batpath + 'changeStaticIP.bat')) time.sleep(5) n = 0 while n < 30: # 获取本机ip 默认有线地址,有线断开会显示无线 pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname())) print(pcaddr, n) if str(pcaddr) != '192.168.198.39': time.sleep(2) n += 1 else: print('地址已修改为地址 192.168.198.39', n) break else: raise Exception('地址修改为192.168.198.39 失败') # 判断联网 ,不能上网则报错 pingTestIP('www.163.com') # 避免失误 p = pingTestIP('www.163.com') if p == 'N': raise Exception('connect failed.') self.driver.quit() logger.info('test_001_open passed')