摘要:简单记录一些在使用自动化测试使用到的一些操作
pytest --html=report.html --self-contained-html
pip show 包名
# 生成allure 测试报告
0、需要将bin下的信息配置到path变量,如果电脑没有我的电脑logo 可以使用控制面板 搜索高级系统设置进入对应的配置页面,可以将对应的path加到最上面,方便检索
2、pytest test_allure_demo.py --alluredir ./reportcache
3、allure generate reportcache -o allure --clean
4、在allure.yml添加
- custom-logo-plugin
进入
/usr/local/Cellar/allure/2.10.0/libexec/plugins/custom-logo-plugin/static
5.编辑styles.css
.side-nav__brand {
background: url('logo.png') no-repeat left center !important;
margin-left: 10px;
background-size :1px 1px!important;
}
.side-nav__brand span{
display: none;
}
.side-nav__brand:after{
content: "Oceania";
margin-left: -25px;
font-size:33px;
}
6、修改title 自定义JS
在yml中增加
jsFiles:
- index.js
document.title = 'Oceania Report';
1、下载对应chroemderiver.exe
2、将对应文件放到谷歌安装目录, 可以再浏览器通过chrome://version查看安装位置
3、将C:\Program Files\Google\Chrome\Application 放到PATH中
4、将对应driver文件放到python安装目录中(需要注意多个python同时存在的时候需要将对应文件放到执行的这个python版本对应的安装目录中去)
conftest.py
@pytest.fixture(scope='session', autouse=True)
def browser():
"""
定义一个总的调用driver的方法,用例中直接调用browser
:return:
"""
global driver
if driver is None:
driver = webdriver.Chrome()
return driver
具体测试case中(class不需要引入)
@allure.story('主题显示') # 模块级别,二级标签
@allure.title('用例标题:test_004') # 三级标签
def test_004(self, browser):
browser.get("https://xxx.com/")
browser.find_element_by_xpath("/html/body/div[1]/div[2]/form/input[1]").send_keys('xxx')
browser.find_element_by_xpath("/html/body/div[1]/div[2]/form/input[2]").send_keys('xxx')
browser.find_element_by_xpath("/html/body/div[1]/div[2]/form/input[3]").click()
assert 1 != 1
browser.quit()
Settings->Python Interpreter->选择python-》点击show all 将对应的地址设置为本地Python安装的路径
listener.py 文件位置:Lib\site-packages\allure_pytest\listener.py (第三方包所在的LIb目录) 将下图中红色部分test_result.parameters.extend([]) 中参数改成空列表就行了
推荐使用2020.3.5 可以使用免费的Materia 主题插件
下载地址如下:https://www.jetbrains.com/pycharm/download/other.html