Code

Java Automated Test: How to Write with Selenium WebDriver

Java Automated Test: How to Write with Selenium WebDriver

Course with employment: “Profession Java Developer"

Learn More

What You'll Need

Before you begin, it's important to have at least a basic knowledge of the Java language and dependency management principles. You also need to install and configure the IntelliJ IDEA development environment, in which we will create automated tests. This text provides useful resources and materials that will help you understand these issues and effectively begin developing automated tests.

  • Java Core for Beginners: Roadmap
  • IntelliJ IDEA: What is this development environment and how to work in it
  • Maven Basics: What is it and how does it work

Automated tests can be written in various editors, but we recommend using IntelliJ IDEA Community Edition. This free and convenient development environment is ideal for beginner Java developers. IntelliJ IDEA makes it easy to create a new project, add required dependencies, and run tests directly from the interface. Choosing this IDE will help you focus on development and improving code quality. Working with the Selenium library requires ChromeDriver, a driver that enables interaction with the Google Chrome browser. Without it, Selenium cannot directly control the browser. The library allows you to emulate user actions such as clicks and text input, but it requires ChromeDriver as an intermediary to function correctly. In the next section, we will look at how and where to download this driver.

Reading is an integral part of our lives, and it opens the door to new knowledge and experience. Through reading, we can expand our horizons, develop critical thinking, and improve communication skills. We encourage you to explore different genres of literature to find what interests you most. Whether you prefer fiction, scientific articles, or educational materials, reading promotes personal growth and self-improvement. Don't miss the opportunity to immerse yourself in the world of books and gain new experiences and knowledge.

12 Best IntelliJ Plugins to Boost Your Productivity

IntelliJ IDEA is a powerful development environment that offers many built-in features. However, plugins can significantly expand its capabilities. In this article, we will look at 12 of the most useful plugins that will help you optimize your development process and make it more efficient.

The first on our list is the Lombok plugin. It simplifies working with Java by automatically generating getters, setters, and other methods, which helps reduce the amount of code.

The next plugin is CheckStyle. It helps maintain coding standards by checking your code for compliance with specified rules. This is especially relevant for teamwork, where code consistency is of great importance.

Another important tool is SonarLint. This plugin performs static code analysis and helps identify potential errors and vulnerabilities in real time, which contributes to improved code quality.

If you work with code versions, the GitToolBox plugin will be indispensable. It adds additional features for working with Git, including displaying the repository status and the ability to quickly access commits and branches.

For those who prefer visualization, it is worth paying attention to the Rainbow Brackets plugin. It helps better navigate nested code structures by color-coding brackets.

The CodeGlance plugin provides a mini-map of your code, which allows you to quickly navigate the file and improves navigation. This is especially useful when working with large projects.

Another useful tool is Database Navigator. It integrates database work directly into IntelliJ, allowing you to easily run queries and view data without having to switch between applications.

For improved REST API experience, we recommend using the REST Client. This plugin allows you to query and test APIs directly from the IDE, which significantly speeds up the development process.

Also worth mentioning is the BashSupport plugin, which adds support for Bash scripts, which is useful for developers working on Unix-like systems.

If you are doing web development, the Vue.js plugin supports the Vue framework, providing autocompletion and syntax highlighting.

The Markdown Navigator plugin improves work with Markdown files, allowing you to conveniently edit text documents with formatting.

Finally on our list is the JRebel plugin, which allows you to make changes to the code without restarting the application, which significantly speeds up the development and testing process.

Using these 12 plugins will help you get the most out of IntelliJ IDEA and increase the productivity of your development.

Preparing the working Environment

In this section, we'll develop a project in the IntelliJ IDEA development environment. We'll start by including the necessary libraries and setting up the pom.xml file. Then, we'll download ChromeDriver to automate browser testing. Finally, we'll create a simple test that launches the browser and opens a specified page. This will ensure that the environment is set up correctly and ready for automated testing.

