一、基础环境准备

1.Chrome + Chrome Driver

https://www.cnblogs.com/TSmagic/p/15671533.html(此篇文章已经介绍)

2.Selenium + Python

pip install selenium
pip show selenium

Python环境安装就不多做介绍啦!

3.Jenkins

https://www.cnblogs.com/TSmagic/p/15080407.html(此篇文章已经介绍)

4.测试代码

# coding=utf-8

# lm-ui—test—demo-博客园
from selenium import webdriver
import time
import unittest class daTestCase(unittest.TestCase):
def setUp(self):
global driver
chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument('--headless') #浏览器无窗口加载
chromeOptions.add_argument('--disable-gpu') #不开启GPU加速 """
解决报错:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
"""
chromeOptions.add_argument('--disable-dev-shm-usage') #禁止
chromeOptions.add_argument('--no-sandbox')#以根用户打身份运行Chrome,使用-no-sandbox标记重新运行Chrome #其它设置(可选):
chromeOptions.add_argument('--hide-scrollbars') #隐藏滚动条, 应对一些特殊页面
chromeOptions.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度 #创建driver对象
#chrome_options=chromeOptions加载设置
#executable_path="/usr/bin/chromedriver"指定webdriver路径(可选)
driver = webdriver.Chrome(chrome_options=chromeOptions,executable_path="/usr/bin/chromedriver")
print(u"加载驱动完成..")
driver.get("你的测试地址")
print(u"加载页面完成..")
time.sleep(2)
#self.driver.maximize_window() # 浏览器全屏显示 def test_login1(self):
global driver
driver.find_element_by_xpath("//input[@placeholder='请输入账号']").send_keys("daui")
driver.find_element_by_xpath("//input[@placeholder='请输入密码']").send_keys("Qwe123456")
driver.find_element_by_xpath("//*[@id=\"app\"]/div/div[5]/div/div/div/div[6]/button").click()
#self.driver.save_screenshot('D:/1.png') # 截图
print(u"case1:正确账号密码登录成功") def test_login2(self):
global driver
driver.find_element_by_xpath("//input[@placeholder='请输入账号']").send_keys("111st")
driver.find_element_by_xpath("//input[@placeholder='请输入密码']").send_keys("Qwe123456")
driver.find_element_by_xpath("//*[@id=\"app\"]/div/div[5]/div/div/div/div[6]/button").click()
#self.driver.save_screenshot('D:/2.png') # 截图
print(u"case2:账号错误登录失败") def test_login3(self):
global driver
driver.find_element_by_xpath("//input[@placeholder='请输入账号']").send_keys("daui")
driver.find_element_by_xpath("//input[@placeholder='请输入密码']").send_keys("1qwe123")
driver.find_element_by_xpath("//*[@id=\"app\"]/div/div[5]/div/div/div/div[6]/button").click()
#self.driver.save_screenshot('D:/3.png') # 截图
print(u"case3:密码错误登录失败") def tearDown(self):
global driver
print(u'用例执行完成..')
print(u"")
driver.quit() # 退出浏览器 if __name__ == '__main__':
unittest.main()

  

5.运行效果

1.png

2.png

to be continued...

最新文章

  1. svn patch
  2. 用代码定位硬盘上的文件(使用ShellExecute执行explorer /select命令,其它参数也很全)
  3. Windows下一个AndroidStudio 正在使用Git(AndroidStudio工程GitHub关联)
  4. struts2.5新配置动态调用
  5. javaWeb学习总结(7)-关于session的实现:cookie与url重写
  6. 解决asp.net MVC中 当前上下文中不存在名称“model” 的问题
  7. html点小图看大图最快捷的方法
  8. Java多线程JUC
  9. miniui几个常用知识点汇总
  10. mybatis if test 判断字符串的坑
  11. Linux系统一些常用命令(持续增加)
  12. Linux rpm包安装不了
  13. VC,VB操作XML
  14. SQL Server中的数据类型
  15. eclipse主题皮肤设置
  16. 简单认识python的数据类型和语法
  17. jQuery懒加载插件 – jquery.lazyload.js
  18. return 返回字符串
  19. .NET计时器的使用-Stopwatch类
  20. SFTP无法连接 Connection closed by server with exitcode 127

热门文章

  1. SQL Network Interfaces, error: 50 - 发生了 Local Database Runtime 错误。无法创建自动实例
  2. lnmp重新安装mysql
  3. [Unity移动端]gradle打包
  4. 【其他】etcd
  5. https加固,https://ip暴露后端IP。
  6. Java - JDBC批量插入原理
  7. 数据库中1NF,2NF,3NF的判别
  8. PicGo+Typora+Github图床配置步骤(一键上传本地图片)
  9. 同步协程的必备工具: WaitGroup
  10. java 企业级开发中常见的注入方式