Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 29 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.13.0</version>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>3.8</version>
<version>4.8.3</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.20</version>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of this? in this

</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -56,16 +61,35 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<version>2.22.2</version>
<configuration>
<test>com/lambdatest/LambdaTestJBehaveRunner.java</test>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine> <!-- Add this line -->
<includes>
<include>**/LambdaTestJBehaveRunner.java</include>
</includes>
<systemPropertyVariables>
<config>single.conf.json</config>
<embedder>com.lambdatest.single.SingleEmbedder</embedder>
<stories>stories/single.story</stories>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/LambdaTestJBehaveRunner.java</include>
</includes>
<systemPropertyVariables>
<config>single.conf.json</config>
<embedder>com.lambdatest.single.SingleEmbedder</embedder>
<stories>stories/single.story</stories> <!-- Update path here -->
</systemPropertyVariables>

</configuration>
</plugin>
</plugins>
</build>
</profile>
Expand Down
88 changes: 59 additions & 29 deletions src/test/java/com/lambdatest/LambdaTestJBehaveRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,70 +38,99 @@ public class LambdaTestJBehaveRunner {

@Parameter(value = 0)
public int taskID;

@Parameters
public static Collection<Object[]> data() throws Exception {
List<Object[]> taskIDs = new ArrayList<Object[]>();
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<String, Object> ltOptions = new java.util.HashMap<>();
ltOptions.put("isRealMobile", true);
ltOptions.put("app", "<your_app_id>");

// 2. Load Environment Specific Capabilities (deviceName, platformVersion, etc.)
Map<String, String> envCapabilities = (Map<String, String>) 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<String, String> 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<String, String> commonCapabilities = (Map<String, String>) 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<String, Object> commonCapabilities = (Map<String, Object>) config.get("capabilities");
for (Map.Entry<String, Object> 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<String> storyPaths = Arrays.asList(System.getProperty("stories"));
// Run the stories
List<String> storyPaths = Arrays.asList(storiesProperty.split(","));
storyEmbedder.runStoriesAsPaths(storyPaths);
}
}
2 changes: 1 addition & 1 deletion src/test/resources/conf/single.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
"platformName": "android",
"deviceName": ".*",
"platformVersion": "12"
"platformVersion": "14"
}
]
}