Framework
Framework
Framework
├── main/
│ ├── java/
│ │ └── com/
│ │ └── project/
│ └── resources/
├── test/
│ └── java/
│ └── com/
│ └── project/
config/
### Step-by-Step Example of Setting Up Test Execution with TestNG and Cucumber
```xml
<dependencies>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
<!-- Add other dependencies like Selenium, Extent Reports, etc. -->
</dependencies>
```
Create a **TestNG runner** class to run Cucumber feature files. This runner allows
Cucumber tests to be executed as TestNG tests, making use of TestNG’s parallel execution,
reporting, and suite management.
```java
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
@CucumberOptions(
features = "src/test/resources/features",
glue = "stepdefinitions",
plugin = {"pretty", "html:target/cucumber-reports"}
)
public class CucumberTestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
```
- The `@CucumberOptions` annotation specifies the **feature files** and **step
definition** locations.
- The `DataProvider` allows parallel execution for each scenario if desired.
TestNG’s `testng.xml` can be used to manage and control the execution order of both
**Cucumber tests** and **traditional TestNG tests**. You can include the
`CucumberTestRunner` in the `testng.xml` file alongside other TestNG test classes.
Example `testng.xml`:
```xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automation Suite" parallel="tests" thread-count="2">
1. **Extent Reports/Allure Reports**: Both TestNG and Cucumber results can be integrated
into unified reports for a single view of test results. Extent Reports or Allure Reports can
capture results from both TestNG and Cucumber test runs.
2. **Jenkins CI/CD Integration**:
- Configure **Jenkins** to trigger the `testng.xml` suite for continuous integration.
- Jenkins can handle notifications, archive reports, and provide feedback to the team on
test outcomes.
Gist
### Real-Time Execution Scenario Example
1. **Developer Pushes Code**: A developer commits code, which triggers Jenkins to build
the project using Maven (`mvn clean install`).
2. **Running Tests**:
- Jenkins runs `testng.xml`, which:
- Executes Cucumber tests via the `CucumberTestRunner`.
- Runs additional TestNG tests defined in the suite.
3. **Parallel and Sequential Execution**: Using `testng.xml`, tests can be configured to run
in parallel (for Cucumber scenarios) and in sequence (for TestNG tests).
4. **Report Generation and Notifications**:
- After execution, reports are generated and stored in Jenkins, and notifications are sent to
relevant team members with links to the report.
Cucumber handles BDD scenarios, while TestNG is used for other types of tests. We typically
set up a **TestNG runner** to execute Cucumber feature files, and both Cucumber and
TestNG tests are managed through **testng.xml** for suite execution. This integration
allows us to use TestNG’s capabilities (like parallel execution and dependency management)
with Cucumber’s BDD features, providing comprehensive test coverage across different types
of tests. **Jenkins** manages the CI/CD pipeline, executing our tests on each code commit,
and **Maven** handles dependencies and builds.
Parallel Execution
Running both TestNG and Cucumber tests in parallel can be challenging due to
differences in how parallel execution is managed.
In real projects, it’s common to run either TestNG or Cucumber tests in parallel
independently, rather than trying to run both simultaneously in parallel. For example:
In real-time projects, we usually separate TestNG and Cucumber tests in parallel execution
due to their differences. If parallelism is required, we handle it at the job level in Jenkins,
where one job may run Cucumber scenarios in parallel, and another job runs TestNG tests in
parallel. This approach maintains test efficiency while avoiding the complexities of managing
both frameworks simultaneously in parallel within a single suite.
● Programming language
● Framework type: Data driven framework or keyword driver by using page object model
● Packages:
⮚ All the web page related classes come under the pages package
⮚ And all the tests related classes come under Tests package.
https://chatgpt.com/share/f9f28d22-ecf8-4d11-bd5d-eb4f185649a2
● https://chatgpt.com/share/f9f28d22-ecf8-4d11-bd5d-eb4f185649a2
● https://chatgpt.com/share/f9f28d22-ecf8-4d11-bd5d-eb4f185649a2
●
Here are some common automation framework interview questions with answers based on your
experience:
1. Where did you implement OOPS concepts in your framework? Give examples
for each one.
Answer:
1. Encapsulation:
○ Encapsulation is achieved by keeping WebElement locators private in the
webelements package classes and accessing them through public getter methods
in the functions package.
● Example:
java
Copy code
public class LoginPage {
● public By getUsername() {
● return username;
● }
● public By getPassword() {
● return password;
● }
● }
○
2. Inheritance:
○ The BaseClass serves as the parent class, providing common methods such as
browser setup, initialization of WebDriver, and handling timeouts. Test classes in the
testcases package extend BaseClass.
● Example:
java
Copy code
public class BaseClass {
● }
● }
● @Test
● setup();
● // Test steps
● }
● }
○
3. Polymorphism:
○ Method overloading is used for reusable methods like taking screenshots, where we
provide different parameters.
● Example:
java
Copy code
public void takeScreenshot(String testName) {
● }
● }
○
4. Abstraction:
○ Interfaces are used for reporting functionality like ILog to separate the logging
mechanism (Log4j, Extent Reports) from implementation.
● Example:
java
Copy code
public interface ILog {
● }
● }
● }
1. config.properties:
○ Contains key-value pairs for environment-specific data like browser, URL,
timeout, and screenshotPath.
● Example:
makefile
Copy code
browser=chrome
● timeout=30
● screenshotPath=./screenshots
○
2. BaseClass:
○ Reads the properties file using Properties class and sets the configurations.
● Example:
java
Copy code
Properties prop = new Properties();
● driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(I
nteger.parseInt(prop.getProperty("timeout"))));
○
3. Screenshots:
○ Screenshot path is fetched from config.properties in the BaseClass and
passed to the screenshot method.
● Example:
java
Copy code
String screenshotPath = prop.getProperty("screenshotPath");
● FileUtils.copyFile(src, dest);
● }
○
4. Timeouts:
○ Timeout values like implicit, explicit, and Fluent Wait are managed centrally through
config.properties.
● Example:
java
Copy code
int timeout = Integer.parseInt(prop.getProperty("timeout"));