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_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')