├── src
├── main
│ └── java
│ │ └── com
│ │ └── blibli
│ │ └── oss
│ │ └── qa
│ │ └── util
│ │ ├── model
│ │ ├── Constant.java
│ │ ├── HarModel.java
│ │ ├── RequestResponsePair.java
│ │ └── RequestResponseStorage.java
│ │ ├── har
│ │ └── Pages.java
│ │ ├── ResponseModel.java
│ │ ├── json
│ │ └── JSONUtil.java
│ │ └── services
│ │ ├── DevToolsServices.java
│ │ ├── HarEntryConverter.java
│ │ └── NetworkListener.java
└── test
│ └── java
│ └── com
│ └── blibli
│ └── oss
│ └── qa
│ └── util
│ ├── BaseTest.java
│ ├── AppTestWithHarFilter.java
│ ├── UsingCdpTest.java
│ ├── UnicodeTest.java
│ ├── AppTest.java
│ └── ThreadSafeHarCreationTest.java
├── .gitignore
├── .github
└── workflows
│ ├── maven.yml
│ └── maven-publish.yml
├── settings.xml
├── README.md
├── pom.xml
└── LICENSE
/src/main/java/com/blibli/oss/qa/util/model/Constant.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util.model;
2 |
3 | public class Constant {
4 | public static String DEFAULT_UNICODE="UTF-8";
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/blibli/oss/qa/util/har/Pages.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util.har;
2 |
3 | import java.util.Date;
4 |
5 | public class Pages {
6 | private Date startedDate;
7 | private Date endedDate;
8 | }
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | pom.xml.tag
3 | pom.xml.releaseBackup
4 | pom.xml.versionsBackup
5 | pom.xml.next
6 | release.properties
7 | dependency-reduced-pom.xml
8 | buildNumber.properties
9 | .mvn/timing.properties
10 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar
11 | .mvn/wrapper/maven-wrapper.jar
12 | .idea/
13 | *.har
14 | *.iml
--------------------------------------------------------------------------------
/src/main/java/com/blibli/oss/qa/util/model/HarModel.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util.model;
2 |
3 | import lombok.Data;
4 |
5 | import org.openqa.selenium.remote.http.HttpRequest;
6 | import org.openqa.selenium.remote.http.HttpResponse;
7 |
8 | @Data
9 | public class HarModel {
10 | private HttpRequest httpRequest;
11 | private HttpResponse httpResponse;
12 |
13 | public HarModel(HttpRequest httpRequest, HttpResponse httpResponse) {
14 | this.httpRequest = httpRequest;
15 | this.httpResponse = httpResponse;
16 | }
17 |
18 | public HttpRequest getHttpRequest() {
19 | return this.httpRequest;
20 | }
21 |
22 | public HttpResponse getHttpResponse() {
23 | return this.httpResponse;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/com/blibli/oss/qa/util/BaseTest.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util;
2 |
3 | import com.blibli.oss.qa.util.services.NetworkListener;
4 | import io.github.bonigarcia.wdm.WebDriverManager;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.chrome.ChromeOptions;
7 | import org.openqa.selenium.remote.DesiredCapabilities;
8 |
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.nio.file.Files;
12 | import java.nio.file.Paths;
13 | import java.util.Optional;
14 |
15 | public class BaseTest {
16 |
17 |
18 |
19 | public String readHarData(String fileName) throws IOException {
20 | String harFile = Paths.get(".").toAbsolutePath().normalize().toString() + ""+File.separator +""+fileName;
21 | System.out.println("Read Har Data " + harFile);
22 | return new String(Files.readAllBytes(Paths.get(fileName)));
23 | }
24 |
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/main/java/com/blibli/oss/qa/util/ResponseModel.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util;
2 |
3 |
4 | import org.openqa.selenium.devtools.v142.network.model.ResponseReceived;
5 | import org.openqa.selenium.devtools.v142.network.Network;
6 |
7 | public class ResponseModel {
8 | ResponseReceived responseReceived;
9 | Network.GetResponseBodyResponse getResponseBodyResponse;
10 |
11 | public ResponseReceived getResponseReceived() {
12 | return responseReceived;
13 | }
14 |
15 | public void setResponseReceived(ResponseReceived responseReceived) {
16 | this.responseReceived = responseReceived;
17 | }
18 |
19 | public Network.GetResponseBodyResponse getGetResponseBodyResponse() {
20 | return getResponseBodyResponse;
21 | }
22 |
23 | public void setGetResponseBodyResponse(Network.GetResponseBodyResponse getResponseBodyResponse) {
24 | this.getResponseBodyResponse = getResponseBodyResponse;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: Java CI with Maven
5 |
6 | on:
7 | push:
8 | branches: [ master ]
9 | pull_request:
10 | branches: [ master ]
11 |
12 | env:
13 | ## Sets environment variable
14 | CHROME_MODE: HEADLESS
15 |
16 | jobs:
17 | build:
18 |
19 | runs-on: ubuntu-latest
20 |
21 | steps:
22 | - uses: actions/checkout@v3
23 | - name: Set up JDK 11
24 | uses: actions/setup-java@v3
25 | with:
26 | java-version: '11'
27 | distribution: 'temurin'
28 | cache: maven
29 | server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
30 | settings-path: ${{ github.workspace }} # location for the settings.xml file
31 |
32 | - uses: browser-actions/setup-chrome@latest
33 | - name: test chrome
34 | run: chrome --version
35 | - name: Build with Maven
36 | run: mvn -B clean verify --file pom.xml -s $GITHUB_WORKSPACE/settings.xml -Dfile.encoding=UTF-8
37 |
--------------------------------------------------------------------------------
/src/main/java/com/blibli/oss/qa/util/model/RequestResponsePair.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util.model;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 | import org.openqa.selenium.devtools.v142.network.model.*;
6 |
7 |
8 | import java.util.Date;
9 |
10 | @Getter
11 | @Setter
12 | public class RequestResponsePair {
13 | private String requestId;
14 | private Request request;
15 | private RequestWillBeSent requestWillBeSent;
16 | private RequestWillBeSentExtraInfo requestWillBeSentExtraInfo;
17 | private Response response;
18 | private ResponseReceivedExtraInfo responseReceivedExtraInfo;
19 | private LoadingFailed loadingFailed;
20 | private LoadingFinished loadingFinished;
21 | private Date requestOn;
22 | private String responseBody;
23 |
24 | public RequestResponsePair(Request request, Date requestOn, String responseBody) {
25 | this.request = request;
26 | this.requestOn = requestOn;
27 | this.responseBody = responseBody;
28 | }
29 |
30 | public RequestResponsePair(String requestId, Request request, Date requestOn, String responseBody) {
31 | this.requestId = requestId;
32 | this.request = request;
33 | this.requestOn = requestOn;
34 | this.responseBody = responseBody;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
23 |
24 |
25 | github
26 | ${env.USERNAME}
27 | ${env.GITHUB_TOKEN}
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/main/java/com/blibli/oss/qa/util/model/RequestResponseStorage.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util.model;
2 |
3 | import lombok.Getter;
4 | import org.openqa.selenium.devtools.v142.network.model.LoadingFailed;
5 | import org.openqa.selenium.devtools.v142.network.model.Request;
6 | import org.openqa.selenium.devtools.v142.network.model.Response;
7 | import org.openqa.selenium.devtools.v142.network.model.ResponseReceivedExtraInfo;
8 |
9 | import java.util.Collections;
10 | import java.util.Date;
11 | import java.util.List;
12 | import java.util.concurrent.CopyOnWriteArrayList;
13 |
14 | @Getter
15 | public class RequestResponseStorage {
16 | private final List requestResponsePairs;
17 |
18 | public RequestResponseStorage() {
19 | this.requestResponsePairs = new CopyOnWriteArrayList<>();
20 | }
21 |
22 | public void addRequest(Request request, Date requestOn) {
23 | requestResponsePairs.add(new RequestResponsePair(request, requestOn, null));
24 | }
25 |
26 | public void addRequest(String requestId, Request request, Date requestOn) {
27 | requestResponsePairs.add(new RequestResponsePair(requestId, request, requestOn, null));
28 | }
29 |
30 | public void addResponse(Response response, String responseBody) {
31 | for (int i = 0; i < requestResponsePairs.size(); i++) {
32 | if (requestResponsePairs.get(i).getRequest().getUrl().equals(response.getUrl())) {
33 | requestResponsePairs.get(i).setResponse(response);
34 | requestResponsePairs.get(i).setResponseBody(responseBody);
35 | break;
36 | }
37 | }
38 | }
39 |
40 | public void addLoadingFailed(LoadingFailed loadingFailed){
41 | for (int i = 0; i < requestResponsePairs.size(); i++) {
42 | if (requestResponsePairs.get(i).getRequestId().equals(loadingFailed.getRequestId().toString())) {
43 | requestResponsePairs.get(i).setLoadingFailed(loadingFailed);
44 | break;
45 | }
46 | }
47 | }
48 |
49 | public void addresponseReceivedExtraInfo(ResponseReceivedExtraInfo responseReceivedExtraInfoConsumer) {
50 | for (int i = 0; i < requestResponsePairs.size(); i++) {
51 | if (requestResponsePairs.get(i).getRequestId().equals(responseReceivedExtraInfoConsumer.getRequestId().toString())) {
52 | requestResponsePairs.get(i).setResponseReceivedExtraInfo(responseReceivedExtraInfoConsumer);
53 | break;
54 | }
55 | }
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/src/main/java/com/blibli/oss/qa/util/json/JSONUtil.java:
--------------------------------------------------------------------------------
1 | package com.blibli.oss.qa.util.json;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 |
6 | import java.io.IOException;
7 | import java.nio.charset.StandardCharsets;
8 | import java.nio.file.Files;
9 | import java.nio.file.Path;
10 | import java.nio.file.Paths;
11 | import java.util.ArrayList;
12 |
13 | public class JSONUtil {
14 |
15 | // create function for writting json file with given path from object
16 | public static void appendJson(Object obj, String path) {
17 | // read json file from path
18 | String json = JSONUtil.readJson(path);
19 | ObjectMapper mapper = new ObjectMapper();
20 | // convert json to json objectMapper
21 | ArrayList