Welcome to the SmartUI SDK sample for Playwright Java. This repository demonstrates how to integrate SmartUI visual regression testing with Playwright Java.
smartui-java-playwright-sample/
├── src/
│ └── test/
│ └── java/
│ └── com/
│ └── lambdatest/
│ ├── SmartUISDKPlaywrightCloud.java # Cloud test
│ └── SmartUISDKPlaywrightLocal.java # Local test
├── sdk-playwright-cloud-java.xml # TestNG suite for Cloud
├── sdk-playwright-local-java.xml # TestNG suite for Local
├── pom.xml # Maven dependencies
└── smartui-web.json # SmartUI config (create with npx smartui config:create)
- Java 10 or higher
- Maven 3.6 or higher
- Node.js (for SmartUI CLI)
- LambdaTest account credentials (for Cloud tests)
- Chrome browser (for Local tests)
For Cloud:
export LT_USERNAME='your_username'
export LT_ACCESS_KEY='your_access_key'
export PROJECT_TOKEN='your_project_token'For Local:
export PROJECT_TOKEN='your_project_token'git clone https://github.com/LambdaTest/smartui-java-playwright-sample
cd smartui-java-playwright-sampleThe repository already includes the required dependencies in pom.xml. Build the project to download dependencies:
mvn clean compileDependencies included:
com.microsoft.playwright:playwright- Playwright Java libraryio.github.lambdatest:lambdatest-java-playwright-sdk- SmartUI SDK for Playwright Javaorg.testng:testng- TestNG testing framework
npx smartui config:create smartui-web.jsonThe SmartUI screenshot function is already implemented in the repository.
Cloud Test (src/test/java/com/lambdatest/SmartUISDKPlaywrightCloud.java):
page.navigate("https://www.lambdatest.com");
SmartUISnapshot.smartuiSnapshot(page, "screenshot");Local Test (src/test/java/com/lambdatest/SmartUISDKPlaywrightLocal.java):
page.navigate("https://www.lambdatest.com");
SmartUISnapshot.smartuiSnapshot(page, "screenshot");Note: The code is already configured and ready to use. You can modify the URL and screenshot name if needed.
npx smartui exec -- mvn test -D suite=sdk-playwright-local-java.xmlnpx smartui exec -- mvn test -D suite=sdk-playwright-cloud-java.xml- Connects to LambdaTest Cloud using CDP (Chrome DevTools Protocol)
- Reads credentials from environment variables (
LT_USERNAME,LT_ACCESS_KEY) - Takes screenshot with name:
screenshot
- Runs Playwright locally using Chromium
- Requires Chrome browser installed
- Takes screenshot with name:
screenshot
After running the tests, visit your SmartUI project dashboard to view the captured screenshots and compare them with baseline builds.
For detailed onboarding instructions, see the SmartUI Playwright Java Onboarding Guide.