def setUp(self):
     logger.info('setUp start')
     login.loginWeb(self)
     self.driver.implicitly_wait(10)
     userstatus = Organization_userStatusPage(self.driver, self.url)
     userstatus.click_UserManage()
     time.sleep(0.5)
Exemple #2
0
    def test_001_server3389(self):
        u'''验证下server 3389是否已打开'''

        # 通过用户状态获取httpserver的IP地址
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        status.input_search(serverPcMac)
        status.click_searchb()
        time.sleep(1)
        try:
            serverIP = status.getText_byXpath(status.list_IP1)
        except NoSuchElementException:
            raise Exception(u'用户状态中未找到server IP')
            # print(serverIP)
        else:
            try:
                telnetlib.Telnet(serverIP, port=3389, timeout=10)
            except socket.timeout:
                logger.info(u'内网方向无法访问server TCP3389端口')
                raise Exception(u'内网方向无法访问server TCP3389端口')
            else:
                print('server tcp3389端口已开启')
        self.driver.quit()
        logger.info('test_001_server3389 passed')
Exemple #3
0
    def test_002_MovetoOther(self):
        u'''用户 :移动到其他组'''
        organization_group.import_empty_template(self)  # 判断是否有组织架构,有则清空

        #新建组
        organization_group.group_add(self)

        #切回用户状态列表
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        # 打开用户管理 - 组织成员
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        #移动 列表中第一个 到 新建组'SelfComputerTest' 中
        #获取列表中第一个被移动的用户的IP
        list_IP1 = str(status.getText_byXpath(status.list_IP1))
        status.click_checkbox1()
        time.sleep(0.5)
        status.click_move()
        time.sleep(1)
        status.click_save()
        time.sleep(2)
        # 断言
        group = OrganizationMembersPage(self.driver, self.url)
        group.click_userGroup()
        time.sleep(1)
        group.click_list_groupName_c()
        time.sleep(2)
        listIP = str(group.getText_byXpath(group.listAddIP))
        self.assertEqual(listIP, list_IP1, msg='移动出错 IP不一致')
        authgroup = str(group.getText_byXpath(group.list_authgroup2))
        self.assertEqual(authgroup, 'SelfComputerTest', msg='移动出错 所属组 不一致')
        self.driver.quit()
        print('移动到其他组 验证成功')

        # 删除新建组'SelfComputerTest',使在线用户回到临时用户组
        time.sleep(1)
        organization_group.group_delete(self)
        logger.info('test_002_MovetoOther passed')