After installing IntelliJ IDEA, launch the program and, in the window that opens, select Java as the development language and Maven as the build system. Specify a project name, such as seleniumwd_test, select the desired JDK version, and uncheck Add sample code to start from scratch. Then click Create, and IntelliJ IDEA will create the project we'll be working with. This process is an important start to properly setting up your development environment and preparing to build your Java project using Maven.

Project settings window in IntelliJ IDEA. We'll be using Oracle OpenJDK 23.0.2, but you can choose any JDK version—preferably at least 17. Screenshot: IntelliJ IDEA / Skillbox Media

After creating a project, IntelliJ IDEA automatically generates a pom.xml file. This file serves as a configuration for Maven, where we specify the necessary libraries, plugins, and compilation options. The generated file contains a basic structure, including project IDs and a properties section containing the JDK version and encoding. These values ​​can be left unchanged, as they are appropriate for the current task. Setting up pom.xml is an important step that will allow you to effectively manage dependencies and project configuration.

The original pom.xml file after creating the project. Screenshot: IntelliJ IDEA / Skillbox Media

Read also:

XML format, or Extensible Markup Language, is a markup language designed for storing and transmitting data. It provides a convenient and structured representation of information, which makes it a universal tool for various applications. XML is used in web technologies to exchange data between different systems and platforms.

One of the main uses of XML is working with web services, where it serves as a format for transmitting requests and responses. XML is also widely used in software configuration files, as well as in documents that require a clear structure, such as books, articles, and reports.

Furthermore, XML finds application in areas such as data management, e-commerce, and the creation of interactive applications. Due to its flexibility and extensibility, XML allows developers to create their own tags and data structures, making it an ideal choice for various projects.

Thus, the XML format is an important tool in the modern world of information technology, providing efficient data exchange and structured presentation of information.

The dependencies section must be added to the pom.xml file, which will specify the libraries required for developing and running automated tests. Maven will automatically download the required files from the central repository after updating the project. In this section, we will use Selenium WebDriver to control the browser, TestNG to execute tests and group them into scenarios, and Allure TestNG to generate test results reports.

To properly integrate the dependencies section, you must place it after the properties block, but before the closing tag. Make sure that the code fragment you are about to insert is correct and matches the overall structure of the document. This will ensure the correct functioning and interaction of all elements.

After adding dependencies to the pom.xml file, you must manually refresh the Maven project so that IntelliJ IDEA downloads all the required libraries. To do this, save the changes to the file by pressing Ctrl + S, then open the Maven panel by clicking the icon with the letter m in the right side menu. After that, click the button with the circular arrow to execute the "Reload all Maven projects" command. This will ensure that dependencies are updated correctly and your project is running with up-to-date libraries.

After this action, a loading indicator will appear at the bottom of the window, indicating that the automatic dependency update has begun. Once the process is complete, the red underlines in the file will disappear, and an "External Libraries" section will appear on the left side of the project. In this section, you can view included libraries, such as selenium-java, testng, allure-testng, and others. This will allow you to effectively manage dependencies and ensure the libraries used in your project are up-to-date.

The project after adding dependencies and synchronizing with Maven: on the right is the Maven panel and the Sync/Reload All Maven Projects button; in the center is the dependencies code block in the pom.xml file; On the left is the External Libraries section with a list of loaded libraries. Screenshot: IntelliJ IDEA / Skillbox Media.

The build section must be added to the pom.xml file. This section is designed to include Maven plugins that run tests and generate reports. Properly configuring the build section in pom.xml allows you to automate testing and reporting processes, which contributes to more efficient project management and improves software quality.

We will focus on two plugins that are particularly valuable to users. These tools will help improve the functionality of your site, increase its performance, and optimize visitor interaction. Let's take a closer look at the features and benefits of each plugin so you can choose the one that best suits your needs.

  • maven-surefire-plugin — responsible for running automated tests;
  • allure-maven — generates test results reports.

The build section should be placed immediately after the dependencies block, but before the closing tag. This will allow you to properly organize the project structure and ensure correct assembly. Make sure you follow this sequence to avoid errors during development.

