Centos7.x 使用 selenium + python + jenkins 做UI自动化
2024-09-08 16:25:08
一、基础环境准备
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...
最新文章
- svn patch
- 用代码定位硬盘上的文件(使用ShellExecute执行explorer /select命令,其它参数也很全)
- Windows下一个AndroidStudio 正在使用Git(AndroidStudio工程GitHub关联)
- struts2.5新配置动态调用
- javaWeb学习总结(7)-关于session的实现:cookie与url重写
- 解决asp.net MVC中 当前上下文中不存在名称“model” 的问题
- html点小图看大图最快捷的方法
- Java多线程JUC
- miniui几个常用知识点汇总
- mybatis if test 判断字符串的坑
- Linux系统一些常用命令(持续增加)
- Linux rpm包安装不了
- VC,VB操作XML
- SQL Server中的数据类型
- eclipse主题皮肤设置
- 简单认识python的数据类型和语法
- jQuery懒加载插件 – jquery.lazyload.js
- return 返回字符串
- .NET计时器的使用-Stopwatch类
- SFTP无法连接 Connection closed by server with exitcode 127
热门文章
- SQL Network Interfaces, error: 50 - 发生了 Local Database Runtime 错误。无法创建自动实例
- lnmp重新安装mysql
- [Unity移动端]gradle打包
- 【其他】etcd
- https加固,https://ip暴露后端IP。
- Java - JDBC批量插入原理
- 数据库中1NF,2NF,3NF的判别
- PicGo+Typora+Github图床配置步骤(一键上传本地图片)
- 同步协程的必备工具: WaitGroup
- java 企业级开发中常见的注入方式