<span style="color: #577999; font-style: italic">#coding=utf-8<br><span style="color: #577999; font-style: italic"><br><span style="color: #161b99; font-style: italic">'''<br><span style="color: #161b99; font-style: italic"> Created on 2017-7-4<br><span style="color: #161b99; font-style: italic"> @auther:Qigege<br><span style="color: #161b99; font-style: italic"> project:<span style='color: #161b99; font-style: italic; font-family: "宋体"'>登录测试用例<span style="color: #161b99; font-style: italic"><br><span style="color: #161b99; font-style: italic">'''<br><span style="color: #161b99; font-style: italic"><br><span style="color: #4038e3">import unittest<br><span style="color: #4038e3">from selenium <span style="color: #4038e3">import webdriver<br><span style="color: #4038e3">from selenium.webdriver.firefox.firefox_binary <span style="color: #4038e3">import FirefoxBinary<br><span style="color: #4038e3">import time<br><br><span style="color: #4038e3">class <span style="color: #dd2eee">LoginCase(unittest.TestCase):<br><span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">setUp(<span style="color: #94558d">self):<br> binary=FirefoxBinary(<span style="color: #ef3142">'F:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">ff<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">MozillaFirefox50.1.0<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">firefox.exe')<br><span style="color: #94558d">self.driver=webdriver.Firefox(<span style="color: #660099">firefox_binary=binary)<br><span style="color: #94558d">self.url=<span style="color: #ef3142">'https://passport.cnblogs.com/user/signin?ReturnUrl=https%3A%2F%2Fwww.cnblogs.com%2F'<br><span style="color: #ef3142"><br><span style="color: #ef3142"> <span style="color: #577999; font-style: italic">#<span style='color: #577999; font-style: italic; font-family: "宋体"'>定义登录的方法<br><span style='color: #577999; font-style: italic; font-family: "宋体"'> <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">login(<span style="color: #94558d">self,<span style="font-style: italic">username,<span style="font-style: italic">password):<br> driver=<span style="color: #94558d">self.driver<br> url=<span style="color: #94558d">self.url<br> driver.get(url)<br> driver.find_element_by_id(<span style="color: #ef3142">'input1').send_keys(<span style="font-style: italic">username)<br> driver.find_element_by_id(<span style="color: #ef3142">'input2').send_keys(<span style="font-style: italic">password)<br> driver.find_element_by_id(<span style="color: #ef3142">'signin').click()<br><br><span style="color: #577999; font-style: italic">#@unittest.skip(u'<span style='color: #577999; font-style: italic; font-family: "宋体"'>条件均正确暂时跳过<span style="color: #577999; font-style: italic">')<br><span style="color: #577999; font-style: italic"> <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_success(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username and password right'''<br><span style="color: #161b99; font-style: italic"> <span style="color: #94558d">self.login(<span style="color: #ef3142">'Qigege',<span style="color: #ef3142">'******')<br> time.sleep(<span style="color: #549937">2)<br> link=<span style="color: #94558d">self.driver.find_element_by_link_text(<span style="color: #ef3142">'Qigege')<br><span style="color: #94558d">self.assertTrue(<span style="color: #ef3142">'Qigege' <span style="color: #4038e3">in link.text)<br><span style="color: #577999; font-style: italic">#<span style='color: #577999; font-style: italic; font-family: "宋体"'>截图<br><span style='color: #577999; font-style: italic; font-family: "宋体"'> <span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">user_pwd.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>条件均正确<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold"> <span style="color: #577999; font-style: italic">#@unittest.skip(u'<span style='color: #577999; font-style: italic; font-family: "宋体"'>密码错误暂时跳过<span style="color: #577999; font-style: italic">')<br><span style="color: #577999; font-style: italic"> <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_pwd_error(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username right and password error'''<br><span style="color: #161b99; font-style: italic"> <span style="color: #94558d">self.login(<span style="color: #ef3142">'Qigege',<span style="color: #ef3142">'123123')<br> time.sleep(<span style="color: #549937">2)<br> link=<span style="color: #94558d">self.driver.find_element_by_id(<span style="color: #ef3142">'tip_btn')<br><span style="color: #94558d">self.assertTrue(<span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>用户名或密码错误<span style="color: #008080; font-weight: bold">',link.text)<br><span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">err_pwd.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>密码错误<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold"> <span style="color: #577999; font-style: italic">#@unittest.skip(u'<span style='color: #577999; font-style: italic; font-family: "宋体"'>密码为空暂时跳过<span style="color: #577999; font-style: italic">')<br><span style="color: #577999; font-style: italic"> <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_pwd_null(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username right and password null'''<br><span style="color: #161b99; font-style: italic"> <span style="color: #94558d">self.login(<span style="color: #ef3142">'Qigege',<span style="color: #ef3142">'')<br> time.sleep(<span style="color: #549937">2)<br> link=<span style="color: #94558d">self.driver.find_element_by_id(<span style="color: #ef3142">'tip_input2')<br><span style="color: #94558d">self.assertTrue(<span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>请输入密码<span style="color: #008080; font-weight: bold">' <span style="color: #4038e3">in link.text)<br><span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">null_pwd.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>密码为空<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold"> <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_user_err(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username error and password right'''<br><span style="color: #161b99; font-style: italic"> <span style="color: #94558d">self.login(<span style="color: #ef3142">'gege',<span style="color: #ef3142">'******')<br> time.sleep(<span style="color: #549937">2)<br> link=<span style="color: #94558d">self.driver.find_element_by_id(<span style="color: #ef3142">'tip_input2')<br><span style="color: #94558d">self.assertTrue(<span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>用户名或密码错误<span style="color: #008080; font-weight: bold">',link.text)<br><span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">err_user.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>用户名错误<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold"> <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_user_null(<span style="color: #94558d">self): '''username null and password right''' self.login('','******') link=self.driver.find_element_by_id('tip_input1') self.assertTrue(u'请输入登录用户名' in link.text) self.driver.get_screenshot_as_file('E:\\py-sql\\example\\pro5_note\\null_user.jpg') print u'用户名为空——测试用例' def tearDown(self): time.sleep(2) print u'测试完毕!' self.driver.quit()if __name__=='__main__': unittest.main()</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
以上是一次完整的自动化登录测试-2017-7-4的详细内容。更多信息请关注PHP中文网其他相关文章!