After making changes, don't forget to save the file by pressing Ctrl + S. Then, in the Maven panel, click the 'Reload All Maven Projects' button to update the necessary plugins. This will help avoid dependency issues and ensure the project works correctly.

The project after adding the build section and synchronizing with Maven. The right panel displays enabled plugins, including surefire and allure. Screenshot: IntelliJ IDEA / Skillbox Media.

If you encounter errors in IntelliJ IDEA after installing plugins, you will need to make changes to the code before continuing.

If you encounter an error, it is important to stay calm and follow a few steps to resolve it. First, check that you have entered the data correctly. Errors often occur due to typos or incorrect formatting. If the data is correct, try refreshing the page or application. This can help resolve temporary glitches.

If the error continues to occur, consult the documentation or help materials. They can contain information about common errors and how to resolve them. It is also a good idea to check for software updates, as outdated versions can cause problems.

If none of these methods help, consider contacting support. Describe your problem in detail, including the steps you've already taken, so they can help you more quickly. Remember that errors are a normal part of working with technology, and most can be resolved with a systematic approach.

After integrating the maven-surefire-plugin plugin, you may encounter an error. This issue is often related to the plugin's configuration or incompatibility with other project components. To resolve the error, check your pom.xml settings and ensure all dependencies are specified correctly. It is also recommended to update the plugin to the latest stable version, as this may resolve compatibility issues. If the error continues to occur, please consult the plugin's documentation or the developer community for further assistance.

Could not find dependency 'org.aspectj:aspectjweaver:1.9.20.1'. Please check that the version and repositories in your project are specified correctly. This version may have been removed or moved. It is recommended to update the dependency configuration, specifying the current version or alternative repositories where the required library can be found. Make sure you are using the correct build tools and that your development environment is configured to handle the required dependencies.

You specified a specific version of the aspectjweaver library, but Maven cannot detect it. This can happen if the version was entered manually or is not yet available in the repository. Similar error messages may appear in the editor, indicating a dependency issue. To resolve this issue, verify that the correct version is specified and that the library is available in the repositories. Make sure you are using up-to-date dependencies and update your Maven settings if necessary.

Screenshot: IntelliJ IDEA / Skillbox Media

To fix the error, you need to make changes to the file pom.xml by adding a variable with the AspectJ library version. This should be done in the properties section. Specifying the correct library version will ensure correct functioning of the application and avoid potential compatibility issues. Don't forget to save your changes and update your project dependencies to apply the new settings.

The version currently used is 1.9.22, but it may be updated in the future. For the latest stable version, visit mvnrepository.com.

If the version has been updated, simply update this line accordingly.

Inside the maven-surefire-plugin, replace the statically specified version of the aspectjweaver library with a variable. This will automatically substitute the latest version when using Maven and will help avoid errors during the project build process. This approach improves dependency manageability and increases build stability.

In the plugin configuration, find the line with the -javaagent parameter, which is usually located in the configuration block. Remove this line, as the library is now included directly via Maven, simplifying the integration and dependency management process.

Save the file using Ctrl + S, then click the 'Reload All Maven Projects' button in the Maven panel. If the problem is resolved, IntelliJ IDEA will display a green checkmark, indicating that the project is configured correctly.

If you want to simplify the process and avoid performing all the steps manually, simply delete the old code and replace it with the new one. This will significantly speed up your work and minimize the possibility of errors. Updating the code will improve the performance and functionality of your project.

If the code does not work, make sure that the version of the aspectjweaver library specified in the aspectj.version line is up to date. A newer stable version may be available that will resolve the issue. Regularly updating libraries will help avoid errors and improve the performance of your project.

If you experience problems with Maven in IntelliJ IDEA, try saving the file again and then clicking the Reload All Maven Projects button in the Maven panel. If this doesn't resolve the issue, restart IntelliJ IDEA and repeat all the steps. It's possible there was a typo in one of the steps that is causing the error.

In the preparation phase, we mentioned that Selenium cannot directly control the browser. This task requires ChromeDriver, a special component that acts as an intermediary between Selenium and the browser. To download ChromeDriver, visit googlechromelabs.github.io. There you can find a stable version of the driver that matches your browser version and operating system. Make sure you download the correct version for optimal performance of your tests and automation.

