def test_002_unMount(self):
        u'''U盘弹出 显示'''

        sharing = NetworkSharingPage(self.driver, self.url)
        # 弹出设备
        sharing.click_Eject()
        time.sleep(1)
        sharing.click_ok()
        time.sleep(2)
        #弹出后使用率、容量等都为0
        # U盘使用率
        UsageRate = sharing.getText_byXpath(sharing.UsageRate)
        self.assertEqual(UsageRate, '0', msg='弹出后U盘使用率 显示异常')
        # U盘总容量 已使用容量 剩余容量 三个值+提示是一个元素,判断条件特殊
        # U盘总容量 后元素(所有)
        Total = sharing.getText_byXpath(sharing.Total)
        # “已使用容量”提示
        Usedtext = sharing.getText_byXpath(sharing.Usedtext)
        # “剩余容量”提示
        Residualtext = sharing.getText_byXpath(sharing.Residualtext)
        Total1 = '0' + Usedtext + ' 0' + Residualtext + ' 0'
        if Total == Total1:
            print('弹出后U盘总容量信息 显示正常')
        else:
            raise Exception('弹出后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, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'mount | grep /media/' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 后台实际应有的结果
        result1 = 'codepage=cp437,iocharset=utf8'
        # 判断
        if result1 not in result:
            print('卸载后mount显示 验证成功')
        else:
            raise Exception('卸载后mount显示 验证失败')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')

        self.driver.quit()
        logger.info('test_002_unMount passed')
Beispiel #2
0
    def test_004_delAccount(self):
        u'''账号删除:单个/批量'''

        account = NetworkSharingPage(self.driver, self.url)
        #单个账号删除
        account.click_listdel5()
        time.sleep(1)
        account.click_ok()
        time.sleep(1)
        list5_nodata = account.getText_byXpath(account.list5_nodata)
        self.assertEqual(list5_nodata, ' ', msg='第5行账号删除失败')
        #批量删除 全选
        account.click_allsel()
        time.sleep(0.2)
        account.click_delete()
        time.sleep(2)
        account.click_ok()
        time.sleep(1)
        list3_nodata = account.getText_byXpath(account.list3_nodata)
        self.assertEqual(list3_nodata, ' ', msg='第3行账号删除失败')

        self.driver.quit()
        logger.info('test_004_delAccount 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')