- Notifications
You must be signed in to change notification settings - Fork0
License
abhishek-lambda/lambdatest-java-selenium-sdk
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A powerful Java SDK for seamlessly integrating Selenium tests with the LambdaTest cloud platform. This SDK provides automatic capability injection, test status management, and simplified configuration for running Selenium tests on LambdaTest's cloud infrastructure.
✨Automatic Capability Injection - No need to manually configure LambdaTest capabilities
🔧Java Agent Support - Bytecode instrumentation for seamless integration
📊Test Status Management - Automatically mark tests as passed/failed on LambdaTest
🎯Framework Support - Works with TestNG, JUnit 5, and plain Selenium tests
🌐Tunnel Management - Built-in support for LambdaTest Tunnel
⚙️YAML Configuration - Simple YAML-based configuration
🚀Zero Code Changes - Just add the agent, no changes to existing tests
Add the following dependency to yourpom.xml:
<dependency> <groupId>io.github.lambdatest</groupId> <artifactId>lambdatest-selenium-java-sdk</artifactId> <version>1.0.0</version></dependency>
Add the following to yourbuild.gradle:
dependencies { implementation'io.github.lambdatest:lambdatest-selenium-java-sdk:1.0.0'}
Add the following to yourbuild.gradle.kts:
dependencies { implementation("io.github.lambdatest:lambdatest-selenium-java-sdk:1.0.0")}Create alambdatest.yaml file in your project root:
# LambdaTest credentialsusername:YOUR_LAMBDATEST_USERNAMEaccessKey:YOUR_LAMBDATEST_ACCESS_KEY# Browser capabilitiescapabilities:browserName:chromebrowserVersion:latestplatformName:Windows 10# Test configurationtestName:My Selenium Testbuild:Build#1project:My Project
The easiest way to use this SDK is with the Java agent, which automatically instruments your Selenium tests:
Maven:
mvntest -DargLine="-javaagent:/path/to/lambdatest-selenium-java-sdk-1.0.0-agent.jar"
Gradle:
./gradlewtest -Djvmargs="-javaagent:/path/to/lambdatest-selenium-java-sdk-1.0.0-agent.jar"
IDE (IntelliJ IDEA / Eclipse):
Add VM option:-javaagent:/path/to/lambdatest-selenium-java-sdk-1.0.0-agent.jar
If you prefer not to use the agent, you can use the SDK programmatically:
importcom.lambdatest.selenium.LambdaTestRemoteTest;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.remote.RemoteWebDriver;importorg.testng.annotations.Test;publicclassMySeleniumTestextendsLambdaTestRemoteTest {@TestpublicvoidtestGoogle() {WebDriverdriver =getDriver();// Automatically configured for LambdaTestdriver.get("https://www.google.com");System.out.println("Title: " +driver.getTitle());// Test will be automatically marked as passed/failed }}
Createlambdatest.yaml in your project root:
# Authentication (Required)username:YOUR_USERNAMEaccessKey:YOUR_ACCESS_KEY# Or use environment variables:# username: ${LT_USERNAME}# accessKey: ${LT_ACCESS_KEY}# Capabilities (Optional - will be merged with test capabilities)capabilities:browserName:chromebrowserVersion:latestplatformName:Windows 10resolution:1920x1080# LambdaTest OptionsltOptions:build:Build#1project:My Projectnetwork:truevideo:trueconsole:truevisual:true# Tunnel Configuration (Optional)tunnel:enabled:truename:my-tunnel# Grid ConfigurationgridUrl:https://hub.lambdatest.com/wd/hub
You can also configure using environment variables:
LT_USERNAME- LambdaTest usernameLT_ACCESS_KEY- LambdaTest access keyLT_GRID_URL- Grid URL (default:https://hub.lambdatest.com/wd/hub)
This SDK supportsall Selenium 4 and LambdaTest advanced capabilities. SeeCAPABILITIES.md for comprehensive documentation.
Selenium 4 Capabilities:
browserName,browserVersion(alias:version),platformName(alias:platform,OS)driver_version(aliases:driverVersion,driver)selenium_version(aliases:seleniumVersion,seVersion)idleTimeout(alias:idle)
Test Organization:
build,project,name
Debugging Capabilities:
video(default: true) - Video recordingvisual(alias:debug) - Command-by-command screenshotsnetwork(alias:networkLogs) - Network packet captureconsole- JavaScript console logsverboseWebDriverLogging- Detailed Selenium logsnetwork.mask- Mask network traffic for security
Environment:
resolution- Screen resolution (e.g., "1920x1080")timezone- Custom timezone (e.g., "UTC+05:30")
Local Testing:
tunnel(alias:local) - Enable Lambda TunneltunnelName(alias:localName) - Tunnel identifier
Advanced Testing Capabilities:
autoHeal- Automatically recover from element locator failures (Learn more)smartWait- Automatically wait for elements to be ready (mutually exclusive with autoHeal) (Learn more)smartWaitRetryDelay- Delay between smartWait retries in millisecondsgeoLocation- Simulate user location (e.g., "US", "IN") (Learn more)lambdaMaskCommands- Mask sensitive data in logs (e.g., ["setValues", "setCookies", "getCookies"]) (Learn more)networkThrottling- Simulate network conditions (e.g., "Regular 3G", "Good 4G") (Learn more)customHeaders- Add custom HTTP headers to all requests (Learn more)customDnsMap- Custom DNS mapping for testing (Learn more)network.full.har- Capture full HAR logs with request/response bodies (Learn more)lambda:userFiles(alias:userFiles) - Pre-uploaded files for testing (Learn more)
# Authenticationusername:"your_username"accesskey:"your_accesskey"# Browser ConfigurationbrowserName:"Chrome"browserVersion:"latest"# or "latest-1", "101.0", etc.platformName:"Windows 10"# Test Organizationbuild:"Selenium 4 Build"project:"My Project"name:"Sample Test"# Debugging (increases test time)video:truevisual:falsenetwork:falseconsole:falseverboseWebDriverLogging:false# Environmentresolution:"1920x1080"timezone:"UTC+05:30"# PerformanceidleTimeout:600selenium_version:"4.15.0"# Local Testingtunnel:falsetunnelName:"my-tunnel"# Advanced Testing CapabilitiesautoHeal:false# Note: Cannot be used with smartWaitsmartWait:false# Note: Cannot be used with autoHealsmartWaitRetryDelay:1000# millisecondsgeoLocation:"US"# Country code for geolocation testingnetworkThrottling:"Regular 3G"# Simulate network conditionsnetwork.full.har:true# Capture full HAR logs# Security & PrivacylambdaMaskCommands:# Mask sensitive data in logs -setValues -setCookies -getCookies# Custom ConfigurationcustomHeaders:# Add custom HTTP headersX-Custom-Header:"value"Authorization:"Bearer token"customDnsMap:# Custom DNS mappingexample.com:"192.168.1.1"test.local:"127.0.0.1"# File Upload (files must be pre-uploaded via LambdaTest API)lambda:userFiles: -"sample.pdf" -"test-image.jpg"
Auto Healing - Automatically recover from element locator failures:
autoHeal:true
This feature helps tests automatically adapt when element locators change. Note: Cannot be used together withsmartWait.
Smart Wait - Automatically wait for elements:
smartWait:truesmartWaitRetryDelay:500# Retry every 500ms
Automatically waits for elements to be ready. Note: Cannot be used together withautoHeal.
Geolocation Testing:
geoLocation:"IN"# Simulate location from Indiatimezone:"Asia/Kolkata"
Network Throttling - Simulate different network conditions:
networkThrottling:"Regular 4G"# Options: "Regular 2G", "Good 2G", "Regular 3G", "Good 3G", "Regular 4G", "LTE", "DSL", "Wifi"
Masking Sensitive Data in Logs:
lambdaMaskCommands: -setValues# Hide sendKeys input -setCookies# Hide cookies being set -getCookies# Hide cookies being retrieved
Custom Headers for API Testing:
customHeaders:X-API-Key:"your-api-key"Authorization:"Bearer token"Custom-Header:"custom-value"
Custom DNS Mapping:
customDnsMap:internal.example.com:"192.168.1.100"staging.myapp.com:"10.0.0.50"
Full HAR Logs with Request/Response Bodies:
network:truenetwork.full.har:true
For detailed documentation with examples, seeCAPABILITIES.md.
Reference Documentation:
Add TestNG listener for automatic test status updates:
<!-- testng.xml--><suitename="LambdaTest Suite"> <listeners> <listenerclass-name="com.lambdatest.selenium.LambdaTestStatusListener"/> </listeners> <testname="My Tests"> <classes> <classname="com.example.MyTest"/> </classes> </test></suite>
Or programmatically:
@Listeners(LambdaTestStatusListener.class)publicclassMyTest {// Your tests}
Use the JUnit transformer with the Java agent (automatically detected).
Enable LambdaTest Tunnel for testing local/private applications:
tunnel:enabled:truename:my-tunnel# Additional tunnel optionstunnelName:custom-tunnelverbose:true
Merge custom capabilities with configured ones:
importcom.lambdatest.selenium.LambdaTestCapabilities;importorg.openqa.selenium.chrome.ChromeOptions;ChromeOptionsoptions =newChromeOptions();options.addArguments("--start-maximized");// SDK will merge these with lambdatest.yaml capabilitiesLambdaTestCapabilities.enhance(options);
The SDK fully supports parallel test execution:
TestNG:
<suitename="Parallel Suite"parallel="tests"thread-count="5"> <testname="Chrome Test"> <parametername="browser"value="chrome"/> <classes><classname="com.example.Test1"/></classes> </test> <testname="Firefox Test"> <parametername="browser"value="firefox"/> <classes><classname="com.example.Test1"/></classes> </test></suite>
- Java 8 or higher
- Gradle 7.0+
# Clone the repositorygit clone https://github.com/LambdatestIncPrivate/lambdatest-selenium-java-sdk.gitcd lambdatest-selenium-java-sdk# Build the project./gradlew clean build# Generated artifacts will be in build/libs/# - lambdatest-selenium-java-sdk-1.0.0.jar (main JAR)# - lambdatest-selenium-java-sdk-1.0.0-agent.jar (agent JAR with dependencies)
For maintainers publishing to Maven Central:
# See MAVEN_CENTRAL_PUBLISHING.md for detailed instructions./verify-setup.sh# Verify publishing prerequisites./gradlew publishToMavenLocal# Test local publishing./gradlew publishMavenJavaPublicationToOSSRHRepository# Publish to Maven Central
importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.remote.RemoteWebDriver;importorg.testng.annotations.AfterMethod;importorg.testng.annotations.BeforeMethod;importorg.testng.annotations.Test;importjava.net.URL;publicclassBasicTest {WebDriverdriver;@BeforeMethodpublicvoidsetup()throwsException {ChromeOptionsoptions =newChromeOptions();options.setCapability("platformName","Windows 10");options.setCapability("browserVersion","latest");// SDK will automatically inject LambdaTest capabilitiesdriver =newRemoteWebDriver(newURL("https://hub.lambdatest.com/wd/hub"),options ); }@TestpublicvoidtestExample() {driver.get("https://www.example.com");Stringtitle =driver.getTitle();System.out.println("Page title: " +title);asserttitle.contains("Example"); }@AfterMethodpublicvoidteardown() {if (driver !=null) {driver.quit(); } }}
importorg.testng.annotations.*;publicclassCrossBrowserTest {@Parameters({"browser","version","platform"})@BeforeMethodpublicvoidsetup(Stringbrowser,Stringversion,Stringplatform) {// SDK automatically configures based on parameters }@TestpublicvoidtestAcrossBrowsers() {// Your test code }}
Issue: Driver not connecting to LambdaTest
- Verify credentials in
lambdatest.yamlor environment variables - Check your LambdaTest account has active minutes
- Ensure grid URL is correct
Issue: Java agent not working
- Verify agent JAR path is correct
- Use the
-agentclassifier JAR (with all dependencies) - Check Java version compatibility (Java 8+)
Issue: Tests not marked as passed/failed
- Ensure TestNG listener is configured
- Verify driver session ID is available
- Check network connectivity to LambdaTest
Add to your test:
System.setProperty("lambdatest.debug","true");
- Java: 8 or higher
- Selenium: 4.x (tested with 4.15.0)
- TestNG: 7.4.0+ (optional, for TestNG integration)
- JUnit: 5.10.0+ (optional, for JUnit integration)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see theLICENSE file for details.
- 📧 Email:support@lambdatest.com
- 📚 Documentation:https://www.lambdatest.com/support/docs/
- 💬 Community:https://community.lambdatest.com/
- 🐛 Issues:GitHub Issues
Made with ❤️ byLambdaTest
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Java100.0%