Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Java PW Sample #1

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}

}