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): ✨ allowed using default instance for api request and locators #923

Merged
merged 19 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
aec2eba
feat(java): :sparkles: allowed using default instance for api request…
WasiqB Nov 7, 2024
4728261
fix(workflow): :bug: fixing mobile test failure
WasiqB Nov 7, 2024
d1bb960
fix(workflow): :bug: fixing failing mobile test workflow
WasiqB Nov 7, 2024
91f5c02
fix(workflow): :bug: fixing mobile test failures
WasiqB Nov 7, 2024
5eee4f1
fix(workflow): :bug: fixing mobile failed workflows
WasiqB Nov 7, 2024
657b018
fix(workflow): :bug: fixing failing android workflow
WasiqB Nov 7, 2024
5751e68
fix(workflow): :bug: fixing failing android workflow
WasiqB Nov 7, 2024
6c12404
fix(workflow): :bug: fixing failing web and mobile test workflows
WasiqB Nov 7, 2024
57a1f3a
fix(workflow): :bug: fixing failing mobile test workflows
WasiqB Nov 7, 2024
7bddae8
fix(workflow): :bug: fixing failing ios test workflows
WasiqB Nov 8, 2024
7ad7599
fix(workflow): :bug: fixing failing ios test workflows
WasiqB Nov 8, 2024
acdcbe3
fix(workflow): :bug: fixing failing ios test workflows
WasiqB Nov 8, 2024
fe9b429
fix(workflow): :bug: fixing failing android test workflows
WasiqB Nov 8, 2024
534eeff
fix(workflow): :bug: fixing failed android and ios workflows
WasiqB Nov 8, 2024
f34745c
fix(workflow): :bug: fixing failed android and ios workflows
WasiqB Nov 8, 2024
a6dae28
fix(workflow): :bug: fixing failed android and ios workflows
WasiqB Nov 8, 2024
f185a22
fix(workflow): :bug: fixing failed android workflows
WasiqB Nov 8, 2024
b054042
fix(workflow): :bug: fixing failed android workflows
WasiqB Nov 8, 2024
15ab808
chore(website): :arrow_up: upgraded dependencies
WasiqB Nov 8, 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
49 changes: 46 additions & 3 deletions .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 @@ -91,7 +95,12 @@ jobs:
- name: Install Appium 2.0
if: ${{ inputs.run-appium }}
run: |
brew install ffmpeg
if [ "${{ startsWith(inputs.runs-on, 'ubuntu') }}" == "true" ]; then
sudo apt update && sudo apt upgrade
sudo apt install ffmpeg
else
brew install ffmpeg
fi
npm install -g appium
appium driver install uiautomator2
appium driver install xcuitest
Expand All @@ -111,6 +120,40 @@ jobs:
os: 'iOS'
os_version: ${{ inputs.simulator-version }}
shutdown_after_job: true
wait_for_boot: true
erase_before_boot: true

- name: Enable KVM
if: inputs.run-android
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: AVD cache
uses: actions/cache@v4
id: avd-cache
if: inputs.run-android
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ inputs.emulator-name }}-${{ inputs.emulator-version }}-${{ inputs.emulator-profile }}-${{ inputs.emulator-arch }}-${{ inputs.emulator-target }}-${{ inputs.emulator-channel }}

