首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >请问大佬这个生成Allure报告,怎么能应用失败一条用例后自动截图啊 如果我有很多用例的话?

请问大佬这个生成Allure报告,怎么能应用失败一条用例后自动截图啊 如果我有很多用例的话?

提问于 2022-07-01 13:51:30
回答 0关注 0查看 68
代码语言:python
复制
import time
import pytest
import allure
from page import login_xpath
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


@allure.feature("项目登录测试")
class Test_leopardv5_Login():
    def setup(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get('*************')
        self.driver.implicitly_wait(10)

    def teardown(self):
        self.driver.quit()


    # 登录模块
    @pytest.mark.parametrize('casename,username,pwd,expect',
                             [
                                 ['正确的用户名错误的密码', 'admin', '32232', '用户名或密码错误'],
                                 ['错误的用户名密码', 'ad4min', '4343', '用户名或密码错误'],
                                 ['正确的用户名和正确的密码', 'admin4', 'admin', '控制台']
                             ])
    def test_login(self, casename, username, pwd, expect):
        allure.dynamic.title(casename)  # 用例名称
        allure.dynamic.description('登录模块测试用例')  # 用例描述‘
        with allure.step('step1:输入用户名'):
            self.driver.find_element(By.NAME, login_xpath.username).send_keys(username)
        with allure.step('step1:输入密码'):
            self.driver.find_element(By.NAME, login_xpath.pwd).send_keys(pwd)
        with allure.step('step1:点击登录按钮'):
            self.driver.find_element(By.CLASS_NAME, login_xpath.login_buttun).click()
        self.driver.implicitly_wait(10)
        time.sleep(2)
        if casename.__contains__('错误'):
            msg = self.driver.find_element(By.XPATH, login_xpath.errors).text
            WebDriverWait(self.driver, 5, poll_frequency=0.5, ignored_exceptions=None).until(
                EC.visibility_of_element_located((By.XPATH, login_xpath.errors)))
            assert msg == expect
        else:
            kongzhitai = self.driver.find_element(By.XPATH, login_xpath.kongzhi).text
            WebDriverWait(self.driver, 5, poll_frequency=0.5, ignored_exceptions=None).until(
                EC.visibility_of_element_located((By.XPATH, login_xpath.kongzhi)))
            assert kongzhitai == expect


if __name__ == '__main__':
    pytest.main()

回答

和开发者交流更多问题细节吧,去?写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com