In this example, we download ChromeDriver for Windows 11 (64-bit) with browser version 135.0.7049.97. Select the link, right-click, click "Go to URL," and wait for the ZIP archive to download. Screenshot: Chrome / Skillbox Media

After downloading the archive, unzip it and move the chromedriver.exe file to a convenient location. We recommend creating a folder on the C drive, for example, "tools," so that the full path to the file looks like this: C:\tools\chromedriver. This will make it easier to access the driver for automating the Chrome browser.

You can use the specified path or choose any other, as long as it is correct. In the future, we will enter it manually in the code.

The chromedriver.exe file in the tools folder on drive C Screenshot: Windows 11 / Skillbox Media

We've finished everything The preparatory steps are complete, and now we need to test the project's functionality. Let's make sure the libraries are correctly linked, the driver is installed, and the tests are ready to run. To do this, create a Java file named Main.java and add the following code to it:

If configured correctly, clicking the green Run button at the top of the IntelliJ IDEA window will automatically open the browser and immediately close it. If the code does not run, make sure the following:

  • is the path to chromedriver.exe specified accurately;
  • does the ChromeDriver version match the version of your browser;
  • is Google Chrome installed or do you have a different browser;
  • is the program not being blocked by an antivirus or security system.
If the program runs successfully, you will see the following in the console: the line "Process finished with exit code 0" — this means that the program completed without errors; the red message is a warning related to the Chrome DevTools Protocol mechanism. It is needed for debugging, for example, for writing logs or monitoring network requests. We don't use it, so you can ignore this warning when running automated tests. Screenshot: IntelliJ IDEA / Skillbox Media

Writing automated tests

This section presents two test scenarios for the saucedemo.com website. The first scenario is aimed at checking the functionality of the login page, while the second scenario will focus on testing the shopping cart. These tests will help ensure the correct functioning of the site and improve the user experience.

For ease of extension and code reuse, we will apply the Page Object pattern architecture, dividing the project into separate classes. Each class will be responsible for a specific page or component, improving code readability and maintainability. We'll develop a base class for browser interaction, describe the actions performed on the pages, add auxiliary settings, and implement tests. This approach will ensure the flexibility and scalability of the testing framework, allowing for easy modifications and the addition of new functionality as needed.

Read also:

Basic Design Patterns in Java

Design patterns are proven solutions to common problems that arise during software development. The Java language distinguishes several key patterns that help developers create flexible and maintainable applications.

Design patterns are typically classified into three main categories: creational, structural, and behavioral. Creational patterns, such as Singleton, Factory Method, and Abstract Factory, are responsible for creating objects, allowing you to manage their creation process. Structural patterns, such as Adapter, Composite, and Proxy, help organize classes and objects, ensuring convenient interaction between them. Behavioral patterns, such as Observer, Strategy, and Command, define how objects interact and exchange information.

Using design patterns in Java not only simplifies development but also improves the readability and maintainability of code. Knowing the basic patterns allows developers to effectively solve problems, avoiding reinventing the wheel. When applied correctly, design patterns can significantly speed up the development process and improve the quality of the software product.

First, you need to create a helper class, BasicActions, which will launch the browser with the specified parameters. This class will allow you to specify the path to ChromeDriver, activate incognito mode, maximize the browser window, and set an implicit wait. With Selenium, the browser will wait for elements to appear on the page for a certain amount of time (for example, up to 5 seconds) before throwing an error. This will make automation more reliable and efficient.

To create the class, open the src → main → java folder in the project panel. Right-click the java folder and select New → Package, then name it basic. Next, right-click the basic package, select New → Java Class, and name it BasicActions. Paste the following code:

To launch the browser, you now only need to use a single method. This simple approach significantly simplifies the process and speeds up task execution. With this method, you can quickly open the browser and begin interacting with web pages, making it a convenient tool for automation and testing.

