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
Gitand enter the repository URL:https://github.com/cihat-kose/testng-practice-lessons.git. - Click
Clone.
This repository now follows the standard Maven project layout. After cloning the project, let Maven download the required dependencies:
mvn dependency:resolveYou can also import the project into IntelliJ IDEA or Eclipse as a Maven
project; the IDE will automatically recognise the configuration defined in
pom.xml.
Maven downloads every dependency declared in the pom.xml file automatically,
so you only need to ensure that a compatible JDK is installed (Java 11 or
higher).
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=src/test/java/_08_CrossBrowserTesting/cross-browser-test.xmlYou 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 | 4.35.0 | Selenium |
| Log4j2 | 2.23.1 | Log4j2 API, Log4j2 Core |
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 src/test/resources/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.xmlfile for faster test execution.
- Data Providers: Pass data to test methods dynamically using the
@DataProviderannotation.
- 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.