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 studies for automated checks. It permits builders and testers to create detailed and significant studies of their check outcomes and may be built-in with numerous check frameworks resembling JUnit, TestNG, and extra.
Why Attract particularly?
Attract is a well-liked alternative amongst builders and testers for creating check studies due to its ease of use and adaptability. The framework is extremely customizable and permits builders to create studies 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 are going to see tips on how to set up Attract to your mission, tips on how to generate studies and tips on how to use annotations to provide your studies extra that means. I’ll show attract’s capabilities on a small Selenium UI auto testing mission.
Set up
Gradle
In an effort to use Attract with Gradle in your mission you will have so as to add a number of dependencies to tasks’ construct.gradle file:
- testImplementation group: ‘org.aspectj’, title:
‘aspectjweaver’, model: ‘wanted model’ - testImplementation group: ‘io.qameta.attract’, title:
‘allure-java-commons’, model: ‘wanted model’ - testImplementation group: ‘io.qameta.attract’, title:
‘allure-junit5’, model: ‘wanted model’ - testImplementation group: ‘io.qameta.attract’, title:
‘allure-commandline’, model: ‘wanted model’ - testImplementation group: ‘io.qameta.attract’, title:
‘allure-assertj’, model: ‘wanted model’
You’ll want so as to add Attract plugin into plugins part of your construct.gradle file as properly:
- id “io.qameta.attract” model “wanted model”

It will add “allureServe” and “allureReport” to your gradle verification duties.

After constructing the mission and downloading all of the recordsdata from dependencies you can begin implementing Attract to your mission.
Maven
For Maven it’s a fairly simple course of as properly. You’ll want to change your pom.xml file:
<properties>
<aspectj.model>wanted model</aspectj.model>
<attract.model>wanted model</attract.model>
</properties>
<dependencies>
<dependency>
<groupId>io.qameta.attract</groupId>
<artifactId>allure-junit4</artifactId>
<model>$attract.model</model>
</dependency>
<dependency>
<groupId>io.qameta.attract</groupId>
<artifactId>allure-rest-assured</artifactId>
<model>$attract.model</model>
</dependency>
</dependencies>
<construct>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<model>wanted model</model>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
javaagent:”$settings.localRepository/org/aspectj/aspectjweaver/$aspectj.model/aspectjweaver-$aspectj.model.jar”
</argLine>
<properties>
<property>
<title>listener</title>
<worth>io.qameta.attract.junit4.AllureJunit4</worth>
</property>
</properties>
<systemProperties>
<property>
<title>attract.outcomes.listing</title>
<worth>$mission.construct.listing/allure-results</worth>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<model>$aspectj.model</model>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>io.qameta.attract</groupId>
<artifactId>allure-maven</artifactId>
<model>wanted model</model>
<configuration>
<reportVersion>wanted model</reportVersion>
</configuration>
</plugin>
</plugins>
</construct>
Don’t overlook to interchange wanted model with the model you want.
This may also add all the required dependencies and plugins to your mission, and after constructing the mission Attract will likely be prepared.
Establishing mission
We’ll start with a small Selenium check that opens Google.com, enters textual content into the search subject, 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) strategy and the non-POM strategy.
Let’s begin with the POM strategy, which is the popular technique for organizing UI automated testing frameworks. Moreover, we’ll be capable to showcase Attract annotations. We’ll create two courses for this objective: GooglePage and GoogleSearchPomTest. The GooglePage class will include our parts with locators and the strategies that take care of these parts. The GoogleSearchPomTest class will include our check logic.
The mission will likely be out there in its entirety on GitHub repository insert hyperlink to repository. You’ll be able to obtain it and discover how every part is finished.

GooglePage class.