Exemple #4
0
    def test_001_userList(self):
        u'''用户状态 列表'''
        tempUser = getAssertText('tempUser')
        Minute = getAssertText('minute')
        Ban = getAssertText('Ban')
        #003中设置了ip/mac绑定上网,这里增加一个判断联网
        pingTestIP()  # 避免判断失误
        p = pingTestIP()
        if p == 'N':  # 如果不通
            # 1、改回DHCP, 调用bat脚本
            os.system('%s' % (batpath + 'changeDhcpIp.bat'))
            time.sleep(5)
            n = 0
            while n < 30:
                # 获取本机ip 默认有线地址,有线断开会显示无线
                pcaddr_new = socket.gethostbyname(
                    socket.getfqdn(socket.gethostname()))
                print(pcaddr_new, n)
                if '192.168.' not in str(pcaddr_new):
                    time.sleep(2)
                    n += 1
                else:
                    print('IP地址已自动获取成功', n)
                    break
            else:
                raise Exception('未获取到地址')
        pingTestIP('www.baidu.com')  #避免判断失误
        p = pingTestIP('www.baidu.com')
        if p == 'N':
            # 1、将mac改回, 调用bat脚本
            os.system('%s' % (batpath + 'changeMacToBack.bat'))
            time.sleep(5)
            n = 0
            while n < 30:
                # 获取本机ip 默认有线地址,有线断开会显示无线
                pcaddr_new = socket.gethostbyname(
                    socket.getfqdn(socket.gethostname()))
                print(pcaddr_new, n)
                if '192.168.' not in str(pcaddr_new):
                    time.sleep(2)
                    n += 1
                else:
                    print('IP地址已自动获取成功', n)
                    break
            else:
                # raise Exception('未获取到地址1')
                # 开启绑定情况下 仅更改mac 可能会获取不到地址
                os.system('%s' % (batpath + 'ipconfig_release.bat'))
                time.sleep(5)
                os.system('%s' % (batpath + 'ipconfig_renew.bat'))
                time.sleep(5)
                i = 0
                while i < 30:
                    # 获取本机ip 默认有线地址,有线断开会显示无线
                    pcaddr_new = socket.gethostbyname(
                        socket.getfqdn(socket.gethostname()))
                    print(pcaddr_new, i)
                    if '192.168.' not in str(pcaddr_new):
                        time.sleep(2)
                        i += 1
                    else:
                        print('IP地址已自动获取成功2', i)
                        break
                else:
                    raise Exception('未获取到地址2')
            #3、关闭"仅MAC绑定用户能上网" 关闭ip/mac绑定 以访003出错
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            group = OrganizationMembersPage(self.driver, self.url)
            # 打开用户管理 - 组织成员
            group.click_UserManage()
            time.sleep(0.5)
            group.click_userGroup()
            time.sleep(1)
            group = OrganizationMembersPage(self.driver, self.url)
            group.click_globalconfig()
            time.sleep(1)
            group.click_IPMACb_C()
            group.click_MACb_C()
            time.sleep(0.5)
            group.click_saveAllSetting()
            time.sleep(1)
            IPMACb_Cs = str(
                group.getAttribute_byXpath(group.IPMACb_Cs, 'checked'))
            self.assertEqual(IPMACb_Cs, 'true', msg='"仅IP/MAC绑定用户能上网" 关闭出错')
            print('"仅IP/MAC绑定用户能上网" 关闭')
            Macb_Cs = str(group.getAttribute_byXpath(group.MACb_Cs, 'checked'))
            self.assertEqual(Macb_Cs, 'true', msg='"仅MAC绑定用户能上网" 关闭出错')
            print('"仅MAC绑定用户能上网" 关闭')
            self.driver.quit()

        # 打开用户管理 - 用户状态
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        #定义页面显示元素变量
        ID = str(status.getText_byXpath(status.ID))
        username = str(status.getText_byXpath(status.username))
        group = str(status.getText_byXpath(status.group))
        VlanID = str(status.getText_byXpath(status.VlanID))
        IP = str(status.getText_byXpath(status.IP))
        mac = str(status.getText_byXpath(status.mac))
        authmode = str(status.getText_byXpath(status.authmode))
        online_time_length = str(
            status.getText_byXpath(status.online_time_length))
        Uploading_data = str(status.getText_byXpath(status.Uploading_data))
        Downing_data = str(status.getText_byXpath(status.Downing_data))
        Uploading_speed = str(status.getText_byXpath(status.Uploading_speed))
        Downing_speed = str(status.getText_byXpath(status.Downing_speed))
        edit = str(status.getText_byXpath(status.edit))

        # 断言 用户列表是否显示有误
        time.sleep(1)
        self.assertEqual(ID, '1', msg='ID出错')
        print('用户状态 - ID 验证成功')
        self.assertIsNotNone(username, msg='用户名 出错')
        print('用户状态 - 用户名 验证成功')
        self.assertEqual(group, tempUser,
                         msg='所属组 出错')  #脚本在最后会清空组织架构,所以脚本在一开始新建组,用户都是 临时用户
        print('用户状态 - 所属组 验证成功')
        self.assertIsNotNone(VlanID, msg='VLANID 出错')
        print('用户状态 - VLANID 验证成功')
        self.assertIn('192.168.', IP, msg='IP 出错')  #lan口地址段
        print('用户状态 - IP 验证成功')
        self.assertEqual(len(mac), 17, msg='mac 出错')  #判断mac地址长度
        print('用户状态 - mac 验证成功')
        self.assertIsNotNone(authmode, msg='认证方式 出错')
        print('用户状态 - 认证方式 验证成功')
        self.assertIn(Minute, online_time_length, msg='在线时长 出错')  # 在线时长是否包含“分”
        print('用户状态 - 在线时长 验证成功')
        self.assertIsNotNone(Uploading_data, msg='上传数据 出错')
        print('用户状态 - 上传数据 验证成功')
        self.assertIsNotNone(Downing_data, msg='下载数据 出错')
        print('用户状态 - 下载数据 验证成功')
        self.assertIsNotNone(Uploading_speed, msg='上传速度 出错')
        print('用户状态 - 上传速度 验证成功')
        self.assertIsNotNone(Downing_speed, msg='下载速度 出错')
        print('用户状态 - 下载速度 验证成功')
        self.assertEqual(edit, Ban, msg='拉黑菜单显示 出错')
        print('用户状态 - 拉黑菜单显示 验证成功')
        self.driver.quit()
        logger.info('test_001_userList passed')
