Docs
Reports
You probably don't need fancy reports: Selenide's error messages already tell the whole story. If you still want them, there's a built-in text report and an Allure integration.
YAGNI
First of all, think twice: you probably don’t need any special reports.
Gradle and Maven already generate decent test reports with all the errors. When a test fails, Selenide already produces a detailed error message, including a screenshot and the HTML of the page. Usually that’s enough to understand why the test failed:
Element should be hidden {#gameWin}
Element: '<img class="gameOver" id="gameWin" src="img/thumbs-up.jpeg"></img>'
Screenshot: file:/.../hangman/build/reports/tests/1510751914648.0.png
Page source: file:/.../hangman/build/reports/tests/1510751914648.0.html
Timeout: 4 s.
If you still want reports, there are two options: the text report and the Allure report.
Text report
A simple report built into Selenide. It shows every step performed during the test:
+----------------------+---------------------------------------------+--------+----------+
|Element |Subject |Status |ms. |
+----------------------+---------------------------------------------+--------+----------+
|open |http://localhost:2070/ |PASSED |4669 |
|open |http://localhost:2070/fakeLogin?username=bob |PASSED |1324 |
|By.linkText: Quicky |click() |PASSED |793 |
|#btn-message-reply |click() |PASSED |1002 |
|By.name: message.text |should be(focused) |PASSED |57 |
|By.name: message.text |should have(text 'long thread') |PASSED |47 |
|By.name: message.text |set value(Hello world!) |PASSED |69 |
|#send-button |click() |PASSED |1051 |
|.alert-success |should be(visible) |PASSED |71 |
+----------------------+---------------------------------------------+--------+----------+
It looks simple, but it has all the information you need. To enable it:
- Set up slf4j in your project (slf4j is the de-facto standard logging API in Java).
- Add the extension, listener or rule for your test framework:
import com.codeborne.selenide.junit5.TextReportExtension;
@ExtendWith({TextReportExtension.class})
public class MyTest {
// ...
}
import com.codeborne.selenide.testng.TextReport;
@Listeners({TextReport.class})
public class MyTest {
// ...
}
import com.codeborne.selenide.junit.TextReport;
public class MyTest {
@Rule
public TextReport textReport = new TextReport();
// ...
}
Allure report
QA engineers often want “beautiful” reports. They’re for managers, they say. We’re rather skeptical: managers rarely read them. Think twice before you spend time on beautifying reports.
If you still insist, set up Allure, a popular open-source reporting tool from Qameta Software. It has a built-in Selenide integration, and yes, its reports look really nice. :)
- Add the dependency
io.qameta.allure:allure-selenide(the latest version) to your project. - Add the listener at the beginning of your tests:
@BeforeAll
static void setupAllureReports() {
SelenideLogger.addListener("AllureSelenide", new AllureSelenide());
// or, for fine-tuning:
SelenideLogger.addListener("AllureSelenide", new AllureSelenide()
.screenshots(false)
.savePageSource(true)
);
}
See the sample project Selenide + Allure.
SelenideLogger.addListener must be called in the same thread as the test itself.
Some test frameworks run @BeforeAll and @Test methods in different threads, and then your listener gets no events from the test.
In that case, move the initialization to a @BeforeEach or even the @Test method.P.S. But please, PLEASE don’t adopt BDD for the nice reports! BDD isn’t meant for reports. It’s a development process. If you only apply it technically, without changing the process, it will just create more problems.
Didn't find the answer?
Ask the community, we answer fast: Selenide examples · Telegram · Report an issue