GoogleSearchPomTest class.
To maintain issues easy, I received’t be making a separate class for the search outcomes web page. Since we solely must work together with one ingredient on the outcomes web page, I’ll embrace it within the present GooglePage class.
Producing report
As soon as every part is about up, we are able to generate the primary Attract report by operating our checks for the primary time. It will create folders within the construct listing of our mission 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” choice in your Gradle duties.
Operating “allureServe” will launch the Attract internet service in your native machine and open an HTML web page in your browser. This web page will present an summary 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 courses 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 technique. Attract robotically designates strategies annotated with “@BeforeEach” and “@AfterEach” as “Arrange” and “Tear down” steps, respectively. Nevertheless, it doesn’t show any steps inside the check technique itself.
Customizing report
One of many foremost options of Attract is its annotations, which permit customers to customise the report back to make it extra readable. Presently, the report doesn’t present a lot data.
To enhance it, we are able to begin by utilizing the “@Proprietor(‘Proprietor’s title and place’)” annotation. We are able to annotate check courses with this annotation to point the proprietor of the checks.

After including the “@Proprietor” annotation to our check courses, 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 title included.

By including the “@Proprietor” annotation to our check courses, 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(‘Check title’)” annotation. We are able to add this annotation to every check class and check technique to offer a transparent, descriptive title for every suite and technique within the report.

We have to generate the report yet another time.

By including the “@DisplayName” and “@Proprietor” annotations to our check courses and check strategies, the report has change into extra readable for non-technical stakeholders resembling managers.
In some circumstances, 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 may be added to each check technique in a set, similar to “@DisplayName”.

It will 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 technique in our web page object. This permits 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 technique.

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 properly.

Attract additionally gives the length of every check technique, which may 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 straight, you should utilize the static technique “step()” supplied by Attract. This technique lets you outline a step with a reputation and go the interplay with the driving force as a lambda by 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 seems to be 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 may be chosen from the SeverityLevel enum.

It will change the severity degree within the report. Notice that by default severity degree is about to “Regular”.

Now let’s see what a failed check goes to seem like. Let’s change our isSearchedTextInHeader technique to anticipate false as a substitute of true.

Now we are able to see we have now failed checks in our run. Let’s see what data we have now 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 forward to the search button to change into clickable in each checks. If we remark out this step in one of many checks, the driving force could also be too fast to click on the button, leading to an “ingredient not interactable” exception. Attract acknowledges this sort of error and marks the check as damaged, indicating that it’s almost certainly a check engineering mistake moderately than a bug.

Once we encounter failed checks in our check runs, we frequently wish to examine the particular reason behind the failure. One efficient means to do that is to connect a screenshot of the second the check failed. JUnit gives 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 may 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 connected to your report.
However likelihood is this answer goes to battle along with your @AfterEach strategies, since they’re run first. I managed to seek out a better however much less elegant answer to keep away from such a scenario on this specific mission. 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 have a whole lot of checks, implementation of testing framework interfaces goes to learn you much more. Nevertheless, to know the final concept of tips on how to seize and connect screenshots to the check report, the above instance is ample.
Now every time an exception happens throughout check technique execution, a screenshot will likely be captured and added to the report.


This strategy gives a clearer understanding of any points that occurred in the course of the check execution, permitting you, your supervisor, or another involved get together to determine what went mistaken.
Conclusion
The capabilities of Attract prolong far past what has been lined on this article. There are quite a few different attention-grabbing and helpful implementations of Attract in cooperation with CI/CD course of, mission and check administration techniques. By implementing the straightforward hints mentioned right here, it is possible for you to to arrange and customise your Attract report back to an excellent extent, thereby making it a beneficial and informative software for you and your workforce. 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 mission.
Latest News
-
Accelerating Knowledge Tasks with Parallel Computing – Grape Up
-
10-Actual-World Examples of RPA Automated System
-
Meet Distillery: Gregg Wheeler, Chief Income Officer
-
Cloud Growth Overview for Non-Cloud Builders – Grape Up
-
Experiences selling area of interest software program | Profitable Software program