1 代码框架
2 单模块运行
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: TestJohnDeere.py
Author : 曾良均
QQ: 277099728
Date: 12/1/2023 4:03 PM
Description :
-------------------------------------------------
Change Activity:
-------------------------------------------------
"""
__author__ = 'ljzeng'
import pytest
from Common.logger import Log
from Common.Operator import *
from Common.Logins import Logins
from Page.Credentials.CredentialsPage import CredentialsPage as cp
from selenium.webdriver.common.by import By
import allure
log = Log("TestJohnDeere")
class TestJohnDeere:
driver = None
lg = None
page = None
coll = (By.XPATH, '//*[@id="nav_arrow"]/div')
@pytest.fixture()
def begin(self):
log.info('--------开始测试John Deere Credentials功能--------')
self.driver = browser("chrome")
self.lg = Logins()
self.lg.login(self.driver, 'atcred@iicon004.com', 'Win.12345')
self.driver.implicitly_wait(10)
self.page = cp()
ac = self.lg.get_attribute(self.coll, 'class')
while True:
if ac != 'icn collapse':
ar = (By.ID, 'nav_arrow')
self.page.click(ar)
continue
else:
break
self.lg.click(self.page.johndeere_menu)
time.sleep(1)
self.lg.switch_to_iframe(self.page.right_iframe)
yield self.lg
self.driver.quit()
def add_jdlink(self, begin):
log.info('点击 JD Link 的Add')
if not begin.is_clickable(self.page.jdlink_add_btn):
time.sleep(2)
try:
begin.click(self.page.jdlink_add_btn)
time.sleep(1)
self.driver.switch_to.window(self.driver.window_handles[1])
time.sleep(2)
txt = begin.get_text(self.page.jdlink_page_signin_lable)
except Exception:
log.info('Add 跳转失败!')
return False
else:
log.info('Add 跳转成功!')
self.driver.switch_to.window(self.driver.window_handles[0])
if txt == 'Sign In':
return True
else:
return False
@allure.feature("测试Credentials功能")
@allure.story("测试JD Link Credentials设置功能")
def test_addJDlink(self, begin):
"""测试Add JD Link功能"""
res = self.add_jdlink(begin)
if res:
log.info('Add JD Link 测试成功!')
else:
log.info('Add JD Link 测试失败!')
assert res
if __name__ == '__main__':
pytest.main(['-vs', 'TestJohnDeere.py']) # 主函数模式
pytest.main([‘-vs‘, ‘TestJohnDeere.py‘])
3 主函数运行指定用例
3.1 pytest.ini定义要执行的用例文件、类、方法
[pytest]
addopts=-vs
testpaths=./TestCase
python_files=Test*.py
python_classes=Test
python_functions=test
markers=
smoke:
uermanage:
3.2 主函数运行(run.py)
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: run.py
Author : 曾良均
QQ: 277099728
Date: 12/4/2023 9:27 AM
Description : 这是所有测试用例运行的主函数
-------------------------------------------------
Change Activity:
-------------------------------------------------
"""
__author__ = 'ljzeng'
import pytest
import os
if __name__ == '__main__':
pytest.main(['-s', '-q', '--clean-alluredir', '--alluredir=allure-results'])
os.system(r"copy environment.properties allure-results\")
os.system(r"allure generate -c -o Reportallure-report")
# os.system(r"allure open Reportallure-report") # 此命令会打开报告
4 查看Allure报告
allure open Reportallure-report
5 遇到的问题
5.1 allure-results does not exists
当pytest.main中指定的–alluredir不是allure-results时,后面执行allure generate会把如题错误
解决方法:指定 —alluredir=allure-results 即可
原文地址:https://blog.csdn.net/zljun8210/article/details/134812223
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_47974.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。