def test_001_AccountSettings(self): u'''账号设置:新建、删除、修改''' reachMaxA = getAssertText('reachMaxA') roleA = getAssertText('roleA') account = NetworkSharingPage(self.driver, self.url) #新建 n = 2 while n < 6: n += 1 if n < 6: account.click_add() time.sleep(1) account.input_username(n) account.input_passwd1(n) account.input_passwd2(n) authority = account.selelement_byName(account.authority) Select(authority).select_by_value('1') #0 读 1 读写 account.click_save() time.sleep(1) else: account.click_add() time.sleep(1) account.input_username(n) account.input_passwd1(n) account.input_passwd2(n) authority = account.selelement_byName(account.authority) Select(authority).select_by_value('0') # 0 读 1 读写 account.click_save() time.sleep(1) tips = str(account.getText_byClass(account.tips_show_in)) self.assertEqual(tips, reachMaxA, msg='最大账号为5个 验证失败') account.click_modal_hide() time.sleep(1) Acc3 = str(account.getText_byXpath(account.Acc3)) auth3 = str(account.getText_byXpath(account.auth3)) self.assertEqual(Acc3, '3', msg='新增账号失败') self.assertEqual(auth3, roleA, msg='新增账号权限失败') Acc4 = str(account.getText_byXpath(account.Acc4)) auth4 = str(account.getText_byXpath(account.auth4)) self.assertEqual(Acc4, '4', msg='新增账号名失败') self.assertEqual(auth4, roleA, msg='新增账号权限失败') Acc5 = str(account.getText_byXpath(account.Acc5)) auth5 = str(account.getText_byXpath(account.auth5)) self.assertEqual(Acc5, '5', msg='新增账号名失败') self.assertEqual(auth5, roleA, msg='新增账号权限失败') self.driver.quit() logger.info('test_001_AccountSettings passed')
def test_003_otherAccount(self): u'''修改其他新增账号名及密码''' role2A = getAssertText('role2A') account = NetworkSharingPage(self.driver, self.url) account.click_listedit3() time.sleep(1) account.input_username('33') account.input_passwd1('33') account.input_passwd2('33') authority = account.selelement_byName(account.authority) Select(authority).select_by_value('0') # 0 读 1 读写 account.click_save() time.sleep(1) Acc3 = str(account.getText_byXpath(account.Acc3)) auth3 = str(account.getText_byXpath(account.auth3)) self.assertEqual(Acc3, '33', msg='新增账号失败') self.assertEqual(auth3, role2A, msg='新增账号权限失败') self.driver.quit() logger.info('test_003_otherAccount 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')