我正在使用 pytest.mark.parametrize 进行数据驱动测试。现在,当我生成 html 报告时,测试用例名称如下所示,其中包括所有参数(数据)。我的目标是仅捕获“test_RSA_Health”之类的测试用例名称,并从报告的“测试”列中删除所有其他详细信息。可能吗?
我的代码:conftest
import time
import allure
import pytest
from allure_commons.types import AttachmentType
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from Utilities.filepath import *
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
test_fn = item.obj
docstring = getattr(test_fn, '__doc__')
if docstring:
rep.nodeid = docstring
return rep
@pytest.fixture(scope="function")
def selenium_driver(request):
chrome_options = Options()
chrome_options.add_argument("--headless")
# chrome_options.add_argument("--window-size=1920,1080")
# chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument("--disable-extensions")
# chrome_options.add_argument('disable-infobars')
s = Service("C:\\Users\\aprat\\OneDrive\\Desktop\\selenium\\chromedriver98\\chromedriver.exe")
url = "https:test.com"
driver = webdriver.Chrome(service=s, options=chrome_options)
driver.maximize_window()
driver.set_window_size(1200, 600)
driver.get(url)
driver.find_element(By.NAME, "user_name").send_keys("9998887776")
driver.find_element(By.NAME, "password_name").send_keys("qwerty123")
driver.find_element(By.XPATH, "//button[@type= 'submit']").click()
time.sleep(3)
request.cls.driver = driver
yield driver
driver.close()
@pytest.fixture()
def log_on_failure(request, selenium_driver):
yield
item = request.node
driver = selenium_driver
if item.rep_call.failed:
allure.attach(driver.get_screenshot_as_png(), name="screenshot", attachment_type=AttachmentType.PNG)
测试脚本:
import time
import pytest
from Pages.HomePage import HomePage
from TestCases.BaseTest import BaseTest
from Utilities import dataProvider
class Test_RSA_Health(BaseTest):
@pytest.mark.parametrize("pin,sumvalue,mobileno,selfage,fullname,email,firstname,lastname,dob,income,pan,designation,add1,add2,height,weight,nomfirstname,nomlastname,nomdob", dataProvider.get_data("rsa_health"))
def test_RSA_Health(self,pin,sumvalue,mobileno,selfage,fullname,email,firstname,lastname,dob,income,pan,designation,add1,add2,height,weight,nomfirstname,nomlastname,nomdob):
home = HomePage(self.driver)
healthinsuranepage = home.SelectHealth()
self.VerifyPresence_PinCodeTextBox()
healthinsuranepage.landing_page()
healthinsuranepage.InputPin(pin)
healthinsuranepage.SelectSum(str(sumvalue))
healthinsuranepage.InputMobileNo(mobileno)
insureddetailspage = healthinsuranepage.ClickNext()
self.VerifyPresence_SelfCheckBox()
insureddetailspage.landing_page()
insureddetailspage.SelectMemberSelf()
self.VerifyPresence_SelfAgeTextBox()
insureddetailspage.InputAge(selfage)
time.sleep(2)
quotespage = insureddetailspage.ClickNext()
time.sleep(5)
quotespage.landing_page()
quotespage.ShareQuotes()
time.sleep(3)
quotespage.SelectAllQuotes()
time.sleep(2)
quotespage.ClickNext1()
self.VerifyPresence_NameTextBox()
quotespage.InputName(fullname)
quotespage.InputEmail(email)
quotespage.InputMobileNo(mobileno)
time.sleep(2)
quotespage.ClickSubmit()
time.sleep(2)
self.VerifyPresence_CloseButton()
time.sleep(2)
quotespage.ClickCloseButton()
time.sleep(2)
policydetailspage = quotespage.RSAPlanSelect()
time.sleep(3)
propdetailspage = policydetailspage.ConfirmTenure()
policydetailspage.landing_page()
self.VerifyPresence_FirstNameTextBox()
propdetailspage.landing_page()
propdetailspage.InputFirstName(firstname)
propdetailspage.InputLastName(lastname)
propdetailspage.InputDOB(dob)
propdetailspage.SelectPropGender()
propdetailspage.InputEmailId(email)
propdetailspage.InputContactNo(mobileno)
propdetailspage.InputIncome(income)
propdetailspage.InputPANCard(pan)
propdetailspage.SelectOccupationDropdown()
self.VerifyPresence_SelectOccupationOption()
propdetailspage.SelectOccupation()
propdetailspage.InputDesignation(designation)
propdetailspage.SelectMaritalStatusDropdown()
self.VerifyPresence_MaritalStatusOption()
propdetailspage.SelectMaritalStatus()
propdetailspage.SelectEducationDropdown()
self.VerifyPresence_QualificationOption()
propdetailspage.SelectQualification()
propdetailspage.SelectTPANameDropdown()
self.VerifyPresence_TPANameOption()
propdetailspage.SelectTPA()
propdetailspage.InputAdd1(add1)
propdetailspage.InputAdd2(add2)
selfdetailspage = propdetailspage.ClickNext()
self.VerifyPresence_SelfFirstNameTextBox()
selfdetailspage.landing_page()
selfdetailspage.InputSelfFirstName(firstname)
selfdetailspage.InputSelfLastName(lastname)
selfdetailspage.InputSelfDOB(dob)
selfdetailspage.SelectSelfGender()
selfdetailspage.InputSelfHeight(height)
selfdetailspage.InputSelfWeight(weight)
selfdetailspage.InputSelfDesignation(designation)
selfdetailspage.InputNomineeFName(nomfirstname)
selfdetailspage.InputNomineeLName(nomlastname)
selfdetailspage.InputNomineeDOB(nomdob)
selfdetailspage.SelectNomineeGender()
selfdetailspage.SelectNomineeRltnDropdown()
self.VerifyPresence_NomRelationOption()
selfdetailspage.SelectNomineeRelation()
questionariespage = selfdetailspage.ClickNext()
time.sleep(4)
questionariespage.landing_page()
policyreviewpage = questionariespage.ClickNext()
self.VerifyPresence_NameValidationText()
policyreviewpage.landing_page()
proposer_name = policyreviewpage.GetName()
proposer_email = policyreviewpage.GetEmail()
proposer_mobno = policyreviewpage.GetPhoneNo()
try:
assert proposer_name == fullname
assert proposer_email == email
assert int(proposer_mobno) == mobileno
except Exception as e:
raise e
policyreviewpage.FinalSubmit()
self.VerifyPresence_ShareButton()
policyreviewpage.SharePolicy()