Let's create two helper classes: Config and Constant. These classes will be used to store the settings and variables required to run each test. The Config class will contain configuration parameters, and the Constant class will contain fixed values ​​that may be needed in tests. This approach will provide convenient data access and simplify the process of modifying and scaling tests, which will increase their efficiency and ease of use.

The Config class is created in the basic package. It is responsible for managing the basic launch parameters. It allows you to select the operating system and browser, clear cookies and local storage, and close the browser when the tests are complete. This class simplifies setting up the test environment and provides efficient parameter management, which contributes to a smoother testing process.

The Constant class is designed to store URLs and timeout values, which determine the time to wait for elements to appear on the page when using Selenium. This class should be placed in the constants package, which is located at the following path: src → main → java. Optimizing element waits helps improve the stability of automated tests and ensures a more efficient experience with your web application.

If IntelliJ IDEA doesn't automatically create a package, you'll need to create one manually. To do this, open the src → main → java folder, right-click the java folder, select New → Package, and name it constants. Then, create a new Constant class in this package and paste the necessary code into it.

To create a universal parent class for all site pages, we'll develop a BasePage class. This class will contain common methods that can be used in any test. These methods might include, for example, a link follow function and a method for waiting for an element to appear on the page. Thus, BasePage will become the basis for all pages, ensuring uniformity and ease of writing tests.

Create a class in the pages.base package located at src/main/java.

At this stage of development, we create classes that will manage the various pages of the site. This is the basis of the Page Object pattern. As part of this process, we implement key functions that enable interaction with page elements and simplify testing and code maintenance. Thus, we form a structure that will allow you to effectively organize work with the site's interface, improving its testability and maintainability.

  • SaucedemoLoginPage - for entering login and password;
  • SaucedemoShowcasePage - for adding products to the cart;
  • CartPage - for checking the amount in the cart.

We will develop a base BaseTest class, which will be responsible for launching the browser, creating pages, and completing work after the tests are completed. This class will provide effective test lifecycle management and simplify the process of automating web application testing.

To create the SaucedemoLoginPage class, open the project panel and navigate to the src → main → java folder. Right-click the java folder, select New → Package, and enter pages.saucedemo. IntelliJ IDEA will automatically create all the necessary subdirectories. Then, right-click the pages.saucedemo package, select New → Java Class, and name it SaucedemoLoginPage. Then, add the appropriate code to implement the login page functionality.

To create a new class in IntelliJ IDEA, right-click the java folder, select New → Package, and name it pages.showcase. This will allow you to create the necessary package structure. Then, right-click the pages.showcase package, select New → Java Class, and name it SaucedemoShowcasePage. Then paste the appropriate code into the created class.

Open the src folder → main → java. Right-click the java folder and select New → Package. Enter the package name pages.cart. After that, click on the created pages.cart package, then select New → Java Class and specify the class name CartPage. Next, add the necessary code to the created class.

To complete the project setup, you need to create code for the base class, which will be located not in the main directory, but in the test folder. In the project panel, go to the src folder, then open the test folder and select java. Click on the java folder, select New, then Package and enter the name tests.base. After that, click on the created tests.base package, select New, then Java Class and specify the class name BaseTest.

At this stage, it is important to pay attention to the project structure that should be formed. This structure will serve as the basis for further development and organization of all components. Properly structuring a project will help optimize workflows, simplify navigation, and make the code more understandable for the development team. Make sure all elements are in logical places, which will ensure ease of use and ease of maintenance of the project in the future.

Screenshot: IntelliJ IDEA / Skillbox Media

Let's create two classes for testing functionality online store. The first class, LoggingTest, will be responsible for testing the user authorization process. The second class, PriceSumTest, will calculate the total price of the items in the shopping cart. These classes will help ensure the reliability and correctness of the application, allowing you to identify potential errors and improve the user experience.

  • LoggingTest checks whether the user logs in successfully;
  • PriceSumTest checks whether the total for the selected items in the shopping cart is calculated correctly.

Both classes will use the existing project infrastructure, including launching a browser, opening pages, and accessing elements using the Page Object approach. All of these functions have already been implemented, and we only need to describe the test scenarios. This will allow you to effectively use the components already developed and focus on creating high-quality tests.

