allure - 我无法将屏幕截图附加到魅力报告
问题描述
正在生成报告,但 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
}
}
解决方案
推荐阅读
- c# - 平均 - EF 通用存储库
- sql - 在印度编号系统中将数字转换为单词
- html - 在每张幻灯片上插入文本
- regex - VBA如何在单元格中的用户输入上使用正则表达式
- mysql - 某列的分组最大值有问题
- apache-spark - Spark合并两个数据帧并通过覆盖第二个数据帧的值来创建一个数据帧
- python-3.x - 使用python和opencv进行直方图均衡而不使用内置函数
- shell - 将文件拆分为多个文件并将它们放入单独的文件夹中
- c# - ffmpeg rtsp 流到 YouTube 直播没有做任何事情
- mysql - 如何将mysql转换为laravel中的查询生成器