Simple Allure 2 configuration for Gradle

Aliaksandr Rasolka
2 min readMay 11, 2018

--

From many time past it’s easy to configure allure with Gradle

“Green plants covering the walls of a multi-story building” by 贝莉儿 NG on Unsplash

For first you need to apply allure gradle plugin. I’m using latest gradle version so let’s use new plugin applying mechanism.

plugins {
id 'io.qameta.allure' version '2.8.1'
}

Next step will be about configuration. In my test I’m using Junit5 and I want to use latest allure version so I’ll manually pass latest version in config and also I have to use custom download link format to get a latest version of allure commandline.

allure {
version = '2.14.0'
}

Last but not least — tools integration. There are many of integration, I’m showing my set:

  1. Junit5
  2. Selenide
  3. Retforit/Okhttp

I’m going to apply this integration as dependencies.

Retforit/Okhttp. I’m using implementation scope because it’s required some code changes to work property:

dependencies {
implementation('io.qameta.allure:allure-okhttp3:2.14.0')
}

Code changes — it’s just additional Okhttp client interceptor:

final AllureOkHttp3 allureOkHttp3 = new AllureOkHttp3();final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(allureOkHttp3)
.build();

Junit5 integration isn’t required any code changes, just place it in right scope, use testRuntimeOnly scope for that:

dependencies {
testRuntimeOnly('io.qameta.allure:allure-junit5:2.14.0')
}

That’s all.

Selenide integration also required some code changes, but lets apply testImplementation scope because it’s required only SelenideLogger listener registration that can be done before tests:

dependencies {
testImplementation('io.qameta.allure:allure-selenide:2.14.0')
}

Code changes — add listener on BeforeAll step:

@BeforeAll
public void setUp() {
SelenideLogger.addListener("allure", new AllureSelenide());
}

And don’t forget to remove listener after tests. Let’s do it on AfterAll step:

@AfterAll
public void tearDown() {
SelenideLogger.removeListener("allure");
}

I’m also advise to create allure property file and point results directory to avoid miss target results creation. I’m place it inside src/test/resources folder and call it allure.properties and add content:

allure.results.directory=build/allure-results

Great! Now you’re all done.

From now you just need to execute your test and after tests run gradle task allureReport that creates Allure report or allureServethat creates Allure report and opens it in the default browser.

Happy testing! D_D

You can find complete project on GitHub.

--

--