To create the LoggingTest class, open the src → test → java folder. Right-click the java folder, select New → Package, and enter the name tests.loggingtest. Next, click on the created tests.loggingtest package, select New → Java Class, enter the class name LoggingTest, and add the necessary code. This process will allow you to organize logging tests in your project, ensuring structure and ease of use of the code.

Now let's create the second test—PriceSumTest. Go to the src → test → java folder, create the tests.pricesumtest package, and in this package, create the PriceSumTest Java class. This test will be designed to verify the functionality related to price summation, which is an important aspect in the development of software for financial data processing. In the PriceSumTest class, we will implement test scenarios that will help ensure the correctness of calculations and the handling of possible errors.

We recommend re-checking the project structure after completing this step. This step is important to ensure the consistency and integrity of all elements. Reconciling the structure will help identify potential flaws and optimize further actions. Regularly reviewing the project structure helps improve the quality and efficiency of work, and also facilitates the process of achieving goals.

Screenshot: IntelliJ IDEA / Skillbox Media

To run automated tests using Maven You need to create an XML configuration file named testng.xml. In this file, we will define which test classes will be run and how they should be grouped. Make sure the file is placed in the src/test/resources folder. Properly configuring testng.xml allows you to effectively organize and manage the testing process, which in turn improves the quality of the software product.

If your IntelliJ IDEA project is missing a resources folder, follow these steps: right-click the test folder → java, select New → Directory and enter the name resources. Then right-click the created folder, select New → File and enter the file name: testng.xml. These steps will help you properly organize the project structure and prepare it for testing using TestNG.

The project has been successfully completed and is ready to run automated tests.

  • We have a project structure built using the Page Object template;
  • The pages and test cases have been implemented;
  • The testng.xml file is configured to run via Maven.

In the next section, we'll test and integrate the Allure library. It will provide information about which tests passed, which failed, and the steps where errors occurred. This will allow us to more effectively analyze test results and improve the quality of our software.

Final project structure - make sure it looks the same in your editor Screenshot: IntelliJ IDEA / Skillbox Media

Running Tests and Viewing Reports

We'll run automated tests using two methods: first through IntelliJ IDEA, and then using Maven and Allure. We'll start with running tests through IntelliJ IDEA. This approach allows you to quickly and easily check your code's functionality directly in the development environment.

Open the testng.xml file. A green arrow will appear at the top of the window. Click it, and IntelliJ IDEA will run both tests: the authorization check and the shopping cart test. If configured correctly, the message "Tests passed: 2 of 2" will appear at the bottom of the screen, and the browser will open to perform the necessary actions. If one of the tests fails, you'll see the message "Tests failed" with detailed error information. Make sure all dependencies and configurations are set correctly for tests to run successfully.

Example console output when one test passed and the second failed. In this case, LoggingTest passed, but PriceSumTest failed: the total in the cart was $45.98, not $29.98 as expected. Screenshot: IntelliJ IDEA / Skillbox Media

If the green arrow at the top of the window is not visible, this may mean that the TestNG plugin is not installed. To check, open IntelliJ IDEA settings: select File → Settings from the menu, then go to the Plugins tab and enter «TestNG» in the search bar. Install the plugin, then restart the editor. Make sure that the green arrow appears after completing these steps, which will allow you to effectively use TestNG's capabilities to test your code.

If the plugin is installed but the arrow is not visible, right-click on the testng.xml file and select the «Run ‘testng.xml'» option. After this, the tests will run in standard mode. Make sure the plugin is configured correctly to avoid similar issues in the future.

If everything looks like in the image, then the TestNG plugin is installed and working. Screenshot: IntelliJ IDEA / Skillbox Media

If If both tests are successful, the message "Tests passed: 2 of 2" will appear on the screen, and green checkmarks will appear to the left of the automated tests. A detailed execution log will also be displayed in the console. The browser will automatically open and perform all the actions described in the scenarios: logging in to the site, adding products, and going to the cart. This allows you to ensure that the functionality works correctly and the application is stable.

