Skip to content

Commit 2ed41a2

Browse files
committed
feat : add sdk support for Java + Testng + Cucmber
1 parent eee8f17 commit 2ed41a2

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

src/tools/sdk-utils/constants.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,63 @@ browserstack-sdk python <path-to-test-file>
3333
\`\`\`
3434
`;
3535

36+
37+
const javaInstructions = `
38+
Add the following dependency to your pom.xml:
39+
\`\`\`xml
40+
<dependency>
41+
<groupId>com.browserstack</groupId>
42+
<artifactId>browserstack-java-sdk</artifactId>
43+
<version>LATEST</version>
44+
<scope>compile</scope>
45+
</dependency>
46+
\`\`\`
47+
48+
For Gradle projects, add to build.gradle:
49+
\`\`\`groovy
50+
dependencies {
51+
implementation 'com.browserstack:browserstack-java-sdk:LATEST'
52+
}
53+
\`\`\`
54+
55+
**Automated Step:**
56+
To migrate your project to use BrowserStack, automatically replace all local WebDriver instantiations (such as \`new ChromeDriver()\`, \`new FirefoxDriver()\`, etc.) with the following BrowserStack RemoteWebDriver code:
57+
58+
\`\`\`java
59+
import org.openqa.selenium.remote.RemoteWebDriver;
60+
import org.openqa.selenium.MutableCapabilities;
61+
import java.net.URL;
62+
63+
MutableCapabilities capabilities = new MutableCapabilities();
64+
// Add any desired capabilities here
65+
66+
capabilities.setCapability("browserstack.user", System.getenv("BROWSERSTACK_USERNAME"));
67+
capabilities.setCapability("browserstack.key", System.getenv("BROWSERSTACK_ACCESS_KEY"));
68+
69+
WebDriver driver = new RemoteWebDriver(
70+
new URL("https://hub-cloud.browserstack.com/wd/hub"),
71+
capabilities
72+
);
73+
\`\`\`
74+
75+
You can use MCP or a code automation tool to:
76+
- Search for all occurrences of \`new ChromeDriver()\`, \`new FirefoxDriver()\`, \`new EdgeDriver()\`, and \`new SafariDriver()\` in your codebase.
77+
- Replace them with the above BrowserStack RemoteWebDriver code.
78+
79+
Inform user to export BROWSERSTACK_USERNAME=${config.browserstackUsername} and
80+
BROWSERSTACK_ACCESS_KEY=${config.browserstackAccessKey} as environment variables.
81+
82+
Run tests using:
83+
\`\`\`bash
84+
mvn clean test
85+
\`\`\`
86+
87+
Or for Gradle:
88+
\`\`\`bash
89+
gradle clean test
90+
\`\`\`
91+
`;
92+
3693
export const SUPPORTED_CONFIGURATIONS: ConfigMapping = {
3794
nodejs: {
3895
playwright: {
@@ -59,4 +116,11 @@ export const SUPPORTED_CONFIGURATIONS: ConfigMapping = {
59116
behave: { instructions: pythonInstructions },
60117
},
61118
},
119+
java: {
120+
playwright: {},
121+
selenium: {
122+
testng: { instructions: javaInstructions },
123+
cucumber: { instructions: javaInstructions },
124+
},
125+
},
62126
};

src/tools/sdk-utils/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type SDKSupportedLanguage = "nodejs" | "python";
1+
export type SDKSupportedLanguage = "nodejs" | "python" | "java";
22
export type SDKSupportedBrowserAutomationFramework = "playwright" | "selenium";
33
export type SDKSupportedTestingFramework =
44
| "jest"
@@ -10,7 +10,8 @@ export type SDKSupportedTestingFramework =
1010
| "cucumber"
1111
| "nightwatch"
1212
| "webdriverio"
13-
| "mocha";
13+
| "mocha"
14+
| "testng";
1415

1516
export type ConfigMapping = Record<
1617
SDKSupportedLanguage,

0 commit comments

Comments
 (0)