def test_006_passwdAcessFTP(self):
        u'''启用/取消 密码访问ftp'''
        roleA = getAssertText('roleA')
        host = gettelnet('host')
        User = getweb('User')
        Passwd = getweb('Passwd')
        account = NetworkSharingPage(self.driver, self.url)
        account.click_AccountSettings()
        time.sleep(1)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        if open_pswd != 'true':
            account.click_open_pswd()
            time.sleep(2)
            open_pswd = str(
                account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'true', msg='启用密码访问 开启失败')
        # 操作删除 以访已有规则
        account.click_allsel()
        time.sleep(0.2)
        account.click_delete()
        time.sleep(2)
        try:
            self.driver.implicitly_wait(2)
            account.find_ok()
        except NoSuchElementException:
            try:
                account.find_tips_show_inf()
                time.sleep(1)
            except NoSuchElementException:
                pass
        except AttributeError:
            try:
                account.find_tips_show_inf()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('账号列表为空')
        # 新增一个账号
        account.click_add()
        time.sleep(1)
        account.input_username('1')
        account.input_passwd1('1')
        account.input_passwd2('1')
        authority = account.selelement_byName(account.authority)
        Select(authority).select_by_value('1')  # 0 读 1 读写
        account.click_add_modal()

        # self.driver.find_element_by_xpath('//*[@id="modal-add"]/div/div/div[3]/ul/li[1]/button').click()
        time.sleep(3)
        Acc3 = str(account.getText_byXpath(account.Acc3))
        auth3 = str(account.getText_byXpath(account.auth3))
        self.assertEqual(Acc3, '1', msg='新增账号失败')
        self.assertEqual(auth3, roleA, msg='新增账号权限失败')
        time.sleep(5)
        #ftp验证
        # ftp尝试使用无密码登录(应该失败)
        IP = host
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******')  # 相当于没有验证账号密码
        except ftplib.error_perm:
            print('启用密码访问后 ftp无密码无法登录 验证通过')
        else:
            raise Exception("启用密码访问后 ftp无密码依旧可以登录")
        ftp.quit()
        # ftp尝试使用admin登录
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user=User, passwd=Passwd)  # admin账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        else:
            print("启用密码访问后 ftp使用admin可以登录")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        print('ftpFile', ftpFile)
        ftp.quit()
        # ftp尝试使用guest登录
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******', passwd='guest')  # guest账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        else:
            print("启用密码访问后 ftp使用修改过guest密码的账号可以登录")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        print('ftpFile', ftpFile)
        ftp.quit()
        # ftp尝试使用新增账号1登录
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******', passwd='1')  # 新增账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        else:
            print("启用密码访问后 ftp使用新增账号可以登录")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        print('ftpFile', ftpFile)
        ftp.quit()

        #取消密码访问
        account = NetworkSharingPage(self.driver, self.url)
        account.click_AccountSettings()
        time.sleep(1)
        account.click_open_pswd()
        time.sleep(10)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'None', msg='启用密码访问 取消失败')
        # ftp尝试使用无密码登录
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******')  # 相当于没有验证账号密码
        except ftplib.error_perm:
            raise Exception("取消密码访问后 ftp无密码无法登录")
        else:
            print('启用密码访问后 ftp无密码无法登录 验证通过')
        ftp.quit()

        # # 删除账号
        # account.click_listedit3()
        # time.sleep(1)
        # account.click_ok()
        # time.sleep(1)
        # list3_nodata = account.getText_byXpath(account.list3_nodata)
        # self.assertEqual(list3_nodata, ' ', msg='第3行账号删除失败')
        # print('账号删除')

        self.driver.quit()
        logger.info('test_005_passwdAcessFTP passed')
    def test_007_passwdAcessSAMBA(self):
        u'''启用/取消 密码访问samba'''
        host = gettelnet('host')
        User = getweb('User')
        Passwd = getweb('Passwd')
        account = NetworkSharingPage(self.driver, self.url)
        account.click_AccountSettings()
        time.sleep(1)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        if open_pswd != 'true':
            account.click_open_pswd()
            time.sleep(2)
            open_pswd = str(
                account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'true', msg='启用密码访问 开启失败')
        time.sleep(5)
        # samba登录
        user_name = "anonymous"
        pass_word = ""
        my_name = "anyname"
        domain_name = ""
        remote_smb_IP = host
        #1 无密码登录(应该失败)
        smb = SMBConnection(user_name,
                            pass_word,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            print('启用密码访问后 samba无密码无法登录 验证通过')
        else:
            raise Exception('启用密码访问后 samba无密码依旧可以登录')
        smb.close()
        # 2 admin密码登录
        smb = SMBConnection(User,
                            Passwd,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('启用密码访问后 samba使用admin登录验证失败')
        smb.close()
        print('启用密码访问后 samba使用admin登录 验证通过')
        # 3 guest账号登录
        smb = SMBConnection('guest',
                            'guest',
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('启用密码访问后 samba使用guest登录验证失败')
        smb.close()
        print('启用密码访问后 samba使用guest登录 验证通过')
        # 4 新增账号登录
        smb = SMBConnection('1', '1', my_name, domain_name, use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('启用密码访问后 samba使用新增账号登录验证失败')
        smb.close()
        print('启用密码访问后 samba使用新增登录 验证通过')

        #取消密码访问
        account.click_open_pswd()
        time.sleep(10)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'None', msg='启用密码访问 取消失败')
        # samba无密码登录
        smb = SMBConnection(user_name,
                            pass_word,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('取消密码访问后 samba无密码无法登录')
        else:
            print('启用密码访问后 samba无密码登录 验证通过')
        smb.close()

        # 删除账号
        account.click_listdel3()
        time.sleep(1)
        account.click_ok()
        time.sleep(1)
        list3_nodata = account.getText_byXpath(account.list3_nodata)
        self.assertEqual(list3_nodata, ' ', msg='第3行账号删除失败')
        print('账号删除')

        self.driver.quit()
        logger.info('test_006_passwdAcessSAMBA passed')
Example #3
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')