def test_001_configbackup(self): u'''配置备份''' # 配置备份(因为chrome配置导出提示'损害计算机'问题,这里使用Firefox导出配置文件) # 先删除tmp路径中的xml文件 call_Firefox.del_config_xml(self) # 添加一个当天的时间计划配置 后面用于验证配置导出正确() call_Firefox.Firefox_login_web(self) self.driver.implicitly_wait(10) timePlan = timePlanPage(self.driver, self.url) timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) # 操作删除 以访已有规则 timePlan.click_selall() time.sleep(0.2) timePlan.click_delall() time.sleep(1) try: self.driver.implicitly_wait(2) timePlan.find_ok() except NoSuchElementException: try: timePlan.find_tipsshowin() time.sleep(1) except NoSuchElementException: pass else: time.sleep(1) print('时间计划列表已删除') # 创建时间计划 新增时间计划的名称 命令为当前年月 today = str(datetime.date.today())[:-3] # 获取当前年月(以访测试过程正好隔天,仅取年份月份) timePlan.click_add() time.sleep(1) timePlan.input_TimeRangeName(today) timePlan.click_save() time.sleep(1) # 断言 开启提示信息是否有误 list_name = str(timePlan.getText_byXpath(timePlan.listName)) time.sleep(1) self.assertEqual(list_name, today, msg='时间段名 与配置的不一致') print('时间计划已添加') # 开始进行配置备份 #进入系统配置-系统维护-配置管理 config = MaintenancePage(self.driver, self.url) config.click_sysConfig() time.sleep(0.5) config.click_Maintenance() time.sleep(1) config.click_configuration() time.sleep(1) config.click_output() time.sleep(2) self.driver.quit() logger.info('test_001_configbackup 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_002_Resert(self): u'''恢复出厂''' nodata = getAssertText('nodata') #用于恢复出厂并验证 login.loginWeb(self) #admin账号登录 self.driver.implicitly_wait(10) config = MaintenancePage(self.driver, self.url) #进入系统配置-系统维护-配置管理 config.click_sysConfig() time.sleep(0.5) config.click_Maintenance() time.sleep(1) config.click_configuration() time.sleep(1) config.click_restore() time.sleep(1) config.click_ok() time.sleep(1) config.click_ok() #确认重启 time.sleep(30) i = 0 while i < 30: 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账号登录 self.driver.implicitly_wait(10) timePlan = timePlanPage(self.driver, self.url) timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) list_nodata = timePlan.getText_byXpath(timePlan.listnodata) self.assertEqual(list_nodata, nodata, msg='配置恢复出厂成功') time.sleep(1) self.driver.quit() logger.info('test_002_Resert 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('策略已删除') # 删除时间计划 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() # 删除组织架构 organization_group.group_delete(self) print('组织架构 已删除') logger.info('tearDown over') logger.info('%s' % ('=' * 50))
def test_003_configIpmort(self): u'''导入配置''' nodata = getAssertText('nodata') config_xml = getAssertText('config_xml') config_xml3 = getAssertText('config_xml3') batpath = os.path.dirname(os.path.abspath('.')) + '/script/' #先进行配置文件命名修改 path = os.path.dirname(os.path.abspath('.')) + '/tmp/' # 配置文件存放(下载)路径 sys.path.append(r'%s' % path) files = os.listdir(r'%s' % path) #os.listdir(path) 返回path指定的文件夹包含的文件或文件夹的名字的列表 #通过文件名称判断 修改为指定的文件名 for filename in files: portion = os.path.splitext(filename) #splitext()用于返回 文件名和扩展名 元组 # print(portion2) if config_xml in str(portion[0]): #如果文件名种包含"系统配置20" if portion[1] == '.xml': #如果后缀是 .xml newname = config_xml3 + '.xml' #重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下 filenamedir = (r'%s' % path) + filename newnamedir = (r'%s' % path) + newname #修改文件名称(与autoIt上传脚本中上传的文件名称一致) os.rename(filenamedir, newnamedir) #导入配置 验证 login.loginWeb2(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) config.click_configuration() time.sleep(1) # 选中'选择文件' #这里没有取消"导入前恢复出厂设置"按钮 config.click_chooseFile() time.sleep(1) #调用autoIt脚本上传组的xml文件 if config_xml3 == '系统配置3333': autoItScript = batpath + 'SE_config_importCn.exe' if config_xml3 == 'Systemconfig3333': autoItScript = batpath + 'SE_config_importEn.exe' os.system('%s' % autoItScript) #点击导入 config.click_innerput() time.sleep(1) config.click_ok() time.sleep(2) #取消重启 config.click_no() time.sleep(1) #验证导入配置是否成功(通过配置的 今天时间计划) timePlan = timePlanPage(self.driver, self.url) timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) today = str(datetime.date.today())[:-3] # 获取当前年月(以访测试过程正好隔天,仅取年份月份) list_name = str(timePlan.getText_byXpath(timePlan.listName)) self.assertEqual(list_name, today, msg='配置导入失败') time.sleep(1) # 删除时间计划 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() # 删除tmp路径中的xml文件 call_Firefox.del_config_xml(self) logger.info('test_003_configIpmort passed')
def test_URLFilter(self): u'''URL过滤 www.163.com,控制IP段,生效时间内无法访问163,可以访问百度''' baidutitle = getAssertText('baidutitle') login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) timePlan = timePlanPage(self.driver, self.url) # 创建时间计划 为当天 timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) # 操作删除 以访已有规则 timePlan.click_selall() time.sleep(0.2) timePlan.click_delall() time.sleep(1) try: self.driver.implicitly_wait(2) timePlan.find_ok() except NoSuchElementException: try: timePlan.find_tipsshowin() time.sleep(1) except NoSuchElementException: pass else: time.sleep(1) print('时间计划列表已删除') timePlan.click_add() time.sleep(1) timePlan.input_TimeRangeName('TimePlan') timePlan.click_save() time.sleep(1) # 断言 开启提示信息是否有误 list_name = str(timePlan.getText_byXpath(timePlan.listName)) time.sleep(1) self.assertEqual(list_name, 'TimePlan', msg='时间段名 与配置的不一致') print('时间计划已添加') # 获取本机ip 默认有线地址,有线断开会显示无线 pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname())) #配置防火墙 firewall = AccessControlPage(self.driver, self.url) firewall.click_FireWall() time.sleep(0.5) firewall.click_AccessControl() time.sleep(1) firewall.click_add() time.sleep(1) firewall.input_PolicyNames('URLfilter') firewall.click_sourceIP() time.sleep(1) firewall.click_usergroup() time.sleep(1) # 选择IP段 用自身IP firewall.click_userip() time.sleep(1) firewall.input_starip(pcaddr) firewall.input_endip(pcaddr) firewall.click_saveW1() time.sleep(1) seltime = firewall.selelement_byName('timeGrpName') time.sleep(1) Select(seltime).select_by_value('TimePlan') selFilterTypes = firewall.selelement_byName(firewall.selFilterTypes) time.sleep(1) Select(selFilterTypes).select_by_value('2') #URL过滤 firewall.input_glnrUrl('www.163.com') firewall.click_save() time.sleep(1) # 开启访问控制 checkTrafficS = firewall.getAttribute_byId( firewall.checkTrafficS, 'checktype') # checktype 0未开启,1开启 if checkTrafficS == '0': firewall.click_checkTraffic() time.sleep(2) print('访问控制策略 已添加') #断言 list_content = str(firewall.getText_byXpath(firewall.list_Content)) self.assertEqual(list_content, 'www.163.com', msg='过滤内容不为"www.163.com"') checkTrafficS = firewall.getAttribute_byId( firewall.checkTrafficS, 'checktype') #checktype 0未开启,1开启 self.assertEqual(checkTrafficS, '1', msg='访问控制 未开启') self.driver.quit() # 访问官网,使用打不开网页的 title做断言 time.sleep(5) self.dr = webdriver.Chrome() # self.dr.maximize_window() self.dr.implicitly_wait(10) self.dr.set_page_load_timeout(10) # selenium超时设置/等待时间过长自动停止 # 清除浏览器cookies cookies = self.dr.get_cookies() print(f"main: cookies = {cookies}") self.dr.delete_all_cookies() # 因为被过滤,会打不开网站,,命令执行后会一直处于命令执行中,最后报超时错误,默认超时300s # selenium.common.exceptions.TimeoutException: Message: timeout # 配合上文 set_page_load_timeout(10)设置等待超时时间,这里等待10s,判断报超时错误则正常,否则失败 time.sleep(3) # 尝试访问百度 应可以 time.sleep(1) self.dr.get('http://www.baidu.com') title2 = self.dr.title print(title2) self.assertEqual(title2, baidutitle, msg='URL过滤开启后 不能打开其他网页') print('百度正常打开 验证成功') # 尝试访问163 应不可以 try: self.dr.get('http://www.163.com/') except TimeoutException: print('163禁止 验证成功') else: raise Exception('163禁止失败') self.dr.close() logger.info('test_URLFilter passed')
def test_002_filter(self): u'''ACL防火墙''' nodata = getAssertText('nodata') #创建时间计划 为当天 timePlan = timePlanPage(self.driver, self.url) timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) timePlan.click_add() time.sleep(1) timePlan.input_TimeRangeName('TimePlan') timePlan.click_save() time.sleep(1) list_name = str(timePlan.getText_byXpath(timePlan.listName)) time.sleep(1) self.assertEqual(list_name, 'TimePlan', msg='时间段名 与配置的不一致') print('时间计划已添加') # 配置防火墙 #新建一条IP过滤 firewall = AccessControlPage(self.driver, self.url) firewall.click_FireWall() time.sleep(0.5) firewall.click_AccessControl() time.sleep(1) firewall.click_add() time.sleep(1) firewall.input_PolicyNames('IPfilter') firewall.click_sourceIP() time.sleep(1) firewall.click_usergroup() time.sleep(0.5) firewall.click_userip() time.sleep(0.5) firewall.click_userall() time.sleep(0.5) firewall.click_saveW1() # 弹窗中的保存 time.sleep(1) seltime = firewall.selelement_byName('timeGrpName') time.sleep(1) Select(seltime).select_by_value('TimePlan') time.sleep(0.5) selFilterTypes = firewall.selelement_byName(firewall.selFilterTypes) Select(selFilterTypes).select_by_value('1') # ip过滤 time.sleep(0.5) selProtocol = firewall.selelement_byName(firewall.selProtocol) Select(selProtocol).select_by_value('4') #4 AH time.sleep(0.3) Select(selProtocol).select_by_value('5') #all time.sleep(0.3) Select(selProtocol).select_by_value('1') #ICMP time.sleep(0.3) Select(selProtocol).select_by_value('2') #TCP time.sleep(0.3) Select(selProtocol).select_by_value('3') #UDP time.sleep(0.5) selservice = firewall.selelement_byName('cyfw') Select(selservice).select_by_value('137') time.sleep(0.5) firewall.click_save() time.sleep(1) #新建一条URL firewall.click_add() time.sleep(1) firewall.input_PolicyNames('URLfilter') firewall.click_sourceIP() time.sleep(1) firewall.click_usergroup() time.sleep(0.5) firewall.click_userip() time.sleep(0.5) firewall.click_userall() time.sleep(0.5) firewall.click_saveW1() # 弹窗中的保存 time.sleep(1) seltime = firewall.selelement_byName('timeGrpName') Select(seltime).select_by_value('TimePlan') time.sleep(0.5) selFilterTypes = firewall.selelement_byName(firewall.selFilterTypes) Select(selFilterTypes).select_by_value('4') # DNS过滤 time.sleep(1) Select(selFilterTypes).select_by_value('3') # 关键字过滤 time.sleep(1) Select(selFilterTypes).select_by_value('2') # URL过滤 time.sleep(1) firewall.input_glnrUrl('www.123.com') time.sleep(1) firewall.click_save() time.sleep(1) print('访问控制策略 已添加') # 开/关访问控制 checkTrafficS = firewall.getAttribute_byId( firewall.checkTrafficS, 'checktype') # checktype 0未开启,1开启 self.assertEqual(checkTrafficS, '0', msg='访问控制 默认未关闭') if checkTrafficS == '0': firewall.click_checkTraffic() time.sleep(2) checkTrafficS = firewall.getAttribute_byId(firewall.checkTrafficS, 'checktype') self.assertEqual(checkTrafficS, '1', msg='访问控制 开启失败') if checkTrafficS == '1': firewall.click_checkTraffic() time.sleep(3) checkTrafficS = firewall.getAttribute_byId(firewall.checkTrafficS, 'checktype') self.assertEqual(checkTrafficS, '0', msg='访问控制 关闭失败') #测试移动策略 list1_name = str(firewall.getText_byXpath(firewall.list1_name)) self.assertEqual(list1_name, 'IPfilter', msg='访问控制列表 顺序1不为 IPfilter') selmoveto_1 = firewall.selelement_byID(firewall.u_moveto_1) Select(selmoveto_1).select_by_value('URLfilter') time.sleep(0.5) firewall.click_movetosave() time.sleep(1) i = 0 while i < 30: firewall.click_AccessControl() time.sleep(1) list1_name = str(firewall.getText_byXpath(firewall.list1_name)) if list1_name == 'URLfilter': print('访问控制列表 移动验证通过') break else: time.sleep(1) i += 1 else: raise Exception(u'访问控制列表 移动出错') #删除 firewall.click_selall() time.sleep(0.5) firewall.click_delall() time.sleep(1) firewall.click_ok() time.sleep(1) listnodata = str(firewall.getText_byXpath(firewall.listnodata)) self.assertEqual(listnodata, nodata, msg='策略删除失败') 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='时间计划删除失败') self.driver.quit() logger.info('test_002_filter passed')
def test_IPfilter(self): u'''IP地址过滤tcp80 控制组织架构成员,生效时间内无法访问http网页''' organization_group.import_empty_template(self) # 判断组织架构是否有其他组 有则清空 organization_group.add_user(self) #将自身IP增加到组织架构中 login.loginWeb(self) # admin账号登录 self.driver.implicitly_wait(10) timePlan = timePlanPage(self.driver, self.url) # 创建时间计划 为当天 timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) # 操作删除 以访已有规则 timePlan.click_selall() time.sleep(0.2) timePlan.click_delall() time.sleep(1) try: self.driver.implicitly_wait(2) timePlan.find_ok() except NoSuchElementException: try: timePlan.find_tipsshowin() time.sleep(1) except NoSuchElementException: pass else: time.sleep(1) print('时间计划列表已删除') timePlan.click_add() time.sleep(1) timePlan.input_TimeRangeName('TimePlan') timePlan.click_save() time.sleep(1) # 断言 开启提示信息是否有误 list_name = str(timePlan.getText_byXpath(timePlan.listName)) time.sleep(1) self.assertEqual(list_name, 'TimePlan', msg='时间段名 与配置的不一致') print('时间计划已添加') #配置防火墙 firewall = AccessControlPage(self.driver, self.url) firewall.click_FireWall() time.sleep(0.5) firewall.click_AccessControl() time.sleep(1) firewall.click_add() time.sleep(1) firewall.input_PolicyNames('IPfilter') firewall.click_sourceIP() time.sleep(1) firewall.click_usergroup() time.sleep(1) # 组织架构,这里选择的是ROOT 所有 firewall.click_Root() firewall.click_saveW1() time.sleep(1) seltime = firewall.selelement_byName('timeGrpName') time.sleep(1) Select(seltime).select_by_value('TimePlan') # #默认就是IP过滤、TCP 可省略 # FilterTypessel = self.driver.find_element_by_name('FilterTypes') # time.sleep(1) # Select(FilterTypessel).select_by_value('1') #IP过滤 # Protocol = self.driver.find_element_by_name('Protocol') # time.sleep(1) # Select(Protocol).select_by_value('2') #TCP selservice = firewall.selelement_byName('cyfw') time.sleep(1) Select(selservice).select_by_value('80') #80(web) firewall.click_save() time.sleep(1) firewall.click_checkTraffic() time.sleep(2) print('访问控制策略 已添加') #断言 list_dstport = str(firewall.getText_byXpath(firewall.list_dstport)) self.assertEqual(list_dstport, '80-80', msg='策略目的端口不为"80-80"') checkTrafficS = firewall.getAttribute_byId( firewall.checkTrafficS, 'checktype') #checktype 0未开启,1开启 self.assertEqual(checkTrafficS, '1', msg='访问控制 未开启') self.driver.quit() #访问官网,使用打不开网页的 title做断言 time.sleep(8) self.driver = webdriver.Chrome() # self.driver.maximize_window() self.driver.implicitly_wait(10) self.driver.get('http://' + httpWebUrl + '/') title = str(self.driver.title) # print(title) self.assertEqual(title, httpWebUrl, msg='TCP80 禁止失败') self.driver.quit() logger.info('test_IPfilter passed')
def test_001_SystemObject(self): u'''系统对象:时间计划、地址组''' # 创建时间计划 为当天 timePlan = timePlanPage(self.driver, self.url) timePlan.click_sysObj() time.sleep(0.5) timePlan.click_timePlan() time.sleep(1) #操作删除 以访已有规则 timePlan.click_selall() time.sleep(0.2) timePlan.click_delall() time.sleep(1) try: self.driver.implicitly_wait(2) timePlan.find_ok() except NoSuchElementException: try: timePlan.find_tipsshowin() time.sleep(1) except NoSuchElementException: pass else: time.sleep(1) print('时间计划列表已删除') timePlan.click_add() time.sleep(1) timePlan.input_TimeRangeName('TimePlan') timePlan.click_save() time.sleep(1) list_name = str(timePlan.getText_byXpath(timePlan.listName)) time.sleep(1) self.assertEqual(list_name, 'TimePlan', msg='时间段名 与配置的不一致') print('时间计划已添加') addressgroup = AddressGroupPage(self.driver, self.url) addressgroup.click_AddressGroup() time.sleep(1) addressgroup.click_add() time.sleep(1) addressgroup.input_name('test') time.sleep(1) addressgroup.click_addressTypeold() time.sleep(0.5) addressgroup.click_btn_tor() time.sleep(0.3) addressgroup.click_btn_tol() time.sleep(0.3) addressgroup.click_btn_delet() time.sleep(0.3) addressgroup.click_addressTypenew() time.sleep(0.5) addressgroup.input_startAddress('1.2.3.4') addressgroup.input_endAddress('1.2.3.5') addressgroup.click_btn_tol() time.sleep(0.3) addressgroup.click_btn_delet() time.sleep(0.3) addressgroup.click_btn_tor() time.sleep(0.3) print('地址组 验证通过') self.driver.quit() logger.info('test_001_SystemObject passed')