Exemple #5
0
    def test_003_movetoBlicklist(self):
        u'''用户 :移动到黑名单'''
        nodata = getAssertText('nodata')
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        # 打开用户管理 - 组织成员
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)

        #需要设备下有另一个终端(至少两个终端),因为不能拉黑自己并且用户状态的用户是在线的(注意用户与lan口在同网段才会在线)
        # 获取本机ip 默认有线地址,有线断开会显示无线
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        #获取第一行第二行IP
        IP_line1 = str(status.getText_byXpath(status.list_IP1))
        IP_line2 = str(status.getText_byXpath(status.list_IP2))
        #判断选出非自身主机的IP
        if pcaddr == IP_line1:
            Selected_IP = IP_line2
        else:
            Selected_IP = IP_line1

        #右上角拉黑
        #在列表中搜索选中的IP
        status.input_search(Selected_IP)
        status.click_searchb()
        time.sleep(1)
        #选中列表中第一个拉黑,获取其mac地址
        status.click_listCheckbox1()
        Selected_MAC = status.getText_byXpath(status.Selected_MAC)
        status.click_addToBlackList()
        time.sleep(1)
        status.click_ok()
        time.sleep(2)
        # 断言 黑名单列表中的MAC和北移动的用户的mac
        blacklist = Organization_userBlackPage(self.driver, self.url)
        blacklist.click_blacklist()
        time.sleep(100)
        MAC_black = str(blacklist.getText_byXpath(blacklist.blicklist_mac))
        self.assertEqual(MAC_black, Selected_MAC, msg='黑名单移动出错 MAC不一致')
        print('移动到黑名单-右上角拉黑 验证成功')
        # 删除黑名单列表中的用户
        blacklist.click_delete()
        time.sleep(1)
        blacklist.click_ok()
        time.sleep(1)

        #用户列表 拉黑
        status.click_userstatus()
        time.sleep(1)
        # 在列表中搜索选中的IP
        status.input_search(Selected_IP)
        status.click_searchb()
        time.sleep(1)
        # 选中列表中第一个拉黑,获取其mac地址
        Selected_MAC = status.getText_byXpath(status.Selected_MAC)
        status.click_calldown()
        time.sleep(1)
        status.click_ok()
        time.sleep(2)
        # 断言 黑名单列表中的MAC和北移动的用户的mac
        blacklist.click_blacklist()
        time.sleep(1)
        MAC_black = str(blacklist.getText_byXpath(blacklist.blicklist_mac))
        self.assertEqual(MAC_black, Selected_MAC, msg='黑名单移动出错 MAC不一致')
        print('移动到黑名单-列表中拉黑 验证成功')
        # 删除黑名单列表中的用户
        blacklist.click_delete()
        time.sleep(1)
        blacklist.click_ok()
        time.sleep(1)
        list_tips = str(blacklist.getText_byXpath(blacklist.list_tips))
        self.assertEqual(list_tips, nodata, msg='黑名单删除失败')
        self.driver.quit()
        logger.info('test_003_movetoBlicklist passed')
    def test_001_UserStatistics(self):
        u'''用户统计(某些型号不支持建立pppoe账号)'''
        tempUser = getAssertText('tempUser')
        Minute = getAssertText('minute')
        Ban = getAssertText('Ban')
        pppoeSp = getParameter('pppoeSp')
        SupportP = getExcelValue(pppoeSp)
        webAutnp = getParameter('webAutnp')
        SupportW = getExcelValue(webAutnp)

        userstatus = Organization_userStatusPage(self.driver, self.url)
        userstatus.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        selmanual = userstatus.selelement_byXpath(userstatus.selmanual)
        Select(selmanual).select_by_value('3')
        time.sleep(0.3)
        Select(selmanual).select_by_value('5')
        time.sleep(0.3)
        Select(selmanual).select_by_value('10')
        time.sleep(0.3)
        Select(selmanual).select_by_value('60')
        time.sleep(0.3)
        Select(selmanual).select_by_value('manual')
        time.sleep(0.3)
        userstatus.click_refreshtable()
        time.sleep(1)
        #右上角移动、加入黑名单按钮
        userstatus.find_move()
        userstatus.find_addToBlackList()
        # 定义页面显示元素变量
        ID = str(userstatus.getText_byXpath(userstatus.ID))
        username = str(userstatus.getText_byXpath(userstatus.username))
        group = str(userstatus.getText_byXpath(userstatus.group))
        VlanID = str(userstatus.getText_byXpath(userstatus.VlanID))
        IP = str(userstatus.getText_byXpath(userstatus.IP))
        mac = str(userstatus.getText_byXpath(userstatus.mac))
        authmode = str(userstatus.getText_byXpath(userstatus.authmode))
        online_time_length = str(
            userstatus.getText_byXpath(userstatus.online_time_length))
        Uploading_data = str(
            userstatus.getText_byXpath(userstatus.Uploading_data))
        Downing_data = str(userstatus.getText_byXpath(userstatus.Downing_data))
        Uploading_speed = str(
            userstatus.getText_byXpath(userstatus.Uploading_speed))
        Downing_speed = str(
            userstatus.getText_byXpath(userstatus.Downing_speed))
        edit = str(userstatus.getText_byXpath(userstatus.edit))

        # 断言 用户列表是否显示有误
        time.sleep(1)
        self.assertEqual(ID, '1', msg='ID出错')
        print('用户状态 - ID 验证成功')
        self.assertIsNotNone(username, msg='用户名 出错')
        print('用户状态 - 用户名 验证成功')
        self.assertEqual(group, tempUser,
                         msg='所属组 出错')  # 脚本在最后会清空组织架构,所以脚本在一开始新建组,用户都是 临时用户
        print('用户状态 - 所属组 验证成功')
        self.assertIsNotNone(VlanID, msg='VLANID 出错')
        print('用户状态 - VLANID 验证成功')
        self.assertIn('192.168.', IP, msg='IP 出错')  # lan口地址段
        print('用户状态 - IP 验证成功')
        self.assertEqual(len(mac), 17, msg='mac 出错')  # 判断mac地址长度
        print('用户状态 - mac 验证成功')
        self.assertIsNotNone(authmode, msg='认证方式 出错')
        print('用户状态 - 认证方式 验证成功')
        self.assertIn(Minute, online_time_length, msg='在线时长 出错')  # 在线时长是否包含“分”
        print('用户状态 - 在线时长 验证成功')
        self.assertIsNotNone(Uploading_data, msg='上传数据 出错')
        print('用户状态 - 上传数据 验证成功')
        self.assertIsNotNone(Downing_data, msg='下载数据 出错')
        print('用户状态 - 下载数据 验证成功')
        self.assertIsNotNone(Uploading_speed, msg='上传速度 出错')
        print('用户状态 - 上传速度 验证成功')
        self.assertIsNotNone(Downing_speed, msg='下载速度 出错')
        print('用户状态 - 下载速度 验证成功')
        self.assertEqual(edit, Ban, msg='拉黑菜单显示 出错')
        print('用户状态 - 拉黑菜单显示 验证成功')

        userauth = Organization_userAuthPage(self.driver, self.url)
        userauth.click_userAuth()
        time.sleep(1)
        userauth.click_account()
        time.sleep(2)
        userauth.click_addUser()
        time.sleep(1)
        selauthType = userauth.selelement_byName(userauth.authType)
        if SupportW == '√':
            try:
                self.driver.implicitly_wait(2)
                Select(selauthType).select_by_value('Web')
            except NoSuchElementException:
                raise Exception('认证账号中不能选择web类型')
        elif SupportW == '×':
            try:
                self.driver.implicitly_wait(2)
                Select(selauthType).select_by_value('Web')
            except NoSuchElementException:
                logger.info(u'认证账号中不能选择web类型,与参数表相符')
            else:
                CapPic(self.driver)
                logger.info(u'认证账号中能选择web类型,与参数表不相符')
                raise Exception('认证账号中能选择web类型,与参数表不相符')
        else:
            logger.info(u'web参数表读取异常')
            logger.info(u'web参数表读取值为:', SupportW)
            raise Exception(u'web参数表读取异常')
        time.sleep(0.3)
        if SupportP != '×':
            try:
                self.driver.implicitly_wait(2)
                Select(selauthType).select_by_value('PPPoE')
            except NoSuchElementException:
                raise Exception('认证账号中不能选择pppoe类型')
        elif SupportP == '×':
            try:
                self.driver.implicitly_wait(2)
                Select(selauthType).select_by_value('PPPoE')
            except NoSuchElementException:
                logger.info(u'认证账号中不能选择pppoe类型,与参数表相符')
            else:
                CapPic(self.driver)
                logger.info(u'认证账号中能选择pppoe类型,与参数表不相符')
                raise Exception('认证账号中能选择pppoe类型,与参数表不相符')
        else:
            logger.info(u'pppoe参数表读取异常')
            logger.info(u'pppoe参数表读取值为:', SupportP)
            raise Exception(u'pppoe参数表读取异常')
        time.sleep(0.3)
        self.driver.implicitly_wait(10)

        self.driver.quit()
        logger.info('test_001_UserStatistics passed')
    def test_001_tcp80(self):
        u'''验证tcp80 映射'''

        # #改用另外设置的server pc
        # # 打开Everthing,Evering充当80server(需事先设置开启相关http服务)
        # handle = win32process.CreateProcess("D:\Program Files\Everything\Everything.exe", '', None,
        #                                     None, 0, win32process.CREATE_NO_WINDOW, None, None,
        #                                     win32process.STARTUPINFO())  # 打开Evering,获得其句柄
        # #获取本机地址
        # pcaddr=socket.gethostbyname(socket.gethostname())

        #通过用户状态获取httpserver的IP地址
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        status.input_search(serverPcMac)
        status.click_searchb()
        time.sleep(1)
        try:
            serverIP = status.getText_byXpath(status.list_IP1)
        except NoSuchElementException:
            raise Exception(u'用户状态中未找到server IP')
            # print(serverIP)
        else:
            try:
                telnetlib.Telnet(serverIP, port=80, timeout=10)
                print('server tcp80端口已开启')
            except socket.timeout:
                logger.info(u'内网方向无法访问server TCP80端口')
                raise Exception(u'内网方向无法访问server TCP80端口')

        staticMapping = staticMappingPage(self.driver, self.url)
        #配置映射
        staticMapping.click_NetworkConfig()
        time.sleep(0.5)
        staticMapping.click_portMapping()
        time.sleep(1)
        staticMapping.click_add()
        time.sleep(1)
        staticMapping.input_IDs('statictest')
        staticMapping.input_IPs(serverIP)
        Selprotocols = staticMapping.selelement_byName(staticMapping.Protocols)
        Select(Selprotocols).select_by_value('1')  #1:tcp 2:udp 3:tcp/udp
        time.sleep(0.5)
        staticMapping.input_inS('80')
        time.sleep(0.5)
        staticMapping.input_inE('80')
        time.sleep(1)
        staticMapping.input_outS('80')
        time.sleep(0.5)
        staticMapping.input_outE('80')
        staticMapping.click_save()
        time.sleep(1)
        #断言
        list_port = str(staticMapping.getText_byXpath(staticMapping.list_port))
        print(list_port)
        self.assertEqual(list_port, '80~80:80~80', msg='端口对应关系不一致')
        print('tcp80映射 已添加')

        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        print('WAN1_ip=', WAN1_ip)
        time.sleep(1)
        self.driver.quit()
        url = 'http://' + str(WAN1_ip)
        print(url)

        if CPUmodel == 'Qualcomm':
            # 部分型号,如高通,因为芯片问题必须关闭wan口mac学习功能,原mac未清除之前无法从wan口访问路由器
            # 这里需要设置计划任务2分钟后清空原pc的arp缓存
            hostip = gettelnet('host')
            port = gettelnet('port')
            username = bytes(getweb('User'), encoding="utf8")
            password = bytes(getweb('Passwd'), encoding="utf8")
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            # 输入登录用户名
            tn.read_until(b'login:'******'Password:'******'#')
            tn.write(b"uptime" + b"\n")
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            print('result:', result)
            result1 = str(result.split(r'\r\n')[1]).split(r':')
            print(result1[1])
            tn.close()  # tn.write('exit\n')
            if int(result1[1]) + 2 < 60:
                hour = result1[0]
                min = int(result1[1]) + 2
            else:
                if int(result1[0]) + 1 < 24:
                    hour = int(result1[0]) + 1
                    min = '0' + str((int(result1[1]) + 2) - 60)
                else:
                    hour = '0' + str(int(result1[0]) + 1 - 24)
                    min = '0' + str((int(result1[1]) + 2) - 60)
            print(hour)
            print(min)
            pcaddr = str(
                socket.gethostbyname(socket.getfqdn(socket.gethostname())))
            cmd = "echo '%s %s * * * arp -d %s' > cmd " % (min, hour, pcaddr)
            print(cmd)
            cmd = bytes(cmd, encoding='utf8')
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            # 输入登录用户名
            tn.read_until(b'login:'******'Password:'******'#')
            tn.write(cmd + b"\n")
            tn.read_until(b'#')
            tn.write(b"cat cmd >> /var/spool/cron/crontabs/admin" + b"\n")
            tn.read_until(b'#')
            tn.write(b"killall crond" + b"\n")
            tn.read_until(b'#')
            tn.write(b"crond &" + b"\n")
            tn.read_until(b'#')
            tn.write(b"cat /var/spool/cron/crontabs/admin" + b"\n")
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            print('result:', result)
            if 'adp -d' in result:
                print('计划任务已写入')

        # 更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        if CPUmodel == 'Qualcomm':
            time.sleep(120)  #等待计划任务执行
        # 重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 将IP改回自动获取(设置dns为自动获取)
        # 调用bat脚本
        os.system('%s' % (batpath + 'ipconfig_renew.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('未获取到地址')

        print('url:', url)
        self.driver = webdriver.Chrome()
        # self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get(url)
        title = self.driver.title
        print(title)
        self.assertEqual(title,
                         '探索昆虫世界,用老蛙24mm f/14微距镜头试试 - 摄影,镜头 - IT之家',
                         msg='http访问有误')
        self.driver.quit()

        # win32process.TerminateProcess(handle[0], 0)  # 关闭Everying,没有能关闭掉就不关了
        logger.info('test_001_tcp80 passed')
    def test_002_userstatus(self):
        u'''PPPoE拨号挂断&&查看拨号信息&&同网段通信'''

        #将有线地址改为不同网段的地址,以验证同网段通信
        # 调用bat脚本 地址修改为 192.168.189.39 网关192.168.198.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 失败')

        # 开始拨号
        Adsl.connect(self)
        # 通过断言IP地址网段,判断是否可以拨号成功
        pcaddr_connectAdsl = socket.gethostbyname(
            socket.getfqdn(socket.gethostname()))
        # print(pcaddr_connectAdsl)
        self.assertIn('10.10.10.', str(pcaddr_connectAdsl), msg='PPPoE拨号失败')
        # 打开网页测试,测试上网
        self.driver = webdriver.Chrome()
        # self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get('http://www.baidu.com')
        time.sleep(2)
        title1 = self.driver.title
        print(title1)
        self.assertEqual(title1, baidutitle, msg='网页打开异常')
        time.sleep(1)
        #打开路由器页面测试同网段访问
        self.driver.get(RouteUrl)
        time.sleep(2)
        url = self.driver.current_url
        print(url)
        self.assertIn('login.html', url, msg='无法访问路由器')
        self.driver.quit()

        #查看拨号信息显示
        # 打开用户管理 - 用户状态
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        #通过过滤IP地址验证是否显示拨号用户信息
        status.input_search(str(pcaddr_connectAdsl))
        status.click_searchb()
        list_IP1 = str(status.getText_byXpath(status.list_IP1))
        self.assertIsNotNone(list_IP1, msg='pppoe列表 未显示拨号用户信息')
        self.driver.quit()

        #拨号挂断,通过断言IP地址网段,判断是否挂断
        Adsl.disconnect(self)
        pcaddr_disconnectAdsl = socket.gethostbyname(
            socket.getfqdn(socket.gethostname()))
        print(pcaddr_disconnectAdsl)
        self.assertIn('192.168.', str(pcaddr_disconnectAdsl), msg='PPPoE挂断失败')

        # 将IP改回自动获取
        # 调用bat脚本
        os.system('%s' % (batpath + 'changeDhcpIp.bat'))
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr_new = socket.gethostbyname(
                socket.getfqdn(socket.gethostname()))
            print(pcaddr_new, n)
            if '192.168.' not in str(pcaddr_new):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')

        logger.info('test_002_userstatus passed')
Exemple #9
0
    def test_002_localDMZ(self):
        u'''验证局部DMZ'''
        # #获取本机地址
        # pcaddr=socket.gethostbyname(socket.gethostname())

        # 通过用户状态获取httpserver的IP地址
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        status.input_search(serverPcMac)
        status.click_searchb()
        time.sleep(1)
        try:
            serverIP = status.getText_byXpath(status.list_IP1)
            # print(serverIP)
        except NoSuchElementException:
            raise Exception(u'用户状态中未找到server IP')

        #局部DMZ
        dmz = DMZPage(self.driver, self.url)
        dmz.click_NetworkConfig()
        time.sleep(0.5)
        dmz.click_portMapping()
        time.sleep(1)
        dmz.click_DMZ()
        time.sleep(1)
        dmz.click_DMZEn()
        dmz.input_GlobalDMZ('0.0.0.0')  #防止已经有过全局DMZ设置
        dmz.input_WAN1DMZ(serverIP)
        dmz.click_save()
        time.sleep(1)
        #断言
        dmz.click_DMZ()  #相当于刷新下界面,否则on依旧没有checked参数
        time.sleep(1)
        DMZ_status = str(dmz.getAttribute_byXpath(dmz.DMZEs, 'checked'))
        print(DMZ_status)
        self.assertEqual(DMZ_status, 'true', msg='DMZ 开启有问题')
        print('局部DMZ 已开启')

        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        time.sleep(1)

        if CPUmodel == 'Qualcomm':
            # 部分型号,如高通1200Wv2,因为芯片问题必须关闭wan口mac学习功能,原mac未清除之前无法从wan口访问路由器
            # 这里需要设置计划任务2分钟后清空原pc的arp缓存
            hostip = gettelnet('host')
            port = gettelnet('port')
            username = bytes(getweb('User'), encoding="utf8")
            password = bytes(getweb('Passwd'), encoding="utf8")
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            # 输入登录用户名
            tn.read_until(b'login:'******'Password:'******'#')
            tn.write(b"uptime" + b"\n")
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            print('result:', result)
            result1 = str(result.split(r'\r\n')[1]).split(r':')
            print(result1[1])
            tn.close()  # tn.write('exit\n')
            if int(result1[1]) + 2 < 60:
                hour = result1[0]
                min = int(result1[1]) + 2
            else:
                if int(result1[0]) + 1 < 24:
                    hour = int(result1[0]) + 1
                    min = '0' + str((int(result1[1]) + 2) - 60)
                else:
                    hour = '0' + str(int(result1[0]) + 1 - 24)
                    min = '0' + str((int(result1[1]) + 2) - 60)
            print(hour)
            print(min)
            pcaddr = str(
                socket.gethostbyname(socket.getfqdn(socket.gethostname())))
            cmd = "echo '%s %s * * * arp -d %s' > cmd " % (min, hour, pcaddr)
            print(cmd)
            cmd = bytes(cmd, encoding='utf8')
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            # 输入登录用户名
            tn.read_until(b'login:'******'Password:'******'#')
            tn.write(cmd + b"\n")
            tn.read_until(b'#')
            tn.write(b"cat cmd >> /var/spool/cron/crontabs/admin" + b"\n")
            tn.read_until(b'#')
            tn.write(b"killall crond" + b"\n")
            tn.read_until(b'#')
            tn.write(b"crond &" + b"\n")
            tn.read_until(b'#')
            tn.write(b"cat /var/spool/cron/crontabs/admin" + b"\n")
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            print('result:', result)
            if 'adp -d' in result:
                print('计划任务已写入')

        # 更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        if CPUmodel == 'Qualcomm':
            time.sleep(120)  # 等待计划任务执行
        # 重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 将IP改回自动获取(设置dns为自动获取)
        # 调用bat脚本
        os.system('%s' % (batpath + 'ipconfig_renew.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('未获取到地址')

        try:
            telnetlib.Telnet(str(WAN1_ip), port=3389, timeout=10)
            print('局部DMZ 验证成功')
        except socket.timeout:
            logger.info(u'局部DMZ 验证失败')
            raise Exception(u'局部DMZ 验证失败')
        self.driver.quit()
        logger.info('test_002_localDMZ passed')
    def test_001_easyIP(self):
        u'''验证 easyIP,后台telnet验证iptables规则'''

        # 通过用户状态获取httpserver的IP地址
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        status.input_search(serverPcMac)
        status.click_searchb()
        time.sleep(1)
        try:
            serverIP = status.getText_byXpath(status.list_IP1)
        except NoSuchElementException:
            raise Exception(u'用户状态中未找到server IP')
            # print(serverIP)

        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_NetworkConfig()
        time.sleep(0.5)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        print('WAN1_ip=',WAN1_ip)
        time.sleep(1)

        #判断IP
        serverIPadd = str(serverIP).split(r'.')[-1]
        print(serverIPadd)
        if (int(serverIPadd) - 1 > 1) and (int(serverIPadd) + 2 <= 255):
            serverIPadd_1 = str(serverIP).split(r'.')[:-1] + str(int(serverIPadd) - 1)
            serverIPadd1 = str(serverIP).split(r'.')[:-1] + str(int(serverIPadd) + 1)
            serverIPadd2 = str(serverIP).split(r'.')[:-1] + str(int(serverIPadd) + 2)
        else:
            serverIPadd_1 = str(serverIP).split(r'.')[:-1] + str(int(serverIPadd) + 1)
            serverIPadd1 = str(serverIP).split(r'.')[:-1] + str(int(serverIPadd) - 2)
            serverIPadd2 = str(serverIP).split(r'.')[:-1] + str(int(serverIPadd) - 1)

        WAN1_ipadd = str(WAN1_ip).split(r'.')[-1]
        if int(WAN1_ipadd) + 1 <= 255:
            WAN1_ipadd1 = str(WAN1_ip).split(r'.')[:-1] + str(int(WAN1_ipadd) + 1)
        else:
            WAN1_ipadd1 = str(int(WAN1_ipadd) - 1)

        #新增
        natRule = natRulePage(self.driver, self.url)
        #1 包含 边界
        natRule.click_NetworkConfig()
        time.sleep(0.5)
        natRule.click_portMapping()
        time.sleep(1)
        natRule.click_natRule()
        time.sleep(1)
        natRule.click_add()
        time.sleep(1)
        natRule.input_RuleIDs('easyIPtest')
        natRule.input_InFromIPs(serverIP)
        natRule.input_InEndIPs(serverIPadd2)
        natRule.input_OutIPs(WAN1_ipadd1)
        time.sleep(1)
        natRule.click_save()
        time.sleep(1)
        #断言
        InFromIPs = str(natRule.getText_byXpath(natRule.list_InFromIPs))
        self.assertEqual(InFromIPs,serverIP, msg='内网起始IP地址 与设置的不一致')
        InEndIPs = str(natRule.getText_byXpath(natRule.list_InEndIPs))
        self.assertEqual(InEndIPs, serverIPadd2, msg='内网结束IP地址 与设置的不一致')
        OutIPs = str(natRule.getText_byXpath(natRule.list_OutIPs))
        self.assertEqual(OutIPs, WAN1_ipadd1, msg='外网起始IP地址 与设置的不一致')
        print('easyIP规则 已添加')

        # 3、调用wireshark 开启抓包,必须要抓到包之后才会进行下一步,因此放在设置vpn之后,通过抓下一次的log
        packetfile = tmppath + 'syslogtest.pcapng'
        dir = wiresharkpath[0:2]
        getpacket = ('tshark -i%s -f "icmp" -w %s -c 2' % (pcNetworkID, packetfile))
        os.system('%s && cd %s && %s' % (dir, wiresharkpath, getpacket))

        # 4、读取抓包显示 并存为log文件
        logfile = tmppath + 'syslogtest.log'
        savepacket = ('tshark -r %s -T fields -e "ip.src" -e ip.dst -Y "syslog" > %s ' % (packetfile, logfile))
        os.system('%s && cd %s && %s' % (dir, wiresharkpath, savepacket))

        # 5、读取判断syslog生效
        with open(logfile, 'r') as file_to_read:
            while True:
                lines = file_to_read.readline()  # 整行读取数据
                print(lines)
                if not lines:
                    break
                if host + pcaddr in lines:
                    print(u'验证通过')



        # # 连接Telnet服务器
        # hostip = gettelnet('host')
        # port = gettelnet('port')
        # username = bytes(getweb('User'), encoding="utf8")
        # password = bytes(getweb('Passwd'), encoding="utf8")
        # tn = telnetlib.Telnet(host=hostip, port=port)
        # tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # # 输入登录用户名
        # tn.read_until(b'login:'******'Password:'******'#')
        # tn.write(b'iptables -t nat  -L wan1_nat_rule_loop' + b'\n')
        # # 输出结果,判断
        # time.sleep(1)
        # result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        # print('-------------------输出结果------------------------')
        # # 命令执行结果
        # print('result:', result)
        # #后台实际应有的结果
        # result1='SNAT       all  --  anywhere             anywhere            source IP range 192.168.1.200-192.168.1.202 to:192.169.122.250'
        # # 判断
        # if result1 in result:
        #     print('easyIP规则 验证成功')
        # else:
        #     raise Exception('easyIP规则 验证失败')  # 如果没有则报错
        # tn.close()  # tn.write('exit\n')

        self.driver.quit()
        logger.info('test_001_easyIP passed')