From 1c68742bb7deac5b799e75568f616c5d69eb010e Mon Sep 17 00:00:00 2001 From: utkarsh Date: Mon, 2 Feb 2026 00:56:42 +0530 Subject: [PATCH 1/3] Fix issue with [issue/feature name] --- pom.xml | 34 +++++-- .../lambdatest/LambdaTestJBehaveRunner.java | 88 +++++++++++++------ src/test/resources/conf/single.conf.json | 2 +- 3 files changed, 89 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index 467642a..5ffd8f2 100644 --- a/pom.xml +++ b/pom.xml @@ -8,23 +8,28 @@ junit junit - 4.11 + 4.13.2 org.seleniumhq.selenium selenium-java - 3.13.0 + 4.11.0 org.jbehave jbehave-core - 3.8 + 4.8.3 com.googlecode.json-simple json-simple 1.1.1 + + com.thoughtworks.xstream + xstream + 1.4.20 + @@ -56,9 +61,12 @@ org.apache.maven.plugins maven-surefire-plugin - 2.5 + 2.22.2 - com/lambdatest/LambdaTestJBehaveRunner.java + --add-opens java.base/java.lang=ALL-UNNAMED + + **/LambdaTestJBehaveRunner.java + single.conf.json com.lambdatest.single.SingleEmbedder @@ -66,6 +74,22 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + **/LambdaTestJBehaveRunner.java + + + single.conf.json + com.lambdatest.single.SingleEmbedder + stories/single.story + + + + diff --git a/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java b/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java index dc681ce..1118fb6 100644 --- a/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java +++ b/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java @@ -14,6 +14,7 @@ import org.json.simple.JSONArray; import org.json.simple.parser.JSONParser; + import org.jbehave.core.embedder.Embedder; import org.junit.Test; import org.junit.After; @@ -37,70 +38,99 @@ public class LambdaTestJBehaveRunner { @Parameter(value = 0) public int taskID; - @Parameters public static Collection data() throws Exception { List taskIDs = new ArrayList(); - if (System.getProperty("config") != null) { + String configName = System.getProperty("config"); + + System.out.println("Attempting to load config: " + configName); + + if (configName != null) { JSONParser parser = new JSONParser(); - config = (JSONObject) parser.parse(new FileReader("src/test/resources/conf/" + System.getProperty("config"))); - int envs = ((JSONArray) config.get("environments")).size(); + // Use the ClassLoader to find the file in src/test/resources/conf/ + try (java.io.InputStream is = LambdaTestJBehaveRunner.class + .getClassLoader() + .getResourceAsStream("conf/" + configName)) { + + if (is == null) { + // This provides a much clearer error if the file is missing or renamed + throw new java.io.FileNotFoundException("Classpath error: Could not find 'conf/" + configName + "'. Check your src/test/resources/conf folder."); + } + + java.io.InputStreamReader reader = new java.io.InputStreamReader(is); + config = (JSONObject) parser.parse(reader); + } + + int envs = ((JSONArray) config.get("environments")).size(); for (int i = 0; i < envs; i++) { taskIDs.add(new Object[]{i}); } } - return taskIDs; } @Before + public void setUp() throws Exception { JSONArray envs = (JSONArray) config.get("environments"); - String username = System.getenv("LT_USERNAME") == null ? "YOUR_LT_USERNAME" : System.getenv("LT_USERNAME"); //Replace YOUR_LT_USERNAME with your LambdaTest username - - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Replace YOUR_LT_ACCESS_KEY with your LambdaTest accessKey - - String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-android" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android - + String username = System.getenv("LT_USERNAME") == null ? "YOUR_LT_USERNAME" : System.getenv("LT_USERNAME"); + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); + // Use ChromeOptions or UiAutomator2Options, but for generic RemoteWebDriver: DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("app", app_id); //Enter app_url here + // 1. Mandatory W3C standard capabilities + Map ltOptions = new java.util.HashMap<>(); + ltOptions.put("isRealMobile", true); + ltOptions.put("app", "lt://APP10160622431766424164986229"); + + // 2. Load Environment Specific Capabilities (deviceName, platformVersion, etc.) Map envCapabilities = (Map) envs.get(taskID); - Iterator it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry) it.next(); - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); + for (Map.Entry entry : envCapabilities.entrySet()) { + // PlatformName and PlatformVersion are W3C standards; others go to ltOptions + if (entry.getKey().equalsIgnoreCase("platformName")) { + capabilities.setCapability("platformName", entry.getValue()); + } else { + ltOptions.put(entry.getKey(), entry.getValue()); + } } - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry) it.next(); - if (capabilities.getCapability(pair.getKey().toString()) == null) { - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); - } + // 3. Load Common Capabilities (build, name, visual, etc.) + Map commonCapabilities = (Map) config.get("capabilities"); + for (Map.Entry entry : commonCapabilities.entrySet()) { + ltOptions.put(entry.getKey(), entry.getValue()); } - driver = new RemoteWebDriver(new URL("http://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), - capabilities); - } + // 4. Wrap everything in lt:options + capabilities.setCapability("lt:options", ltOptions); + driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), capabilities); + } @After public void tearDown() throws Exception { driver.quit(); } @Test + public void runStories() throws Exception { - Class c = Class.forName(System.getProperty("embedder")); + // Get properties from command line, or use defaults + String embedderClassName = System.getProperty("embedder", "com.lambdatest.single.SingleEmbedder"); + String storiesProperty = System.getProperty("stories"); + + if (storiesProperty == null || storiesProperty.isEmpty()) { + throw new RuntimeException("Error: You must specify stories to run via -Dstories=path/to.story"); + } + + // Initialize the Embedder via reflection + Class c = Class.forName(embedderClassName); Constructor cons = c.getConstructor(WebDriver.class); Embedder storyEmbedder = (Embedder) cons.newInstance(driver); - List storyPaths = Arrays.asList(System.getProperty("stories")); + // Run the stories + List storyPaths = Arrays.asList(storiesProperty.split(",")); storyEmbedder.runStoriesAsPaths(storyPaths); } } diff --git a/src/test/resources/conf/single.conf.json b/src/test/resources/conf/single.conf.json index 1aac897..8bb7eb9 100644 --- a/src/test/resources/conf/single.conf.json +++ b/src/test/resources/conf/single.conf.json @@ -11,7 +11,7 @@ { "platformName": "android", "deviceName": ".*", - "platformVersion": "12" + "platformVersion": "14" } ] } From 1cd2cdb6e04ed1a5f6d760ceabb58f95b4e8bd37 Mon Sep 17 00:00:00 2001 From: utkarshbh785 Date: Mon, 2 Feb 2026 00:56:30 +0530 Subject: [PATCH 2/3] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..22bface --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,33 @@ +trigger: + branches: + include: + - main + - master + - fix/appium-tests # Add any other branches you want to trigger the pipeline + +pool: + name: 'Default' + +# ============================== +# Variable Group +# ============================== +variables: + - group: LambdaTest-Credentials # Assuming you have a variable group for credentials + +# ============================== +# Steps +# ============================== +steps: + + # Checkout the repo to get the latest changes + - checkout: self + clean: true + + # Run Android tests with the 'android' profile + - script: | + echo Running Android Tests with Appium + mvn test -P single + displayName: 'Run Android Tests' + env: + LT_USERNAME: $(LT_USERNAME) # LambdaTest username (securely injected from variable group) + LT_ACCESS_KEY: $(LT_ACCESS_KEY) # LambdaTest access key (securely injected from variable group) From 9ad23ec665bdc7065c96b0b80e004d71a96823b8 Mon Sep 17 00:00:00 2001 From: utkarshbh785 Date: Wed, 15 Apr 2026 01:50:27 +0530 Subject: [PATCH 3/3] Update src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java Co-authored-by: Saurabh <86821971+Saurabh-LT@users.noreply.github.com> --- src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java b/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java index 1118fb6..2d2e730 100644 --- a/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java +++ b/src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java @@ -84,7 +84,7 @@ public void setUp() throws Exception { // 1. Mandatory W3C standard capabilities Map ltOptions = new java.util.HashMap<>(); ltOptions.put("isRealMobile", true); - ltOptions.put("app", "lt://APP10160622431766424164986229"); + ltOptions.put("app", ""); // 2. Load Environment Specific Capabilities (deviceName, platformVersion, etc.) Map envCapabilities = (Map) envs.get(taskID);