Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java): ✨ added common config block for web #887

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a2f410f
feat(java): :sparkles: added common config block for web
WasiqB Aug 25, 2024
3229ff4
fix(java): :bug: fixed failing test cases
WasiqB Aug 25, 2024
698d3ca
fix(java): :bug: fixed failing api and grid tests
WasiqB Aug 25, 2024
ce3a0d4
fix(java): :bug: fixed failing grid and others tests
WasiqB Aug 25, 2024
5d8e5ac
fix(java): :bug: fixed failing others tests
WasiqB Aug 25, 2024
45d3ae0
feat(java): :sparkles: updated missing config with common config
WasiqB Aug 27, 2024
945c33f
fix(java): :bug: fixed failing web cloud tests
WasiqB Aug 27, 2024
a8a6956
fix(java): :bug: fixed failing mobile local tests
WasiqB Aug 28, 2024
482b220
fix(workflow): :bug: fixed failing mobile local workflow
WasiqB Aug 28, 2024
67fea0e
fix(workflow): :bug: fixed failing api and mobile workflow
WasiqB Aug 28, 2024
f05eec7
fix(workflow): :bug: fixing failing mobile local workflow
WasiqB Aug 28, 2024
bca7bbf
fix(workflow): :bug: fixing failing mobile local workflow try 2
WasiqB Aug 28, 2024
12715fe
fix(workflow): :bug: fixing failing mobile local workflow try 3
WasiqB Aug 28, 2024
eea6b3b
fix(workflow): :bug: fixing failing mobile local workflow try 4
WasiqB Aug 28, 2024
4d82439
fix(workflow): :bug: fixing failing mobile local workflow try 5
WasiqB Aug 28, 2024
26ab08f
fix(workflow): :bug: fixing failing mobile local workflow try 6
WasiqB Aug 28, 2024
4baa15c
fix(workflow): :bug: fixing failing mobile local workflow try 7
WasiqB Aug 29, 2024
f230a94
chore: fixed merge conflicts
WasiqB Aug 29, 2024
04af642
fix(workflow): :bug: fixing failing mobile local workflow try 8
WasiqB Aug 29, 2024
c479dbc
fix(workflow): :bug: fixing failing mobile local workflow try 9
WasiqB Aug 29, 2024
c1aa371
fix(workflow): :bug: fixing failing mobile local workflow try 10
WasiqB Aug 31, 2024
696f97b
fix(workflow): :bug: fixing failing mobile local workflow try 11
WasiqB Sep 1, 2024
08c8400
fix(workflow): :bug: fixing failing mobile local workflow try 12
WasiqB Sep 1, 2024
f7f3bbf
fix(workflow): :bug: fixing failing mobile local workflow try 13
WasiqB Sep 1, 2024
dc8a248
fix(workflow): :bug: fixing failing mobile local workflow try 14
WasiqB Sep 1, 2024
40a94df
fix(workflow): :bug: fixing failing mobile local workflow try 15
WasiqB Sep 1, 2024
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
6 changes: 5 additions & 1 deletion .github/workflows/_test-core-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ on:
type: string
description: Emulator / Simulator name
default: Pixel_7_Pro
emulator-profile:
type: string
description: Emulator Profile name
default: pixel_6_pro
emulator-target:
type: string
description: Emulator target image
Expand Down Expand Up @@ -120,7 +124,7 @@ jobs:
api-level: ${{ inputs.emulator-version }}
target: ${{ inputs.emulator-target }}
arch: ${{ inputs.emulator-arch }}
profile: pixel_6_pro
profile: ${{ inputs.emulator-profile }}
channel: ${{ inputs.emulator-channel }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ jobs:
run-ios: true
run-android: true
emulator-name: Pixel_8_Pro
emulator-profile: pixel_6_pro
emulator-version: 30
emulator-channel: canary
emulator-arch: x86
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.20.3
v18.20.4
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@
import static io.github.boykaframework.enums.Message.AUTH_PASSWORD_REQUIRED;
import static io.github.boykaframework.enums.Message.BASE_URL_EMPTY;
import static io.github.boykaframework.enums.Message.CONTENT_TYPE_NOT_SET;
import static io.github.boykaframework.enums.Message.EMPTY_REQUEST_BODY;
import static io.github.boykaframework.enums.Message.EMPTY_URL;
import static io.github.boykaframework.enums.Message.ERROR_EXECUTING_REQUEST;
import static io.github.boykaframework.enums.Message.ERROR_PARSING_REQUEST_BODY;
import static io.github.boykaframework.enums.Message.ERROR_PARSING_RESPONSE_BODY;
import static io.github.boykaframework.enums.Message.SSL_CONTEXT_EMPTY;
import static io.github.boykaframework.enums.Message.SSL_ERROR;
import static io.github.boykaframework.enums.RequestMethod.GET;
import static io.github.boykaframework.manager.ParallelSession.getSession;
import static io.github.boykaframework.utils.ErrorHandler.handleAndThrow;
import static io.github.boykaframework.utils.StringUtils.interpolate;
import static io.github.boykaframework.utils.Validator.requireNonEmpty;
import static io.github.boykaframework.utils.Validator.requireNonNull;
import static io.github.boykaframework.utils.Validator.requireNonNullElse;
import static java.lang.String.join;
import static java.text.MessageFormat.format;
import static java.time.Duration.ofSeconds;
import static java.util.Objects.isNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;
import static java.util.Optional.ofNullable;
import static javax.net.ssl.SSLContext.getInstance;
import static okhttp3.Credentials.basic;
import static okhttp3.MediaType.parse;
import static okhttp3.RequestBody.create;
Expand All @@ -51,6 +56,7 @@
import java.util.Map;
import java.util.function.BiConsumer;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

Expand All @@ -61,7 +67,6 @@
import io.github.boykaframework.builders.ApiRequest;
import io.github.boykaframework.builders.ApiResponse;
import io.github.boykaframework.config.api.ApiSetting;
import io.github.boykaframework.config.api.CommonApiSetting;
import io.github.boykaframework.config.api.LogSetting;
import io.github.boykaframework.enums.ContentType;
import io.github.boykaframework.enums.RequestMethod;
Expand Down Expand Up @@ -99,7 +104,6 @@ public static IApiActions withRequest (final ApiRequest request) {
private final ApiRequest apiRequest;
private final ApiSetting apiSetting;
private final OkHttpClient client;
private final CommonApiSetting commonApiSetting;
private final IApiActionsListener listener;
private final LogSetting logSetting;
private MediaType mediaType;
Expand All @@ -114,12 +118,11 @@ private ApiActions (final ApiRequest apiRequest) {
this.listener = getSession ().getListener (API_ACTION);
this.apiRequest = apiRequest;
this.pathParams = new HashMap<> ();
this.commonApiSetting = getSession ().getCommonApiSetting ();
this.apiSetting = getSession ().getApiSetting ();

final var builder = getApiBuilder ();
this.client = builder.build ();
this.logSetting = requireNonNullElse (this.apiSetting.getLogging (), this.commonApiSetting.getLogging ());
this.logSetting = this.apiSetting.getLogging ();
this.request = new Request.Builder ();
LOGGER.traceExit ();
}
Expand Down Expand Up @@ -152,8 +155,7 @@ private void addHeader (final String name, final String value) {
private ApiActions basicAuth (final String userName, final String password) {
if (!isNull (userName)) {
LOGGER.traceEntry ("Parameters: userName={}", userName);
final var credentials = basic (userName,
requireNonNull (password, AUTH_PASSWORD_REQUIRED.getMessageText ()));
final var credentials = basic (userName, requireNonNull (password, AUTH_PASSWORD_REQUIRED));
addHeader ("Authorization", credentials);
}
return LOGGER.traceExit (this);
Expand All @@ -169,7 +171,7 @@ private <T> ApiActions body (final T body) {

private ApiActions body (final String body) {
LOGGER.traceEntry ();
this.requestBody = create (body, requireNonNull (this.mediaType, CONTENT_TYPE_NOT_SET.getMessageText ()));
this.requestBody = create (body, requireNonNull (this.mediaType, CONTENT_TYPE_NOT_SET));
return LOGGER.traceExit (this);
}

Expand All @@ -178,8 +180,7 @@ private ApiActions body (final Map<String, String> bodyMap) {
final var body = new ArrayList<String> ();
bodyMap.forEach ((k, v) -> body.add (format ("{0}={1}", k, v)));
if (!body.isEmpty ()) {
this.requestBody = create (join ("&", body),
requireNonNull (this.mediaType, CONTENT_TYPE_NOT_SET.getMessageText ()));
this.requestBody = create (join ("&", body), requireNonNull (this.mediaType, CONTENT_TYPE_NOT_SET));
}
return LOGGER.traceExit (this);
}
Expand All @@ -202,15 +203,14 @@ private void fillMap (final Map<String, String> map, final BiConsumer<String, St
}

private OkHttpClient.Builder getApiBuilder () {
final var timeout = requireNonNullElse (this.apiSetting.getTimeout (), this.commonApiSetting.getTimeout ());
final var timeout = this.apiSetting.getTimeout ();
final var builder = new OkHttpClient.Builder ().connectTimeout (ofSeconds (timeout.getConnectionTimeout ()))
.readTimeout (ofSeconds (timeout.getReadTimeout ()))
.writeTimeout (ofSeconds (timeout.getWriteTimeout ()));
if (!this.apiSetting.isValidateSsl () || !this.commonApiSetting.isValidateSsl ()) {
builder.sslSocketFactory (requireNonNull (getSslContext ()).getSocketFactory (),
(X509TrustManager) getTrustedCertificates ()[0]);
if (!this.apiSetting.isValidateSsl ()) {
builder.sslSocketFactory (getSslContext (), (X509TrustManager) getTrustedCertificates ()[0]);
}
if (!this.apiSetting.isVerifyHostName () || !this.commonApiSetting.isVerifyHostName ()) {
if (!this.apiSetting.isVerifyHostName ()) {
builder.hostnameVerifier ((hostname, session) -> true);
}
return builder;
Expand All @@ -230,7 +230,7 @@ private String getRequestBody (final RequestBody body) {
private ApiResponse getResponse (final Map<String, String> queryParams, final String path) {
LOGGER.traceEntry ("Parameters: {}", path);
try {
final var urlBuilder = requireNonNull (HttpUrl.parse (getUrl (path))).newBuilder ();
final var urlBuilder = requireNonNull (HttpUrl.parse (getUrl (path)), EMPTY_URL).newBuilder ();
queryParams.forEach (urlBuilder::addQueryParameter);
this.response = parseResponse (this.client.newCall (this.request.url (urlBuilder.build ())
.build ())
Expand All @@ -243,15 +243,15 @@ private ApiResponse getResponse (final Map<String, String> queryParams, final St
return LOGGER.traceExit (this.response);
}

private SSLContext getSslContext () {
private SSLSocketFactory getSslContext () {
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance ("SSL");
sslContext = getInstance ("SSL");
sslContext.init (null, getTrustedCertificates (), new java.security.SecureRandom ());
} catch (final NoSuchAlgorithmException | KeyManagementException e) {
handleAndThrow (SSL_ERROR, e, e.getMessage ());
}
return sslContext;
return requireNonNull (sslContext, SSL_CONTEXT_EMPTY).getSocketFactory ();
}

private TrustManager[] getTrustedCertificates () {
Expand Down Expand Up @@ -279,7 +279,7 @@ private String getUrl () {
if (this.apiSetting.getPort () > 0) {
hostName = format ("{0}:{1}", hostName, this.apiSetting.getPort ());
}
final var basePath = requireNonNullElse (this.apiSetting.getBasePath (), this.commonApiSetting.getBasePath ());
final var basePath = this.apiSetting.getBasePath ();
return LOGGER.traceExit (format ("{0}{1}", hostName, basePath));
}

Expand Down Expand Up @@ -326,8 +326,8 @@ private void logResponse () {

private ApiActions method (final RequestMethod method) {
LOGGER.traceEntry ("Parameter: {}", method);
if (method != RequestMethod.GET) {
this.request.method (method.name (), requireNonNull (this.requestBody));
if (method != GET) {
this.request.method (method.name (), requireNonNull (this.requestBody, EMPTY_REQUEST_BODY));
}
return LOGGER.traceExit (this);
}
Expand Down Expand Up @@ -362,7 +362,6 @@ private ApiResponse parseResponse (final Response res) {
.headers (headers)
.networkResponse (parseResponse (res.networkResponse ()))
.apiSetting (this.apiSetting)
.commonApiSetting (this.commonApiSetting)
.networkResponse (parseResponse (res.networkResponse ()))
.previousResponse (parseResponse (res.priorResponse ()))
.receivedResponseAt (res.receivedResponseAtMillis ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.boykaframework.actions.drivers;

import static com.google.common.truth.Truth.assertWithMessage;
import static io.github.boykaframework.actions.CommonActions.getDriverAttribute;
import static io.github.boykaframework.actions.CommonActions.performDriverAction;
import static io.github.boykaframework.enums.ListenerType.DRIVER_ACTION;
Expand All @@ -33,6 +34,7 @@
import static java.text.MessageFormat.format;
import static java.util.Objects.isNull;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.logging.log4j.LogManager.getLogger;

import java.io.BufferedWriter;
Expand All @@ -41,13 +43,15 @@
import java.time.Duration;
import java.util.function.Function;

import com.google.common.truth.StringSubject;
import io.github.boykaframework.actions.interfaces.drivers.IDriverActions;
import io.github.boykaframework.actions.interfaces.listeners.drivers.IDriverActionsListener;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.RemoteWebDriver;

/**
* Device / Browser specific actions.
Expand All @@ -74,6 +78,14 @@ private DriverActions () {
this.listener = getSession ().getListener (DRIVER_ACTION);
}

@Override
public String capability (final String name) {
LOGGER.traceEntry ();
LOGGER.info ("Getting the capability of [{}]...", name);
ofNullable (this.listener).ifPresent (l -> l.onCapability (name));
return LOGGER.traceExit (getCapability (name));
}

@Override
@SuppressWarnings ("unchecked")
public <T> T executeScript (final String script, final Object... args) {
Expand Down Expand Up @@ -138,6 +150,14 @@ public void saveLogs () {
LOGGER.traceExit ();
}

@Override
public StringSubject verifyCapability (final String capabilityName) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying the capability of [{}]...", capabilityName);
ofNullable (this.listener).ifPresent (l -> l.onCapability (capabilityName));
return assertWithMessage (capabilityName).that (getCapability (capabilityName));
}

@Override
public <T> void waitUntil (final Function<WebDriver, T> condition) {
LOGGER.traceEntry ();
Expand All @@ -149,6 +169,11 @@ public <T> void waitUntil (final Function<WebDriver, T> condition) {
});
}

private String getCapability (final String name) {
return getDriverAttribute (d -> ((RemoteWebDriver) d).getCapabilities ()
.getCapability (name), EMPTY).toString ();
}

private <D extends WebDriver> void saveLogType (final D driver, final String logType, final String logPath) {
final var logEntries = driver.manage ()
.logs ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.function.Function;

import com.google.common.truth.StringSubject;
import org.openqa.selenium.WebDriver;

/**
Expand All @@ -28,6 +29,15 @@
* @since 16-Feb-2023
*/
public interface IDriverActions {
/**
* Get Current sessions capability based on the name.
*
* @param name Name of capability
*
* @return value of the capability
*/
String capability (String name);

/**
* Executes javascript in browser.
*
Expand All @@ -51,6 +61,15 @@ public interface IDriverActions {
*/
void saveLogs ();

/**
* Verify the current sessions capability based on its name
*
* @param capabilityName Name of capability to verify
*
* @return String subject to verify the capability value
*/
StringSubject verifyCapability (String capabilityName);

/**
* Wait for a specific condition to be true.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
* @since 09-Apr-2023
*/
public interface IDriverActionsListener extends BoykaListener {
/**
* Handles get capability method
*
* @param capability Name of capability
*/
default void onCapability (final String capability) {
// not implemented.
}

/**
* Handle execute script method.
*
Expand All @@ -53,6 +62,15 @@ default void onSaveLogs () {
// not implemented.
}

/**
* Handles verify capability method.
*
* @param capability Name of capability
*/
default void onVerifyCapability (final String capability) {
// not implemented.
}

/**
* Handle wait until method.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static io.github.boykaframework.utils.ErrorHandler.throwError;
import static java.lang.System.getProperty;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;
import static org.apache.logging.log4j.LogManager.getLogger;

import java.io.FileInputStream;
Expand All @@ -43,7 +42,6 @@
import com.google.common.truth.StringSubject;
import com.jayway.jsonpath.DocumentContext;
import io.github.boykaframework.config.api.ApiSetting;
import io.github.boykaframework.config.api.CommonApiSetting;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
Expand All @@ -63,7 +61,6 @@ public class ApiResponse {

private ApiSetting apiSetting;
private String body;
private CommonApiSetting commonApiSetting;
private Map<String, String> headers;
private ApiResponse networkResponse;
private ApiResponse previousResponse;
Expand Down Expand Up @@ -155,10 +152,9 @@ public void verifySchema (final String schemaName) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying Response Schema");
try (
final var inputStream = new FileInputStream (Path.of (getProperty ("user.dir"), "/src/test/resources",
requireNonNullElse (this.apiSetting.getSchemaPath (), this.commonApiSetting.getSchemaPath ()),
schemaName)
.toFile ())) {
final var inputStream = new FileInputStream (
Path.of (getProperty ("user.dir"), "/src/test/resources", this.apiSetting.getSchemaPath (), schemaName)
.toFile ())) {
final var factory = getInstance (V7);
final var jsonSchema = factory.getSchema (inputStream);
final var errors = jsonSchema.validate (new ObjectMapper ().readTree (this.body));
Expand Down
Loading
Loading