Welcome to the testng-practice-lessons repository! This project is designed for SDET students to reinforce their knowledge through practical lessons. It demonstrates how to perform test automation using TestNG with TestNG-specific features like annotations, parallel execution, and data providers.
- π‘ Introduction
- π₯ Installation
- βοΈ Usage
- β¨ Features
- π¦ Dependencies
- π§ Configuration
- π Documentation
- π‘ Examples
- π οΈ Troubleshooting
- π₯ Contributors
- π€ Contributing
- π License
To install TestNGCurrent, clone the repository to your local machine:
git clone https://github.com/cihat-kose/testng-practice-lessons.git
- Open IntelliJ IDEA.
- Go to
File
>New
>Project from Version Control
. - In the dialog, select
Git
and enter the repository URL:https://github.com/cihat-kose/testng-practice-lessons.git
. - Click
Clone
.
- Open IntelliJ IDEA.
- Navigate to
File
>Project Structure
>Libraries
. - Click on the
+
icon and selectFrom Maven
. - In the dialog, search for the necessary libraries using the Maven coordinates:
org.apache.logging.log4j:log4j-api:2.20.0
org.apache.logging.log4j:log4j-core:2.20.0
commons-io:commons-io:2.18.0
org.seleniumhq.selenium:selenium-java:4.32.0
org.slf4j:slf4j-nop:2.0.17
org.testng:testng:7.11.0
- Click
OK
to add the selected libraries.
For each library, you can also use a higher version if available.
Ensure that you have the necessary dependencies installed and navigate to the src
directory to set up and execute the test cases.
Run your tests from any TestNG XML file by following these steps:
# From IntelliJ IDEA or Eclipse
Right-click on any XML file (e.g., 'cross-browser-test.xml') and select 'Run'.
# To run from command line with Maven
mvn test -DsuiteXmlFile=your-test-suite.xml
You can directly run test classes annotated with TestNG:
# Right-click on the class in IntelliJ IDEA and select 'Run ClassName'.
# To run all test classes with Maven
mvn test
- Sorting: Organize tests in a specific order.
- Annotations: Use TestNG's rich set of annotations to define test methods.
- Enable/Disable: Enable or disable tests dynamically.
- Assertions: Utilize TestNG assertions to validate test outcomes.
- Dependency Management: Manage test method dependencies.
- Groups: Group tests for selective execution.
- Cross Browser Testing: Execute tests across multiple browsers.
- Parallel Testing: Run tests in parallel to save time.
- XML Configuration: Configure test suites using
testng.xml
. - Data Providers: Supply data to test methods.
- Parameterized Tests: Run the same test with different parameters.
- Page Object Model (POM): Implement POM for cleaner code.
- HTML Reporting: Generate HTML reports for test results.
- Logging: Integrated logging using Log4j2 for tracking and debugging test execution.
Dependency | Version | Link |
---|---|---|
Java | 21+ | Java |
TestNG | 7.11.0 | TestNG |
Selenium WebDriver | 4.32.0 | Selenium |
Log4j2 | 2.20.0 | Log4j2 API, Log4j2 Core |
Commons IO | 2.18.0 | Commons IO |
SLF4J NOP | 2.0.17 | SLF4J NOP |
Configuration details can be found in the testng.xml
file and other relevant configuration files within the project. Log4j2 configuration is set up in the log4j2.xml
file to provide detailed logging.
The project uses Log4j2 for logging purposes. Ensure the necessary dependencies are included in your project and the log4j2.xml
file is correctly configured for detailed logging. Logging is crucial for tracking and debugging test execution; BaseDriver
utilizes Log4j2 to log test methods' start, end, and results.
Detailed documentation is available in the repository's README.md
file and inline comments within the codebase. Here are some tools and programs used:
This project includes several examples designed to demonstrate TestNG's capabilities, including:
- @Test: Define individual test methods.
- @BeforeClass/@AfterClass: Setup and teardown methods for test classes.
- @BeforeMethod/@AfterMethod: Run methods before and after each test method.
- Parallel Execution in XML: Configure parallel execution in the
testng.xml
file for faster test execution.
- Data Providers: Pass data to test methods dynamically using the
@DataProvider
annotation.
- Browser Setup: Set up tests to run on multiple browsers using WebDriver.
If you encounter any issues:
- Ensure that TestNG and Selenium WebDriver are properly installed and operational.
- Verify that your Java environment is correctly set up for TestNG and other dependencies.
- Check that your IntelliJ IDEA and other development tools are configured according to the project's requirements.
- If problems persist, check your Maven configurations to ensure all necessary dependencies are correctly included.
For additional help, please open an issue in the GitHub repository.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
For more information on how to get started, visit the TestNG Practice Lessons.