首页 > 解决方案 > 我无法将屏幕截图附加到魅力报告

问题描述

正在生成报告,但 Allure 报告中缺少屏幕截图。我使用 kotlintest、selenide 和 Allure。我究竟做错了什么?

override fun afterTest(description: Description, result: TestResult) {
        if(result.status == Failure) {
            saveScreenshot()
        }
    }

    @Attachment(type = "image/png")
    fun saveScreenshot(): ByteArray {
        Screenshots.takeScreenShotAsFile()
        return Screenshots.getLastScreenshot().readBytes()
    }

在 allure-results 文件夹中以及文件 0afd689c-f8bc-444b-ac84-c4379c989f4b-result.json 以及附件 b7d40d19-4b08-47d2-b5c7-e4885685e3bd-attachment 中,但在生成报告后 - 它们不会显示在报告中。这是json文件的内容:

{"name":"test2","status":"failed","statusDetails":{"known":false,"muted":false,"flaky":false,"message":"Element should be visible {By.xpath: //div[contains(text(), \"УДОСТОВЕРЕНИЕ\")]}\nElement: '<div class=\"document-type mr-3 active\" displayed:false></div>'","trace":"Element should be visible {By.xpath: //div[contains(text(), \"УДОСТОВЕРЕНИЕ\")]}\nElement: '<div class=\"document-type mr-3 active\" displayed:false></div>'\nTimeout: 4 s.\n\tat com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:72)\n\tat com.codeborne.selenide.commands.Should.should(Should.java:35)\n\tat com.codeborne.selenide.commands.Should.execute(Should.java:29)\n\tat com.codeborne.selenide.commands.Should.execute(Should.java:12)\n\tat com.codeborne.selenide.commands.Commands.execute(Commands.java:144)\n\tat com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:99)\n\tat com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)\n\tat com.sun.proxy.$Proxy59.shouldBe(Unknown Source)\n\tat kz.btsd.did.steps.RegistrationSteps.shouldBeOnThirdStep_aroundBody8(RegistrationSteps.kt:68)\n\tat kz.btsd.did.steps.RegistrationSteps$AjcClosure9.run(RegistrationSteps.kt:1)\n\tat org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)\n\tat io.qameta.allure.aspects.StepsAspects.step(StepsAspects.java:50)\n\tat kz.btsd.did.steps.RegistrationSteps.shouldBeOnThirdStep(RegistrationSteps.kt:68)\n\tat kz.btsd.did.specs.RegistrationSpec$1$2.invoke(RegistrationSpec.kt:23)\n\tat kz.btsd.did.specs.RegistrationSpec$1$2.invoke(RegistrationSpec.kt:9)\n\tat io.kotlintest.runner.jvm.TestCaseExecutor$executeTestSet$$inlined$map$lambda$1.call(TestCaseExecutor.kt:104)\n\tat io.kotlintest.runner.jvm.TestCaseExecutor$executeTestSet$$inlined$map$lambda$1.call(TestCaseExecutor.kt:23)\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:834)\n"},"stage":"finished","description":"","steps":[{"name":"Подтверждение номера телефона","status":"passed","stage":"finished","steps":[],"attachments":[],"parameters":[{"name":"phoneNumber","value":"7201641700"}],"start":1563877016645,"stop":1563877017497},{"name":"Должен быть на третьем шаге регистрации","status":"failed","statusDetails":{"known":false,"muted":false,"flaky":false,"message":"Element should be visible {By.xpath: //div[contains(text(), \"УДОСТОВЕРЕНИЕ\")]}\nElement: '<div class=\"document-type mr-3 active\" displayed:false></div>'","trace":"Element should be visible {By.xpath: //div[contains(text(), \"УДОСТОВЕРЕНИЕ\")]}\nElement: '<div class=\"document-type mr-3 active\" displayed:false></div>'\nTimeout: 4 s.\n\tat com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:72)\n\tat com.codeborne.selenide.commands.Should.should(Should.java:35)\n\tat com.codeborne.selenide.commands.Should.execute(Should.java:29)\n\tat com.codeborne.selenide.commands.Should.execute(Should.java:12)\n\tat com.codeborne.selenide.commands.Commands.execute(Commands.java:144)\n\tat com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:99)\n\tat com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)\n\tat com.sun.proxy.$Proxy59.shouldBe(Unknown Source)\n\tat kz.btsd.did.steps.RegistrationSteps.shouldBeOnThirdStep_aroundBody8(RegistrationSteps.kt:68)\n\tat kz.btsd.did.steps.RegistrationSteps$AjcClosure9.run(RegistrationSteps.kt:1)\n\tat org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)\n\tat io.qameta.allure.aspects.StepsAspects.step(StepsAspects.java:50)\n\tat kz.btsd.did.steps.RegistrationSteps.shouldBeOnThirdStep(RegistrationSteps.kt:68)\n\tat kz.btsd.did.specs.RegistrationSpec$1$2.invoke(RegistrationSpec.kt:23)\n\tat kz.btsd.did.specs.RegistrationSpec$1$2.invoke(RegistrationSpec.kt:9)\n\tat io.kotlintest.runner.jvm.TestCaseExecutor$executeTestSet$$inlined$map$lambda$1.call(TestCaseExecutor.kt:104)\n\tat io.kotlintest.runner.jvm.TestCaseExecutor$executeTestSet$$inlined$map$lambda$1.call(TestCaseExecutor.kt:23)\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:834)\n"},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1563877017497,"stop":1563877021573}],"attachments":[],"parameters":[],"start":1563877016644,"stop":1563877022306,"uuid":"0afd689c-f8bc-444b-ac84-c4379c989f4b","historyId":"85f46c0c13deba1911ce55e0e9ebd254","labels":[{"name":"host","value":"npa"},{"name":"thread","value":"30600@npa.kotlintest-test-executor-0(41)"}],"links":[]}

