April 23, 2024

What’s Attract and what’s it used for

Attract is an open-source framework that’s designed to create stunning, interactive, and easy-to-read experiences for automated checks. It permits builders and testers to create detailed and significant experiences of their check outcomes and will be built-in with numerous check frameworks equivalent to JUnit, TestNG, and extra.

Why Attract particularly?

Attract is a well-liked selection amongst builders and testers for creating check experiences due to its ease of use and suppleness. The framework is extremely customizable and permits builders to create experiences which are tailor-made to their particular wants. Moreover, Attract gives a variety of options, together with the flexibility to create detailed check suites, the flexibility to incorporate screenshots, and the flexibility so as to add customized information to the report.

On this article we’ll see how one can set up Attract to your challenge, how one can generate experiences and how one can use annotations to present your experiences extra which means. I’ll show attract’s capabilities on a small Selenium UI auto testing challenge.

Set up


In an effort to use Attract with Gradle in your challenge you have to so as to add a number of dependencies to tasks’ construct.gradle file:

  • testImplementation group: ‘org.aspectj’, identify:
    ‘aspectjweaver’, model: ‘wanted model’
  • testImplementation group: ‘io.qameta.attract’, identify:
    ‘allure-java-commons’, model: ‘wanted model’
  • testImplementation group: ‘io.qameta.attract’, identify:
    ‘allure-junit5’, model: ‘wanted model’
  • testImplementation group: ‘io.qameta.attract’, identify:
    ‘allure-commandline’, model: ‘wanted model’
  • testImplementation group: ‘io.qameta.attract’, identify:
    ‘allure-assertj’, model: ‘wanted model’

You’ll want so as to add Attract plugin into plugins part of your construct.gradle file as nicely:

  • id “io.qameta.attract” model “wanted model”

This can add “allureServe” and “allureReport” to your gradle verification duties.

After constructing the challenge and downloading all of the information from dependencies you can begin implementing Attract to your challenge.


For Maven it’s a fairly easy course of as nicely. You’ll want to switch your pom.xml file:

<aspectj.model>wanted model</aspectj.model>
<attract.model>wanted model</attract.model>



            <model>wanted model</model>


                       <model>wanted model</model>
                         <reportVersion>wanted model</reportVersion>

Don’t neglect to exchange wanted model with the model you want.

This may even add all the required dependencies and plugins to your challenge, and after constructing the challenge Attract will likely be prepared.

Organising challenge

We’ll start with a small Selenium check that opens Google.com, enters textual content into the search discipline, clicks the search button, and verifies that the searched textual content is current on the outcomes web page. We’ll discover each the Web page Object Mannequin (POM) method and the non-POM method.

Let’s begin with the POM method, which is the popular methodology for organizing UI automated testing frameworks. Moreover, we’ll be capable to showcase Attract annotations. We’ll create two lessons for this goal: GooglePage and GoogleSearchPomTest. The GooglePage class will comprise our parts with locators and the strategies that take care of these parts. The GoogleSearchPomTest class will comprise our check logic.

The challenge will likely be out there in its entirety on GitHub repository. You possibly can obtain it and discover how every little thing is finished.

GooglePage class.

GoogleSearchPomTest class.

To maintain issues easy, I gained’t be making a separate class for the search outcomes web page. Since we solely must work together with one aspect on the outcomes web page, I’ll embody it within the current GooglePage class.

Producing report

As soon as every little thing is about up, we are able to generate the primary Attract report by working our checks for the primary time. This can create folders within the construct listing of our challenge the place the outcomes of the check runs will likely be recorded. Attract can then use these outcomes to generate a report. To generate an Attract report, run both “./gradlew allureServe” or choose the “allureServe” possibility in your Gradle duties.

Working “allureServe” will launch the Attract net service in your native machine and open an HTML web page in your browser. This web page will present an outline of the check run.

The overview web page shows numerous parts showcasing the outcomes of your check run. A very powerful of those is the “Suites” block, which exhibits the check lessons that had been run. Moreover, there’s a graphical illustration of the amount of checks above it. Clicking on a set will permit you to see which checks had been included and the steps they contained.

In our instance, there was just one check methodology. Attract routinely designates strategies annotated with “@BeforeEach” and “@AfterEach” as “Arrange” and “Tear down” steps, respectively. Nevertheless, it doesn’t show any steps inside the check methodology itself.

Customizing report

One of many principal options of Attract is its annotations, which permit customers to customise the report back to make it extra readable. At present, the report doesn’t present a lot data.

To enhance it, we are able to begin by utilizing the “@Proprietor(‘Proprietor’s identify and place’)” annotation. We are able to annotate check lessons with this annotation to point the proprietor of the checks.

After including the “@Proprietor” annotation to our check lessons, we have to rerun the checks and generate a brand new Attract report utilizing “allureServe”. As soon as the brand new report is generated, we’ll be capable to see the proprietor part with the identify included.