- name: create AVD and generate snapshot for caching
if: inputs.run-android && steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
avd-name: ${{ inputs.emulator-name }}
api-level: ${{ inputs.emulator-version }}
target: ${{ inputs.emulator-target }}
arch: ${{ inputs.emulator-arch }}
profile: ${{ inputs.emulator-profile }}
channel: ${{ inputs.emulator-channel }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: All Test execution
if: ${{ inputs.run-android }}
Expand All @@ -120,11 +163,11 @@ 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
disable-animations: false
disable-animations: true
pre-emulator-launch-script: avdmanager list device
script: mvn verify org.jacoco:jacoco-maven-plugin:prepare-agent -f core-java/pom.xml -Dsuite-name=${{ inputs.suite-name }} -Pcoverage-test

Expand Down
45 changes: 32 additions & 13 deletions .github/workflows/test-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,35 @@ jobs:
suite-name: testng-web-grid
run-grid: true

test-mobile-local:
test-mobile-android-local:
needs:
- check-cloud
uses: ./.github/workflows/_test-core-java.yml
with:
runs-on: macos-12
suite-name: testng-mobile-local
runs-on: ubuntu-latest
suite-name: testng-mobile-android-local
run-appium: true
run-ios: true
run-ios: false
run-android: true
emulator-name: Pixel_8_Pro
emulator-version: 30
emulator-channel: canary
emulator-arch: x86
emulator-target: aosp_atd
simulator-name: iPhone 14
simulator-version: 16.2
emulator-profile: pixel_6_pro
emulator-version: 31
# emulator-channel: canary
emulator-arch: x86_64
emulator-target: google_apis

test-mobile-ios-local:
needs:
- check-cloud
uses: ./.github/workflows/_test-core-java.yml
with:
runs-on: macos-14
suite-name: testng-mobile-ios-local
run-appium: true
run-ios: true
run-android: false
simulator-name: iPhone 15
simulator-version: 17.5

# test-mobile-web:
# needs:
Expand Down Expand Up @@ -185,7 +197,8 @@ jobs:
- test-web-bs
- test-web-lt
- test-web-grid
- test-mobile-local
- test-mobile-android-local
- test-mobile-ios-local
# - test-mobile-web
- test-mobile-bs
- test-mobile-lt
Expand Down Expand Up @@ -215,10 +228,16 @@ jobs:
name: reports-testng-mobile-bs
path: ${{ github.workspace }}/core-java/reports

- name: Download reports-testng-mobile-local files
- name: Download reports-testng-mobile-android-local files
uses: actions/download-artifact@v4
with:
name: reports-testng-mobile-android-local
path: ${{ github.workspace }}/core-java/reports

- name: Download reports-testng-mobile-ios-local files
uses: actions/download-artifact@v4
with:
name: reports-testng-mobile-local
name: reports-testng-mobile-ios-local
path: ${{ github.workspace }}/core-java/reports

# - name: Download reports-testng-mobile-web files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
@ToString
@Getter
@Builder (builderMethodName = "createRequest", buildMethodName = "create")
@Builder (toBuilder = true, builderMethodName = "createRequest", buildMethodName = "create")
public class ApiRequest {
private String body;
private Object bodyObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
@ToString
@Getter
@Builder (builderMethodName = "buildLocator")
@Builder (toBuilder = true, builderMethodName = "buildLocator")
public class Locator {
private By android;
private Predicate<WebElement> filter;
Expand All @@ -53,15 +53,11 @@ public class Locator {
* @return Locator for the element
*/
public By getLocator () {
switch (getSession ().getPlatformType ()) {
case ANDROID:
return getMobileOrWebLocator (this.android);
case IOS:
return getMobileOrWebLocator (this.ios);
case WEB:
default:
return this.web;
}
return switch (getSession ().getPlatformType ()) {
case ANDROID -> getMobileOrWebLocator (this.android);
case IOS -> getMobileOrWebLocator (this.ios);
default -> this.web;
};
}

private By getMobileOrWebLocator (final By locator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ public class DeviceSetting {
private VideoSetting video = new VideoSetting ();
private VirtualDeviceSetting virtualDevice = new VirtualDeviceSetting ();
private WDASetting wda;
private int webViewConnectRetries = 3;
private int webViewConnectTimeout = 60;
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ private void setupLocalSimulatorOptions (final XCUITestOptions options) {
options.setClearSystemFiles (this.settings.isClearFiles ());
options.setNoReset (this.settings.isNoReset ());
options.setFullReset (this.settings.isFullReset ());
options.setWebviewConnectTimeout (ofSeconds (this.settings.getWebViewConnectTimeout ()));
options.setWebviewConnectRetries (this.settings.getWebViewConnectRetries ());
options.setMaxTypingFrequency (this.settings.getTypingSpeed ());
setWdaOptions (this.settings.getWda (), options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package io.github.boykaframework.testng.api.postman;

import static io.github.boykaframework.actions.api.ApiActions.withRequest;
import static io.github.boykaframework.builders.ApiRequest.createRequest;
import static io.github.boykaframework.enums.ContentType.FORM_URLENCODED;
import static io.github.boykaframework.enums.PlatformType.API;
import static io.github.boykaframework.enums.RequestMethod.POST;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;

import io.github.boykaframework.actions.api.ApiActions;
import io.github.boykaframework.builders.ApiRequest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -56,16 +56,14 @@ public void tearDownTestClass () {
*/
@Test (description = "Test Form body POST request")
public void testFormBodyRequest () {
final var request = ApiRequest.createRequest ()
.contentType (FORM_URLENCODED)
final var request = createRequest ().contentType (FORM_URLENCODED)
.formBody ("strange", "boom")
.formBody ("test", "abc")
.method (POST)
.path ("/post")
.create ();

final var response = ApiActions.withRequest (request)
.execute ();
final var response = withRequest (request).execute ();
response.verifyStatusCode ()
.isEqualTo (200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package io.github.boykaframework.testng.api.restful;

import static io.github.boykaframework.actions.api.ApiActions.withRequest;
import static io.github.boykaframework.enums.PlatformType.API;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;

import java.text.DecimalFormat;

import io.github.boykaframework.actions.api.ApiActions;
import io.github.boykaframework.actions.interfaces.data.IDataRow;
import io.github.boykaframework.builders.ApiRequest;
import io.github.boykaframework.enums.PlatformType;
import io.github.boykaframework.enums.RequestMethod;
import io.github.boykaframework.testng.api.restful.data.BookingDataProviders;
import io.github.boykaframework.testng.api.restful.pojo.BookingData;
Expand All @@ -44,7 +44,7 @@
public class DataDrivenBookingTest {
@BeforeClass
public void setupClass () {
createSession (PlatformType.API, "test_restfulbooker");
createSession (API, "test_restfulbooker");
}

@AfterClass
Expand Down Expand Up @@ -106,8 +106,7 @@ private void testBooking (final BookingData bookingData) {
.bodyObject (bookingData)
.create ();

final var response = ApiActions.withRequest (request)
.execute ();
final var response = withRequest (request).execute ();

response.verifyStatusCode ()
.isEqualTo (200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package io.github.boykaframework.testng.api.restful;

import static io.github.boykaframework.actions.api.ApiActions.withRequest;
import static io.github.boykaframework.enums.PlatformType.API;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static io.github.boykaframework.manager.ParallelSession.getSession;
import static io.github.boykaframework.testng.api.restful.data.BookingRequestData.getBookingData;
import static io.github.boykaframework.testng.api.restful.requests.BookingRequest.createBooking;
import static io.github.boykaframework.testng.api.restful.requests.BookingRequest.deleteBooking;
import static io.github.boykaframework.testng.api.restful.requests.BookingRequest.getBooking;

import io.github.boykaframework.actions.api.ApiActions;
import io.github.boykaframework.exception.FrameworkError;
import io.github.boykaframework.testng.api.restful.data.BookingRequestData;
import io.github.boykaframework.testng.api.restful.pojo.BookingData;
Expand Down Expand Up @@ -54,7 +58,7 @@ public class RestfulBookerEndToEndTests {
@BeforeClass (description = "Setup test class")
public void setupTestClass () {
createSession (API, "test_restfulbooker");
this.newBooking = BookingRequestData.getBookingData ();
this.newBooking = getBookingData ();
}

/**
Expand All @@ -68,9 +72,8 @@ public void tearDownTestClass () {
@Story ("Create Booking with POST request")
@Test (description = "Test for creating new booking with POST request")
public void testCreateBooking () {
final var request = BookingRequest.createBooking (this.newBooking);
final var response = ApiActions.withRequest (request)
.execute ();
final var request = createBooking (this.newBooking);
final var response = withRequest (request).execute ();

response.verifyStatusCode ()
.isEqualTo (200);
Expand All @@ -93,29 +96,26 @@ public void testCreateBooking () {
@Story ("Delete Booking")
@Test (description = "Test for Deleting a booking using DELETE request")
public void testDeleteBooking () {
final var request = BookingRequest.deleteBooking (getSession ().getSharedData (BOOKING_ID));
final var response = ApiActions.withRequest (request)
.execute ();
final var request = deleteBooking (getSession ().getSharedData (BOOKING_ID));
final var response = withRequest (request).execute ();
response.verifyStatusCode ()
.isEqualTo (201);
}

@Story ("Get deleted Booking")
@Test (description = "Test for checking deleted booking using GET request")
public void testDeletedBooking () {
final var request = BookingRequest.getBooking (getSession ().getSharedData (BOOKING_ID));
final var response = ApiActions.withRequest (request)
.execute ();
final var request = getBooking (getSession ().getSharedData (BOOKING_ID));
final var response = withRequest (request).execute ();
response.verifyStatusCode ()
.isEqualTo (404);
}

@Story ("Get Created Booking")
@Test (description = "Test for retrieving booking using GET request")
public void testGetBooking () {
final var request = BookingRequest.getBooking (getSession ().getSharedData (BOOKING_ID));
final var response = ApiActions.withRequest (request)
.execute ();
final var request = getBooking (getSession ().getSharedData (BOOKING_ID));
final var response = withRequest (request).execute ();

response.verifyStatusCode ()
.isEqualTo (200);
Expand All @@ -128,9 +128,8 @@ public void testGetBooking () {
@Story ("Json Validation Exception tests")
@Test (description = "Tests for file not found exception", expectedExceptions = FrameworkError.class)
public void testJsonSchemaFileException () {
final var request = BookingRequest.createBooking (this.newBooking);
final var response = ApiActions.withRequest (request)
.execute ();
final var request = createBooking (this.newBooking);
final var response = withRequest (request).execute ();

response.verifyStatusCode ()
.isEqualTo (200);
Expand All @@ -145,8 +144,7 @@ public void testUpdateBooking () {
final var updateBookingData = this.newBooking;

final var request = BookingRequest.updateBooking (getSession ().getSharedData (BOOKING_ID), updateBookingData);
final var response = ApiActions.withRequest (request)
.execute ();
final var response = withRequest (request).execute ();
response.verifyStatusCode ()
.isEqualTo (200);
response.verifyTextField ("firstname")
Expand All @@ -162,8 +160,7 @@ public void testUpdatePartialBooking () {

final var request = BookingRequest.updatePartialBooking (getSession ().getSharedData (BOOKING_ID),
partialBookingData);
final var response = ApiActions.withRequest (request)
.execute ();
final var response = withRequest (request).execute ();
response.verifyStatusCode ()
.isEqualTo (200);
response.verifyTextField ("firstname")
Expand Down
Loading