Python在游戏和GUI开发中表现出色。1)游戏开发使用Pygame,提供绘图、音频等功能,适合创建2D游戏。2)GUI开发可选择Tkinter或PyQt,Tkinter简单易用,PyQt功能丰富,适合专业开发。

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。 Python以简洁和强大的生态系统着称,C 则以高性能和底层控制能力闻名。

2小时内可以学会Python的基本编程概念和技能。1.学习变量和数据类型,2.掌握控制流(条件语句和循环),3.理解函数的定义和使用,4.通过简单示例和代码片段快速上手Python编程。

Python在web开发、数据科学、机器学习、自动化和脚本编写等领域有广泛应用。1)在web开发中,Django和Flask框架简化了开发过程。2)数据科学和机器学习领域,NumPy、Pandas、Scikit-learn和TensorFlow库提供了强大支持。3)自动化和脚本编写方面,Python适用于自动化测试和系统管理等任务。

两小时内可以学到Python的基础知识。1.学习变量和数据类型,2.掌握控制结构如if语句和循环,3.了解函数的定义和使用。这些将帮助你开始编写简单的Python程序。

如何在10小时内教计算机小白编程基础?如果你只有10个小时来教计算机小白一些编程知识,你会选择教些什么�...

使用FiddlerEverywhere进行中间人读取时如何避免被检测到当你使用FiddlerEverywhere...

Python3.6环境下加载Pickle文件报错:ModuleNotFoundError:Nomodulenamed...


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

记事本++7.3.1
好用且免费的代码编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

SublimeText3汉化版
中文版,非常好用