By including the “@Proprietor” annotation to our check lessons, anybody who views the report will know who to contact if there are any points with the checks.

Subsequent, we are able to enhance the report even additional by utilizing the “@DisplayName(‘Take a look at identify’)” annotation. We are able to add this annotation to every check class and check methodology to offer a transparent, descriptive identify for every suite and methodology within the report.

We have to generate the report yet one more time.

By including the “@DisplayName” and “@Proprietor” annotations to our check lessons and check strategies, the report has develop into extra readable for non-technical stakeholders equivalent to managers.

In some instances, it’s essential to offer an outline of how a check works and what it does. We are able to use the “@Description(‘description’)” annotation to realize this. This annotation will be added to each check methodology in a set, identical to “@DisplayName”.

This can present the outline on the allures web page of the check case.

To make the Attract report much more informative, we are able to add the “@Step(‘step description’)” annotation to every methodology in our web page object. This enables any exceptions that happen in the course of the check run to be displayed within the corresponding step.

To implement this, we are able to return to the GooglePage class and add the “@Step” annotation with a descriptive textual content to every methodology.

Now within the report we are able to see that our steps are displayed.

And if our step strategies have any parameters they are going to be displayed as nicely.

Attract additionally gives the length of every check methodology, which will help in optimizing check efficiency.

If you don’t want to use the web page object mannequin in your framework and wish to work together with WebDriver instantly, you need to use the static methodology “step()” offered by Attract. This methodology lets you outline a step with a reputation and go the interplay with the motive force as a lambda by way of the ThrowableRunnableVoid (for interactions not returning any worth) or ThrowableRunnable<T> (for interactions returning one thing) useful interfaces as parameters. The ensuing steps will likely be included within the report, making it extra informative.

Even with this little quantity of customization our report already appears fairly informative and straightforward to learn and perceive. Now we are able to add a degree of severity to our checks. So as to add a degree of severity to our checks, we are able to use the @Severity() annotation, which permits us to specify the extent of severity for every check. The severity degree will be chosen from the SeverityLevel enum.

This can change the severity degree within the report. Word that by default severity degree is about to “Regular”.

Now let’s see what a failed check goes to appear like. Let’s change our isSearchedTextInHeader methodology to anticipate false as an alternative of true.

Now we are able to see now we have failed checks in our run. Let’s see what data now we have inside.

The Attract report shows the variety of failed checks in our suite, identifies the step the place an exception occurred, and presents a related a part of the stack hint. Moreover, Attract distinguishes between failed and damaged checks. We applied a code block that features a 300-millisecond look ahead to the search button to develop into clickable in each checks. If we remark out this step in one of many checks, the motive force could also be too fast to click on the button, leading to an “aspect not interactable” exception. Attract acknowledges the sort of error and marks the check as damaged, indicating that it’s more than likely a check engineering mistake slightly than a bug.

Once we encounter failed checks in our check runs, we frequently wish to examine the precise explanation for the failure. One efficient means to do that is to connect a screenshot of the second the check failed. JUnit affords the TestWatcher interface, whereas TestNG gives the ITestListener interface, each of which permit builders to override the testFailed() and onTestFailure() strategies. In these strategies, a screenshot attachment will be made by including the suitable code. Right here’s an instance:

byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
Attract.getLifecycle().addAttachment(“Screenshot”, “picture/png”, “png”, screenshot );

Attract.getLifeCycle().addAttachment() accepts an array of bytes as one of many parameters.

And Selenium is ready to take screenshots as an array of bytes, as proven within the snippet above. This fashion each time the check fails, a screenshot will likely be captured and hooked up to your report.

However chances are high this answer goes to battle together with your @AfterEach strategies, since they’re run first. I managed to search out a neater however much less elegant answer to keep away from such a state of affairs on this specific challenge. In an effort to keep away from conflicts with the @AfterEach strategies, I applied a attempt/catch block across the complete check code. If an exception is thrown, the catch block takes a screenshot, attaches it to the report, and rethrows the exception.

In fact When you’ve got a whole bunch of checks, implementation of testing framework interfaces goes to profit you much more. Nevertheless, to know the final concept of how one can seize and connect screenshots to the check report, the above instance is enough.

Now every time an exception happens throughout check methodology execution, a screenshot will likely be captured and added to the report.

This method gives a clearer understanding of any points that occurred in the course of the check execution, permitting you, your supervisor, or some other involved occasion to establish what went flawed.


The capabilities of Attract prolong far past what has been coated on this article. There are quite a few different fascinating and helpful implementations of Attract in cooperation with CI/CD course of, challenge and check administration methods. By implementing the easy hints mentioned right here, it is possible for you to to arrange and customise your Attract report back to a fantastic extent, thereby making it a invaluable and informative software for you and your staff. With the help of Attract, you will get a greater understanding of your check outcomes and make data-driven choices that improve the general high quality of your software program challenge.