Skip to content

Commit d997363

Browse files
Merge pull request #2 from abhishek-lambda/dev
Add support for all capabilities of selenium 3 & 4
2 parents 4fdae01 + b63bbbb commit d997363

File tree

14 files changed

+874
-98
lines changed

14 files changed

+874
-98
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Pre-Prod Release
2+
3+
on:
4+
push:
5+
branches:
6+
- pre-prod
7+
8+
jobs:
9+
build-and-release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up JDK 8
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '8'
20+
distribution: 'temurin'
21+
cache: maven
22+
23+
- name: Build with Maven
24+
run: mvn clean package
25+
26+
- name: Upload main JAR artifact
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: lambdatest-java-selenium-sdk
30+
path: target/lambdatest-java-selenium-sdk-*.jar
31+
retention-days: 90
32+
if-no-files-found: error
33+
34+
- name: Upload agent JAR artifact
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: lambdatest-java-selenium-sdk-agent
38+
path: target/lambdatest-java-selenium-sdk-*-agent.jar
39+
retention-days: 90
40+
if-no-files-found: error
41+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ MAVEN_CENTRAL*
2424
*.tmp
2525
*.bak
2626
*~
27-
gradle.properties
27+
gradle.properties
28+
.gradle/
-25.5 KB
Binary file not shown.
-17 Bytes
Binary file not shown.

dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.lambdatest</groupId>
55
<artifactId>lambdatest-java-selenium-sdk</artifactId>
66
<name>LambdaTest Selenium SDK</name>
7-
<version>1.0.1</version>
7+
<version>1.0.2</version>
88
<description>A Java SDK for integrating Selenium tests with LambdaTest cloud platform</description>
99
<url>https://www.lambdatest.com</url>
1010
<licenses>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.lambdatest</groupId>
88
<artifactId>lambdatest-java-selenium-sdk</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.0.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>LambdaTest Selenium SDK</name>

src/main/java/com/lambdatest/selenium/agent/RemoteWebDriverAdvice.java

Lines changed: 200 additions & 38 deletions
Large diffs are not rendered by default.

src/main/java/com/lambdatest/selenium/lambdatest/LambdaTestConfig.java

