仲天
首页
(current)
分类
Go
Python
自动化脚本
xTS(谷歌认证测试)
Selenium
软件测试
Redis
Mysql
Docker
MongoDB
Jquery
Nginx
Bootstrap
Linux
正则表达式
bat
cmd批处理
截图
在线工具
搜索
python + selenium + unittest 实现网站登录注册自动化测试
2022-07-20 14:22:19
235
本文章为原创文章,转载请附上原文地址,谢谢。
推荐一个在线工具网站:[在线工具大全](https://www.zztdd.cn) 登录封装: ```python from selenium import webdriver import time class Auto(object): def __init__(self, *args): login_url = 'https://snail.zhuozhuo.io/?n=fastCat.fcFrontSnail.NewFront.NewFront.PCLoginPage' register_url = "https://getsuwo.com/?n=fastCat.fcFrontSnail.NewFront.NewFront.PCRegisterPage" InRegisterAuto_url = "https://getsuwo.com/?n=fastCat.fcFrontSnail.NewFront.NewFront.PCInternationalRegisterPage" driver = webdriver.Chrome() self.driver = driver self.login_url = login_url self.register_url = register_url self.InRegisterAuto_url = InRegisterAuto_url self.args = args #登录页面 def loginAuto(self): self.driver.implicitly_wait(5) self.driver.get(self.login_url) self.error('self.driver.find_element_by_name("Username").send_keys(self.args[0])') self.error('self.driver.find_element_by_name("Password").send_keys(self.args[1])') self.driver.find_element_by_css_selector("[type='submit']").click() try: time.sleep(0.5) result = self.driver.find_element_by_class_name("ErrorMsg").text return result except: return finally: self.driver.quit() ``` 登录用例执行: ```python import unittest import warnings from Tool import Auto class ExecuteCase(unittest.TestCase): def setUp(self): warnings.simplefilter('ignore', ResourceWarning) # 处理unittest警告信息 # 测试账号(test_1 -- test_8),登录页面账号未作格式校验 def test_1(self): '''所有输入框为空''' expectResult = "帐号不能为空" login = Auto() actualResult = login.loginAuto() self.assertEqual(expectResult, actualResult) def test_2(self): '''输入12位手机号,密码为空,值为:184883658555''' expectResult = "手机号码格式不正确" login = Auto("184883658555") actualResult = login.loginAuto() self.assertEqual(expectResult, actualResult) def test_3(self): '''输入10位手机号,密码为空,值为:1848365858''' expectResult = "手机号码格式不正确" login = Auto("1848365858") actualResult = login.loginAuto() self.assertEqual(expectResult, actualResult) ``` 等等…… [详细源码,请访问github](https://github.com/ZhongTian5/selenium) 推荐一个免费的在线小工具网站:https://www.zztdd.cn/
版权声明:本文为仲天原创文章,转载请附上原文出处链接和本声明。
本文链接:
文章分类
Go
Python
自动化脚本
xTS(谷歌认证测试)
Selenium
软件测试
Redis
Mysql
Docker
MongoDB
Jquery
Nginx
Bootstrap
Linux
正则表达式
bat
cmd批处理
截图
推荐文章
python + selenium + unittest 实现网站登录注册自动化测试
235
Go 取两个切片的交集方法
81
Linux中常用命令,超级详细
404
基于Go、Gin、Redis、Mysql、Vue、TS、Vite、ElementPlus开发的后台管理系统。
389
推荐一个golang日志库,配置简单又好用(原创)
483
优选网站
在线JSON工具
在线音频提取
Linux在线大全
PDF转WORD
TCP/IP端口大全