这是我的 build.gradle

import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
    kotlin("jvm")
    kotlin("plugin.spring")
    id("org.springframework.boot")
    id("io.spring.dependency-management")
    id("io.qameta.allure") version "2.8.1"
}

dependencyManagement {
    imports {
        mavenBom("org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE")
    }
}

repositories {
    maven("https://nexus.mycompany.com/repository/proxy-all/")
}

tasks {
    withType<Test> {
        useJUnitPlatform {}
        systemProperty("allure.results.directory", "build/allure-results")
        systemProperty("browser", System.getProperty("browser"))
    }
}

tasks.getByName<BootJar>("bootJar") {
    enabled = false
}

dependencies {
    val kotlinTestVersion = "3.1.9"
    val selenideVersion = "5.19.0"

    testImplementation(project(":autotests-commons"))

    testImplementation("org.springframework.boot:spring-boot-starter")
    testImplementation("org.springframework.boot:spring-boot-starter-web")
    testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    testImplementation("org.apache.httpcomponents:httpclient")
    testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    testImplementation("io.kotlintest:kotlintest-extensions-spring:$kotlinTestVersion")
    testImplementation("io.kotlintest:kotlintest-runner-junit5:$kotlinTestVersion")
    testImplementation ("io.kotlintest:kotlintest-extensions-allure:$kotlinTestVersion")

    testImplementation("com.codeborne:selenide:$selenideVersion")
    testImplementation("io.qameta.allure:allure-selenide:2.8.1")
    testImplementation("com.google.guava:guava:23.6-jre")
    testRuntimeOnly("io.qameta.allure:allure-junit5:2.8.1")
}

val allureVersion = "2.13.8"

allure {
    version = allureVersion
    autoconfigure = true
    aspectjweaver = true
    configuration = "testImplementation"
    clean = true
    useJUnit5 {
        version = allureVersion
    }
}

标签: allure

解决方案


推荐阅读