An example of successful execution of both automated tests. It is clear that the actual and expected amounts match, and the Failures status is 0, meaning there are no errors. Screenshot: IntelliJ IDEA / Skillbox Media
The shopping cart page on saucedemo.com after running the automated test: we have successfully added two products, and The cart displays their names and prices. Screenshot: Chrome / Skillbox Media

Automated tests have been successfully run in IntelliJ IDEA. Now we will move on to running tests via Maven and create a report using the Allure library. This will provide visual test results and simplify the analysis of their execution.

Let's check if Maven is installed. To do this, open a terminal in the IntelliJ IDEA development environment and run the following command:

If the console displays information about the Maven version, then the configuration is correct, and you can start running automated tests. Otherwise, you will need to download the latest version of Maven and install it on your operating system. After the installation is complete, it is recommended to restart IntelliJ IDEA and the terminal so that the system recognizes the new environment variable and activates Maven. Make sure you follow all steps to avoid errors when running automated tests.

After installing Maven, run the following command in the terminal:

Running a single test makes learning easier, as the command doesn't rely on the testng.xml file. This is especially useful in situations where the IDE cache may be lost. After the test is executed, a success message or a description of the error that occurred will be displayed in the console, which allows you to quickly analyze the test results and fix problems.

An example of a successful autotest run via Maven: we ran the command mvn -Dtest=PriceSumTest test; Maven found and ran the required test (PriceSumTest); the test completed without errors: Tests run: 1, Failures: 0, Errors: 0; overall status: BUILD SUCCESS — everything is fine. Screenshot: IntelliJ IDEA / Skillbox Media.

To run all tests simultaneously, use an alternative command.

In this situation, Maven will first clean up the target folder, which contains compiled classes and old reports, and then run all tests specified in the testng.xml file. However, this command will not work in our sample project, as it requires additional configuration of the pom.xml file. To avoid complications, we'll skip this step and continue running the tests manually.

If the automated tests complete successfully and without errors, enter the following command in the terminal:

If the terminal displays the version number, this confirms that the Allure library is successfully installed and ready for use. You can now rerun the test.

If the terminal does not display the Allure version, this indicates that the library is missing from the system. In this case, you should install Allure similarly to how you installed Maven, following the instructions appropriate for your operating system. Make sure to configure environment variables and paths to ensure Allure functions correctly after installation.

Once installed and configured, you will be able to automatically generate detailed reports each time you run automated tests. These reports contain general information about the test execution status, as well as graphs, charts, categories, and other important information that will help you effectively analyze test results and optimize development processes.

In our example, we can see that one test was launched, it was successful, and the result is displayed as 100% PassedScreenshot: Allure Report / Skillbox Media

What's Next

Congratulations on your successful completion! You now have a basic understanding of the browser automation process and how to create tests using the Page Object template. You've also developed a basic automated testing framework that has a clear structure and the ability to be further extended. This will allow you to effectively organize tests and ensure their ease of maintenance, which is essential for high-quality web application testing.

Now, let's look at implementing a few additional scenarios. This will help deepen your understanding and expand the project's functionality. Scenarios can include various aspects, such as error handling, integration with external APIs, or creating user interfaces. Each of these areas will not only improve the user experience but also increase the overall efficiency of the system. It is important to test each scenario for performance and usability to ensure the project runs smoothly and the end user has a positive experience.

  • Make sure the Login button is accessible again after logging out;
  • Add 3-4 different products to the cart and check if they are actually displayed;
  • Remove one product from the cart and check if it disappears from the list;
  • Enter an incorrect password when logging in and check if an error message appears.

You can perform all of these tests by updating current pages with new methods or creating separate test classes. This will improve the functionality and performance of your site, as well as increase its visibility in search engines. Updating content and implementing new tests contributes to deeper analysis and optimization, which in turn will have a positive impact on user experience and search rankings.

To improve the level of testing in Java, we recommend familiarizing yourself with the JUnit library, which is one of the most popular in this area. If you're looking to learn another programming language, check out our Python mock testing guide for lots of helpful resources and examples.