Lines changed: 156 additions & 57 deletions
Large diffs are not rendered by default.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.lambdatest.selenium.lambdatest.capabilities;
2+
3+
import java.util.Map;
4+
5+
import org.openqa.selenium.remote.DesiredCapabilities;
6+
7+
/**
8+
* Handles browser-specific options (Chrome, Firefox, Edge, Safari, Opera, IE).
9+
* These need special handling because they have different keys for Selenium 3 and 4.
10+
*/
11+
public class BrowserOptionsCapabilities {
12+
13+
/**
14+
* Process browser-specific options from config.
15+
* Sets both Selenium 3 and Selenium 4 keys for compatibility.
16+
*/
17+
public static void processBrowserOptions(Map<String, Object> config, DesiredCapabilities capabilities) {
18+
// Chrome
19+
processBrowserOption(config, capabilities, "chromeOptions", "goog:chromeOptions");
20+
21+
// Firefox
22+
processBrowserOption(config, capabilities, "firefoxOptions", "moz:firefoxOptions");
23+
24+
// Edge
25+
processBrowserOption(config, capabilities, "edgeOptions", "ms:edgeOptions");
26+
27+
// Safari
28+
processBrowserOption(config, capabilities, "safariOptions", "safari:options");
29+
30+
// Opera (no W3C namespace, same for both)
31+
processBrowserOption(config, capabilities, "operaOptions", "operaOptions");
32+
33+
// Internet Explorer
34+
processBrowserOption(config, capabilities, "ieOptions", "se:ieOptions", "IEOptions");
35+
}
36+
37+
/**
38+
* Process a browser option with Selenium 3 and 4 compatibility.
39+
*/
40+
private static void processBrowserOption(Map<String, Object> config, DesiredCapabilities capabilities,
41+
String selenium3Key, String selenium4Key) {
42+
processBrowserOption(config, capabilities, selenium3Key, selenium4Key, selenium3Key);
43+
}
44+
45+
/**
46+
* Process a browser option with custom Selenium 3 key.
47+
*/
48+
private static void processBrowserOption(Map<String, Object> config, DesiredCapabilities capabilities,
49+
String selenium3Key, String selenium4Key, String selenium3TargetKey) {
50+
Object options = null;
51+
52+
// Check Selenium 3 key first
53+
if (config.containsKey(selenium3Key)) {
54+
options = config.get(selenium3Key);
55+
}
56+
// Then check Selenium 4 key
57+
else if (config.containsKey(selenium4Key)) {
58+
options = config.get(selenium4Key);
59+
}
60+
61+
if (options != null) {
62+
// Set both keys for compatibility
63+
capabilities.setCapability(selenium3TargetKey, options); // Selenium 3
64+
capabilities.setCapability(selenium4Key, options); // Selenium 4 W3C
65+
}
66+
}
67+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.lambdatest.selenium.lambdatest.capabilities;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
/**
7+
* Definition of a capability with its key, aliases, and target locations.
8+
* This makes it easy to add new capabilities without modifying the main processing logic.
9+
*/
10+
public class CapabilityDefinition {
11+
12+
private final String primaryKey;
13+
private final List<String> aliases;
14+
private final CapabilityTarget target;
15+
private final String targetKey; // Optional: different key in target (e.g., "project" -> "projectName" for Selenium 3)
16+
17+
/**
18+
* Where the capability should be set.
19+
*/
20+
public enum CapabilityTarget {
21+
/** Set directly on DesiredCapabilities (Selenium 3 style) */
22+
DESIRED_CAPABILITIES,
23+
/** Set in lt:options (Selenium 4/W3C style) */
24+
LT_OPTIONS,
25+
/** Set in both places (for backwards compatibility) */
26+
BOTH
27+
}
28+
29+
public CapabilityDefinition(String primaryKey, CapabilityTarget target) {
30+
this(primaryKey, target, null);
31+
}
32+
33+
public CapabilityDefinition(String primaryKey, CapabilityTarget target, String targetKey) {
34+
this(primaryKey, Arrays.asList(), target, targetKey);
35+
}
36+
37+
public CapabilityDefinition(String primaryKey, List<String> aliases, CapabilityTarget target) {
38+
this(primaryKey, aliases, target, null);
39+
}
40+
41+
public CapabilityDefinition(String primaryKey, List<String> aliases, CapabilityTarget target, String targetKey) {
42+
this.primaryKey = primaryKey;
43+
this.aliases = aliases;
44+
this.target = target;
45+
this.targetKey = targetKey;
46+
}
47+
48+
public String getPrimaryKey() {
49+
return primaryKey;
50+
}
51+
52+
public List<String> getAliases() {
53+
return aliases;
54+
}
55+
56+
public CapabilityTarget getTarget() {
57+
return target;
58+
}
59+
60+
public String getTargetKey() {
61+
return targetKey != null ? targetKey : primaryKey;
62+
}
63+
64+
/**
65+
* Check if this definition matches the given key (primary key or any alias).
66+
*/
67+
public boolean matches(String key) {
68+
return primaryKey.equals(key) || aliases.contains(key);
69+
}
70+
71+
/**
72+
* Get the value from config if it exists (checking primary key and aliases).
73+
*/
74+
public Object getValue(java.util.Map<String, Object> config) {
75+
if (config.containsKey(primaryKey)) {
76+
return config.get(primaryKey);
77+
}
78+
for (String alias : aliases) {
79+
if (config.containsKey(alias)) {
80+
return config.get(alias);
81+
}
82+
}
83+
return null;
84+
}
85+
}
86+

0 commit comments

Comments
 (0)