From 0740c84f6feffbb7ba456178351e42ce13bd7396 Mon Sep 17 00:00:00 2001 From: Ganesh Naik Date: Wed, 6 Dec 2023 13:30:24 +0530 Subject: [PATCH] feat: Archtype changes for Selenium/Appium upgrade --- build.gradle | 8 ++-- gradle.properties | 2 +- .../resources/archetype-resources/pom.xml | 6 +-- .../java/android/test/TestAndroidAction.java | 14 ++++--- .../src/main/java/ios/test/TestIOSAction.java | 38 +++++++++++-------- .../src/main/java/web/test/TestWebAction.java | 9 +++-- 6 files changed, 43 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index 52c11ff..5af7bb7 100644 --- a/build.gradle +++ b/build.gradle @@ -28,18 +28,18 @@ repositories { dependencies { implementation 'org.projectlombok:lombok:1.18.20' - implementation 'org.seleniumhq.selenium:selenium-api:3.141.59' - implementation 'io.appium:java-client:7.0.0' + implementation 'org.seleniumhq.selenium:selenium-api:4.14.1' + implementation 'io.appium:java-client:9.0.0' implementation 'org.apache.commons:commons-lang3:3.12.0' implementation 'org.apache.maven.plugins:maven-toolchains-plugin:3.0.0' implementation 'org.testng:testng:7.4.0' - implementation 'org.seleniumhq.selenium:selenium-java:3.141.59' + implementation 'org.seleniumhq.selenium:selenium-java:4.14.1' implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.0' annotationProcessor 'org.projectlombok:lombok:1.18.20' } group = 'com.testsigma' -version = '1.2.3_cloud' +version = '1.2.4_cloud' description = 'testsigma-addon-archetype' java.sourceCompatibility = JavaVersion.VERSION_11 diff --git a/gradle.properties b/gradle.properties index 1720089..a55480d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ RELEASE_SIGNING_ENABLED=true GROUP=com.testsigma POM_ARTIFACT_ID=testsigma-addon-archetype -VERSION_NAME=1.2.3_cloud +VERSION_NAME=1.2.4_cloud POM_NAME=Testsigma Addon Archetype POM_DESCRIPTION=Testsigma Addon Archetype diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index e8a8489..8fdfdea 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -13,7 +13,7 @@ UTF-8 11 11 - 1.2.3_cloud + 1.2.4_cloud 5.8.0-M1 1.0.0 3.2.1 @@ -48,13 +48,13 @@ org.seleniumhq.selenium selenium-java - 3.141.59 + 4.14.1 io.appium java-client - 7.0.0 + 9.0.0 com.fasterxml.jackson.core diff --git a/src/main/resources/archetype-resources/src/main/java/android/test/TestAndroidAction.java b/src/main/resources/archetype-resources/src/main/java/android/test/TestAndroidAction.java index 1b02244..1478cd3 100644 --- a/src/main/resources/archetype-resources/src/main/java/android/test/TestAndroidAction.java +++ b/src/main/resources/archetype-resources/src/main/java/android/test/TestAndroidAction.java @@ -1,17 +1,19 @@ package ${package}.android.test; +import ${package}.android.SwipeOnScreen; + +import com.google.common.collect.ImmutableMap; import com.testsigma.sdk.TestData; import com.testsigma.sdk.runners.ActionRunner; import io.appium.java_client.android.AndroidDriver; -import ${package}.android.SwipeOnScreen; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.net.URL; -import java.util.concurrent.TimeUnit; +import java.time.Duration;; public class TestAndroidAction { private ActionRunner runner; @@ -19,16 +21,16 @@ public class TestAndroidAction { @BeforeClass public void setup() throws Exception { - //Make sure to start Appium server + // Make sure to start Appium server DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("app", ""); caps.setCapability("deviceName", ""); caps.setCapability("udid", ""); caps.setCapability("platformName", "android"); - driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), caps); - driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); - driver.launchApp(); + driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), caps); + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); + driver.executeScript("mobile: activateApp", ImmutableMap.of("appId", driver.getCapabilities().getCapability("appium:appPackage"))); runner = new ActionRunner(driver); //Initialie Action runner } diff --git a/src/main/resources/archetype-resources/src/main/java/ios/test/TestIOSAction.java b/src/main/resources/archetype-resources/src/main/java/ios/test/TestIOSAction.java index 0824de3..11f350c 100644 --- a/src/main/resources/archetype-resources/src/main/java/ios/test/TestIOSAction.java +++ b/src/main/resources/archetype-resources/src/main/java/ios/test/TestIOSAction.java @@ -1,21 +1,23 @@ package ${package}.ios.test; -import com.testsigma.sdk.TestData; +import com.google.common.collect.ImmutableMap; +import ${package}.ios.EnterDataIfVisible; + import com.testsigma.sdk.Element; +import com.testsigma.sdk.TestData; import com.testsigma.sdk.runners.ActionRunner; import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.remote.MobileCapabilityType; -import ${package}.ios.EnterDataIfVisible; import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.net.URL; -import java.util.concurrent.TimeUnit; +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; public class TestIOSAction { @@ -24,20 +26,24 @@ public class TestIOSAction { @BeforeClass public void setup() throws Exception { - //Make sure to start Appium server - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "14"); - capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS"); - capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 11 Max"); + // Make sure to start Appium server + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("platformName", "iOS"); - capabilities.setCapability("app", ""); + Map appiumOptions = new HashMap<>(); + appiumOptions.put("platformVersion", "14"); + appiumOptions.put("automationName", "XCUITest"); + appiumOptions.put("deviceName", "iPhone 11 Max"); + appiumOptions.put("app", ""); + capabilities.setCapability("appium:options", appiumOptions); - IOSDriver driver = new IOSDriver<>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); - driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); - driver.launchApp(); - runner = new ActionRunner(driver); //Initialie Action runner + IOSDriver driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(60)); + driver.executeScript("mobile: activateApp", ImmutableMap.of("bundleId", + driver.getCapabilities().getCapability("appium:bundleId"))); + runner = new ActionRunner(driver); //Initialie Action runner } @Test diff --git a/src/main/resources/archetype-resources/src/main/java/web/test/TestWebAction.java b/src/main/resources/archetype-resources/src/main/java/web/test/TestWebAction.java index 2e439f5..2fc897f 100644 --- a/src/main/resources/archetype-resources/src/main/java/web/test/TestWebAction.java +++ b/src/main/resources/archetype-resources/src/main/java/web/test/TestWebAction.java @@ -1,16 +1,17 @@ package ${package}.web.test; -import com.testsigma.sdk.TestData; +import ${package}.web.MyFirstWebAction; + import com.testsigma.sdk.Element; +import com.testsigma.sdk.TestData; import com.testsigma.sdk.runners.ActionRunner; -import ${package}.web.MyFirstWebAction; import org.openqa.selenium.By; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.util.concurrent.TimeUnit; +import java.time.Duration; public class TestWebAction { private ActionRunner runner; @@ -21,7 +22,7 @@ public void setup() throws Exception { System.setProperty("webdriver.chrome.driver", ""); driver = new ChromeDriver(); driver.manage().deleteAllCookies(); - driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20)); runner = new ActionRunner(driver); //Initialie Action runner driver.get("https://www.orangehrm.com/orangehrm-30-day-trial/"); }