Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: maven

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
/.idea/
/allure-results/
/allure-report/
/.allure/
/.allure/
/.DS_Store
/*.iml
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<playwright-version>1.31.0</playwright-version>
<testng-version>7.7.1</testng-version>
<playwright-version>1.37.0</playwright-version>
<testng-version>7.8.0</testng-version>
<hamcrest-all-version>1.3</hamcrest-all-version>
<json-simple-version>1.1.1</json-simple-version>
<lombok-version>1.18.26</lombok-version>
<datafaker-version>1.8.0</datafaker-version>
<maven-compiler-plugin-version>3.10.1</maven-compiler-plugin-version>
<maven-surefire-plugin-version>3.0.0-M7</maven-surefire-plugin-version>
<java-release-version>11</java-release-version>
<org-json-verion>20230227</org-json-verion>
<lombok-version>1.18.28</lombok-version>
<datafaker-version>2.0.1</datafaker-version>
<org-json-verion>20230618</org-json-verion>
<maven-compiler-plugin-version>3.11.0</maven-compiler-plugin-version>
<maven-surefire-plugin-version>3.1.0</maven-surefire-plugin-version>
<java-release-version>17</java-release-version>
<maven-enforcer-version>3.4.0</maven-enforcer-version>
<suite-xml>test-suite/testng.xml</suite-xml>
</properties>
<dependencies>
Expand Down Expand Up @@ -88,7 +89,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
<version>${maven-enforcer-version}</version>
<executions>
<execution>
<id>enforce-maven</id>
Expand All @@ -108,5 +109,4 @@
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.mfaisalkhatri.api.manager;

import java.util.Map;

import com.microsoft.playwright.APIRequest;
import com.microsoft.playwright.APIRequestContext;
import com.microsoft.playwright.APIResponse;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.options.RequestOptions;

import java.util.Map;

/**
* @author Faisal Khatri
* @since 2/28/2023
Expand All @@ -18,63 +18,63 @@ public class RequestManager {
private APIRequestContext apiRequestContext;

public void createPlaywright() {
playwright = Playwright.create();
this.playwright = Playwright.create();

}

public void setApiRequestContext(String baseUrl, Map<String, String> headers) {
apiRequestContext = playwright.request()
public void setApiRequestContext(final String baseUrl, final Map<String, String> headers) {
this.apiRequestContext = this.playwright.request()
.newContext(new APIRequest.NewContextOptions().setBaseURL(baseUrl)
.setExtraHTTPHeaders(headers));
}

public APIResponse getRequest(String endpoint) {
return apiRequestContext.get(endpoint);
public APIResponse getRequest(final String endpoint) {
return this.apiRequestContext.get(endpoint);
}

public APIResponse getRequest(String endpoint, RequestOptions options) {
return apiRequestContext.get(endpoint, options);
public APIResponse getRequest(final String endpoint, final RequestOptions options) {
return this.apiRequestContext.get(endpoint, options);
}

public APIResponse postRequest(String endpoint) {
return apiRequestContext.post(endpoint);
public APIResponse postRequest(final String endpoint) {
return this.apiRequestContext.post(endpoint);
}

public APIResponse postRequest(String endpoint, RequestOptions options) {
return apiRequestContext.post(endpoint, options);
public APIResponse postRequest(final String endpoint, final RequestOptions options) {
return this.apiRequestContext.post(endpoint, options);
}

public APIResponse putRequest(String endpoint) {
return apiRequestContext.put(endpoint);
public APIResponse putRequest(final String endpoint) {
return this.apiRequestContext.put(endpoint);
}

public APIResponse putRequest(String endpoint, RequestOptions options) {
return apiRequestContext.put(endpoint, options);
public APIResponse putRequest(final String endpoint, final RequestOptions options) {
return this.apiRequestContext.put(endpoint, options);
}

public APIResponse patchRequest(String endpoint) {
return apiRequestContext.patch(endpoint);
public APIResponse patchRequest(final String endpoint) {
return this.apiRequestContext.patch(endpoint);
}

public APIResponse patchRequest(String endpoint, RequestOptions options) {
return apiRequestContext.patch(endpoint, options);
public APIResponse patchRequest(final String endpoint, final RequestOptions options) {
return this.apiRequestContext.patch(endpoint, options);

}

public APIResponse deleteRequest(String endpoint) {
return apiRequestContext.delete(endpoint);
public APIResponse deleteRequest(final String endpoint) {
return this.apiRequestContext.delete(endpoint);
}

public APIResponse deleteRequest(String endpoint, RequestOptions options) {
return apiRequestContext.delete(endpoint, options);
public APIResponse deleteRequest(final String endpoint, final RequestOptions options) {
return this.apiRequestContext.delete(endpoint, options);
}

public void disposeAPIRequestContext() {
apiRequestContext.dispose();
this.apiRequestContext.dispose();
}

public void closePlaywright() {
playwright.close();
this.playwright.close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

/**
* @author Faisal Khatri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class EmployeeDataBuilder {

public static EmployeeData getEmployeeData() {
Faker faker = new Faker();
final Faker faker = new Faker();
return EmployeeData.builder()
.name(faker.name()
.firstName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package io.github.mfaisalkhatri.api.reqres.tests;

import static io.github.mfaisalkhatri.api.reqres.data.EmployeeDataBuilder.getEmployeeData;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

import com.microsoft.playwright.APIResponse;
import com.microsoft.playwright.options.RequestOptions;
import io.github.mfaisalkhatri.api.reqres.data.EmployeeData;
import org.json.JSONObject;
import org.testng.annotations.Test;

import static io.github.mfaisalkhatri.api.reqres.data.EmployeeDataBuilder.getEmployeeData;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

/**
* @author Faisal Khatri
* @since 2/28/2023
**/
public class ApiTests extends BaseTest {
@Test
public void testGetAPI() {
APIResponse response = manager.getRequest("/api/users/4");
final APIResponse response = this.manager.getRequest("/api/users/4");
assertEquals(response.status(), 200);

JSONObject jsonObject = new JSONObject(response.text());
JSONObject dataObject = jsonObject.getJSONObject("data");
final JSONObject jsonObject = new JSONObject(response.text());
final JSONObject dataObject = jsonObject.getJSONObject("data");

assertEquals(dataObject.get("email")
.toString(), "eve.holt@reqres.in");
Expand All @@ -31,47 +31,47 @@ public void testGetAPI() {

@Test
public void testPostAPI() {
EmployeeData employeeData = getEmployeeData();
APIResponse response = manager.postRequest("/api/users", RequestOptions.create()
final EmployeeData employeeData = getEmployeeData();
final APIResponse response = this.manager.postRequest("/api/users", RequestOptions.create()
.setData(employeeData));
assertEquals(response.status(), 201);

JSONObject jsonObject = new JSONObject(response.text());
final JSONObject jsonObject = new JSONObject(response.text());
assertNotNull(jsonObject.get("id"));
assertEquals(jsonObject.get("name"), employeeData.getName());
assertEquals(jsonObject.get("job"), employeeData.getJob());
}

@Test
public void testPutAPI() {
EmployeeData employeeData = getEmployeeData();
APIResponse response = manager.putRequest("/api/users/2", RequestOptions.create()
final EmployeeData employeeData = getEmployeeData();
final APIResponse response = this.manager.putRequest("/api/users/2", RequestOptions.create()
.setData(employeeData));
assertEquals(response.status(), 200);

JSONObject jsonObject = new JSONObject(response.text());
final JSONObject jsonObject = new JSONObject(response.text());
assertNotNull(jsonObject.get("updatedAt"));
assertEquals(jsonObject.get("name"), employeeData.getName());
assertEquals(jsonObject.get("job"), employeeData.getJob());
}

@Test
public void testPatchAPI() {
EmployeeData employeeData = getEmployeeData();
APIResponse response = manager.patchRequest("/api/users/2", RequestOptions.create()
final EmployeeData employeeData = getEmployeeData();
final APIResponse response = this.manager.patchRequest("/api/users/2", RequestOptions.create()
.setData(employeeData));
assertEquals(response.status(), 200);

JSONObject jsonObject = new JSONObject(response.text());
final JSONObject jsonObject = new JSONObject(response.text());
assertNotNull(jsonObject.get("updatedAt"));
assertEquals(jsonObject.get("name"), employeeData.getName());
assertEquals(jsonObject.get("job"), employeeData.getJob());
}

@Test
public void testDeleteAPI() {
EmployeeData employeeData = getEmployeeData();
APIResponse response = manager.deleteRequest("/api/users/2", RequestOptions.create()
final EmployeeData employeeData = getEmployeeData();
final APIResponse response = this.manager.deleteRequest("/api/users/2", RequestOptions.create()
.setData(employeeData));
assertEquals(response.status(), 204);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.mfaisalkhatri.api.reqres.tests;

import java.util.HashMap;
import java.util.Map;

import io.github.mfaisalkhatri.api.manager.RequestManager;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.util.HashMap;
import java.util.Map;

/**
* @author Faisal Khatri
* @since 2/28/2023
Expand All @@ -17,17 +17,17 @@ public class BaseTest {

@BeforeClass
public void setup() {
manager = new RequestManager();
manager.createPlaywright();
String baseUrl = "https://reqres.in";
Map<String, String> headers = new HashMap<>();
this.manager = new RequestManager();
this.manager.createPlaywright();
final String baseUrl = "https://reqres.in";
final Map<String, String> headers = new HashMap<>();
headers.put("content-type", "application/json");
manager.setApiRequestContext(baseUrl, headers);
this.manager.setApiRequestContext(baseUrl, headers);
}

@AfterClass
public void tearDown() {
manager.disposeAPIRequestContext();
manager.closePlaywright();
this.manager.disposeAPIRequestContext();
this.manager.closePlaywright();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package io.github.mfaisalkhatri.api.restfulbooker.data;

import net.datafaker.Faker;

import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;

import net.datafaker.Faker;

/**
* @author Faisal Khatri
* @since 2/28/2023
**/
public class BookingDataBuilder {
public final class BookingDataBuilder {

private static final Faker FAKER = new Faker();

public static BookingData getBookingData() {
SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-dd");
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return BookingData.builder()
.firstname(FAKER.name()
.firstName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Faisal Khatri
* @since 2/28/2023
**/
public class TokenBuilder {
public final class TokenBuilder {

public static Tokencreds getToken() {
return Tokencreds.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public class BaseTest {

@BeforeTest
public void setupBase() {
manager = new RequestManager();
manager.createPlaywright();
this.manager = new RequestManager();
this.manager.createPlaywright();
final String baseUrl = "http://localhost:3001";
Map<String, String> headers = new HashMap<>();
final Map<String, String> headers = new HashMap<>();
headers.put("content-type", "application/json");
headers.put("Accept", "application/json");
manager.setApiRequestContext(baseUrl, headers);
this.manager.setApiRequestContext(baseUrl, headers);
}

@AfterTest
public void tearDown() {
manager.disposeAPIRequestContext();
manager.closePlaywright();
this.manager.disposeAPIRequestContext();
this.manager.closePlaywright();
}
}
Loading