Skip to content

Commit

Permalink
Merge pull request #1 from Saurabh-LT/main
Browse files Browse the repository at this point in the history
Added Java PW Sample
  • Loading branch information
Saurabh-LT authored Jan 13, 2025
2 parents 41cb4df + a29e488 commit 51f2c1d
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Run SmartUI Tests With Java Playwright On LambdaTest.

Command to execute

npx smartui exec -- mvn test -D suite=sdk-playwright-java.xml
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@lambdatest/smartui-cli": "^4.0.17"
}
}
86 changes: 86 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>smartUI</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<suiteXmlFiles>
<!--suppress UnresolvedMavenProperty -->
<suiteXmlFile>${suite}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>

</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.27.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.9.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.49.0</version> <!-- Use latest stable version -->
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.lambdatest/lambdatest-java-playwright-sdk -->
<dependency>
<groupId>io.github.lambdatest</groupId>
<artifactId>lambdatest-java-playwright-sdk</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

</project>
44 changes: 44 additions & 0 deletions src/test/java/com/lambdatest/SmartUISDKPlaywright.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.lambdatest;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import io.github.lambdatest.SmartUISnapshot;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class SmartUISDKPlaywright {
private Playwright playwright;
private Browser browser;
private Page page;

// Setup Playwright and Browser
@BeforeMethod
public void setup() {
playwright = Playwright.create();
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions()
.setHeadless(false);
browser = playwright.chromium().launch(launchOptions);
page = browser.newPage();
System.out.println("Playwright Browser initiated");
}

@Test
public void basicTest() throws Exception {
page.navigate("https://www.lambdatest.com/visual-regression-testing");
SmartUISnapshot.smartuiSnapshot(page, "SmartUI");
}

@AfterMethod
public void tearDown() {
if (browser != null) {
browser.close();
}
if (playwright != null) {
playwright.close();
}
}

}

0 comments on commit 51f2c1d

Please sign in to comment.