def test_001_ftpServer(self):
        u'''ftp服务器基本设置,ftp查看'''
        host = gettelnet('host')
        ftpSmaba = NetworkSharingPage(self.driver, self.url)
        # 1、设置ftp基本信息
        ftpSmaba.click_choosml()
        time.sleep(1)
        ftpSmaba.input_names('1')
        ftpSmaba.click_FTP_DIR_1_check()
        ftpSmaba.click_modal_FTP()
        time.sleep(1)
        try:  #以访第一次选中后 第二次点击被取消 从而未选中共享目录
            self.driver.implicitly_wait(1)
            ftpSmaba.find_tips_show_inf()
        except NoSuchElementException:
            pass
        else:
            ftpSmaba.click_FTP_DIR_1_check()
            ftpSmaba.click_modal_FTP()
            time.sleep(3)
        self.driver.implicitly_wait(10)
        ftpEn = ftpSmaba.getAttribute_byName(ftpSmaba.ftpEns, 'checked')
        print(ftpEn)
        if ftpEn != 'true':
            ftpSmaba.click_ftpEn()
            time.sleep(1)
        defaultPort = str(
            ftpSmaba.getAttribute_byName(ftpSmaba.ftpports, 'value'))
        self.assertEqual(defaultPort, '21', msg='ftp默认端口不为21')
        ftpSmaba.click_save()
        time.sleep(1)
        enableDevice = ftpSmaba.getAttribute_byId(ftpSmaba.enableDevices,
                                                  'checktype')
        print(enableDevice)
        if enableDevice != '1':  #1为打开网络共享
            ftpSmaba.click_enableDevice()
            time.sleep(3)
        ftpEn = ftpSmaba.getAttribute_byName(ftpSmaba.ftpEns, 'checked')
        enableDevice = ftpSmaba.getAttribute_byId(ftpSmaba.enableDevices,
                                                  'checktype')
        self.assertEqual(ftpEn, 'true', msg='启用FTP服务器 失败')
        self.assertEqual(enableDevice, '1', msg='网络共享 启用失败')
        time.sleep(10)
        #2、ftp查看目录文件
        IP = host
        Port = 21
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=Port, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******')  # 相当于没有验证账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        # print('ftpFile', ftpFile)
        ftp.quit()
        #过滤掉中文和带空格的
        zhmodel = re.compile(u'[\u4e00-\u9fa5]')  # 检查中文
        ftpFile2 = []
        for file in ftpFile:
            if ' ' not in file:
                ftpFile2.append(file[2:])
        for i in ftpFile2:
            if zhmodel.search(i):
                ftpFile2.remove(i)
        # print('ftpFile2:',ftpFile2)
        # 3、telnet后台查看目录文件
        # 连接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, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'cd /ftpRoot/1 ; ls' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        # print('result:', result)
        tn.close()  # tn.write('exit\n')

        #4、判断对比 ftp查看内容在telnet查看的目录中
        for i in ftpFile2:
            if result.count(i):
                pass
            else:
                raise Exception(' 验证失败')  # 如果没有则报错

        self.driver.quit()
        logger.info('test_001_ftpServer passed')
Exemplo n.º 2
0
    def test_001_NetworkSharing(self):
        u'''网络共享&FTP服务器(某些设备可能不支持)'''
        netShareP = getParameter('netShareP')
        Support = getExcelValue(netShareP)
        networkshare = NetworkSharingPage(self.driver, self.url)
        if Support == '√':
            logger.info(u'参数支持网络共享')
            try:
                self.driver.implicitly_wait(2)
                networkshare.find_NetworkSharing()
            except NoSuchElementException:
                CapPic(self.driver)
                logger.info(u'软件不支持 网络共享,与参数表不符')
                raise Exception('软件不支持 网络共享,与参数表不符')
            else:
                logger.info(u'软件支持网络共享,与参数表相符')
                self.driver.implicitly_wait(10)
                time.sleep(1)
                # 开/关访问控制
                enableDevice = networkshare.getAttribute_byId(networkshare.enableDevices, 'checktype')  # checktype 0未开启,1开启
                self.assertEqual(enableDevice, '0', msg='网络共享 默认未关闭')
                networkshare.click_enableDevice()
                time.sleep(2)
                enableDevice = networkshare.getAttribute_byId(networkshare.enableDevices, 'checktype')
                self.assertEqual(enableDevice, '1', msg='网络共享 开启失败')
                networkshare.click_enableDevice()
                time.sleep(2)
                enableDevice = networkshare.getAttribute_byId(networkshare.enableDevices, 'checktype')
                self.assertEqual(enableDevice, '0', msg='网络共享 关闭失败')
                # U盘使用率
                UsageRate = networkshare.getText_byXpath(networkshare.UsageRate)
                self.assertIn('%', UsageRate, msg='U盘使用率 显示异常')
                # U盘总容量 已使用容量 剩余容量 三个值+提示是一个元素,判断条件特殊
                # U盘总容量 后元素(所有)
                Total = networkshare.getText_byXpath(networkshare.Total)
                # “已使用容量”提示
                Usedtext = networkshare.getText_byXpath(networkshare.Usedtext)
                Usedtext1 = 'M' + Usedtext
                # “剩余容量”提示
                Residualtext = networkshare.getText_byXpath(networkshare.Residualtext)
                Residualtext1 = 'M' + Residualtext
                if Usedtext1 in Total and Residualtext1 in Total:
                    print('U盘总容量信息 显示正常')
                else:
                    raise Exception('U盘总容量信息 显示异常')
                #弹出设备
                networkshare.find_Eject()

                # 账号设置
                networkshare.click_AccountSettings()
                time.sleep(1)
                networkshare.click_open_pswd()
                time.sleep(2)
                networkshare.find_add()
                networkshare.find_delete()
                # admin账号
                adminuser = str(networkshare.getText_byXpath(networkshare.adminuser))
                self.assertEqual(adminuser, 'admin', msg='admin账号有误')
                guestuser = str(networkshare.getText_byXpath(networkshare.guestuser))
                self.assertEqual(guestuser, 'guest', msg='guest账号有误')

                #网络共享
                networkshare.click_NetworkSharing2()
                time.sleep(1)
                networkshare.click_choosml()
                time.sleep(1)
                networkshare.input_names('test')
                networkshare.click_modal_hide()
                time.sleep(0.5)
                networkshare.click_ftpEn()
                networkshare.input_ftpport('222')
                networkshare.click_WANEnable()
                try:
                    self.driver.implicitly_wait(2)
                    networkshare.find_sambaEn() # 启用SAMBA
                except ElementNotVisibleException:
                    raise Exception('sambaEn 页面无显示')
        elif Support == '×':
            logger.info(u'参数不支持网络共享')
            try:
                self.driver.implicitly_wait(2)
                networkshare.find_NetworkSharing()
            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_001_NetworkSharing passed')