diff --git a/docs/smartui-pdf-comparison.md b/docs/smartui-pdf-comparison.md index 459b639a..f7c9c5dc 100644 --- a/docs/smartui-pdf-comparison.md +++ b/docs/smartui-pdf-comparison.md @@ -200,18 +200,184 @@ smartui upload-pdf ./spec.pdf --fetch-results results.json This CLI method streamlines PDF uploads and result retrieval, making it ideal for CI/CD pipelines and automated workflows. -## Use Cases of Smart PDF Comparison +## Option 3: Uploading PDFs via SmartUI Java SDK + +For developers who prefer programmatic control, SmartUI provides a Java SDK to upload PDFs and manage visual regression testing programmatically. + +### Step 1: Clone the Sample Project + +First, clone the sample project to get started: + +```bash +git clone https://github.com/LambdaTest/junit-selenium-sample.git +cd junit-selenium-sample +``` + +### Step 2: Install the SmartUI Java SDK + +Add the SmartUI Java SDK to your `pom.xml`: + +```xml + + io.github.lambdatest + lambdatest-java-sdk + 1.0.18 + +``` + +Then compile your project: + +```bash +mvn clean compile +``` + +### Step 3: Set up your credentials + + + + + +
+ + {`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" +export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}" +export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`} + +
+ +
+ + + +
+ + {`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" +set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}" +set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`} + +
-1. **Software Documentation**: In software development, PDF comparison can be utilized to ensure the accuracy and consistency of user manuals, system documentation, and more. It can help in tracking changes made in the document across different software versions or updates. +
+ + + +
+ + {`$Env:LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" +$Env:LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}" +$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`} + +
+ +
+ +
+ +### Step 4: Upload PDFs using Java SDK + +You can upload PDFs in two modes: + + + + -2. **Legal and Compliance Checks**: In legal practices and compliance-heavy industries, comparing different versions of contracts, agreements, or regulatory documents is common. With PDF comparison, one can easily spot differences, alterations, or anomalies, ensuring every detail aligns with legal and compliance requirements. +Upload pre-existing PDFs from your local machine: -3. **Design Validation**: For graphic designers, artists, or anyone involved in the creation of visual content, PDF comparison can be used to validate design changes and ensure consistency across different versions of a design. +> 📁 **Sample File**: [`SmartuiPdfLocalTest.java`](https://github.com/LambdaTest/junit-selenium-sample/blob/master/src/test/java/com/smartuiPdf/SmartuiPdfLocalTest.java) -4. **Proofreading and Editing**: In the publishing industry or any other industry where documents are created and edited, the PDF comparison feature can be invaluable. It can help detect any changes made between different versions of a document, allowing editors and proofreaders to quickly find and correct mistakes. +```java +import io.github.lambdatest.SmartUIConfig; +import io.github.lambdatest.SmartUIPdf; +import io.github.lambdatest.models.FormattedResults; -5. **Quality Assurance**: In industries where accuracy is paramount, such as manufacturing or engineering, PDF comparison can be used for quality assurance. Comparing design specs, product blueprints, or operational guidelines can ensure consistency and adherence to quality standards. +public class SmartuiPdfLocalTest { + public void uploadLocalPdf() throws Exception { + String projectToken = System.getenv("PROJECT_TOKEN"); + + SmartUIConfig config = new SmartUIConfig() + .withProjectToken(projectToken) + .withFetchResult(true); -6. **Archiving and Record Keeping**: For businesses or organizations that need to maintain records over a long period, PDF comparison can help verify the accuracy and integrity of these archives. It can highlight any alterations or modifications made to a document over time. + SmartUIPdf pdfUploader = new SmartUIPdf(config); + + // Upload PDF file + String pdfPath = "path/to/your/document.pdf"; + FormattedResults result = pdfUploader.uploadPDF(pdfPath); + + System.out.println("Upload result: " + result); + } +} +``` + + + + + +Upload PDFs downloaded during LambdaTest cloud test execution: + +> 📁 **Sample File**: [`SmartuiPdfCloudTest.java`](https://github.com/LambdaTest/junit-selenium-sample/blob/master/src/test/java/com/smartuiPdf/SmartuiPdfCloudTest.java) + +```java +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.remote.RemoteWebDriver; +import java.io.File; +import java.io.FileOutputStream; +import java.util.Base64; + +public class SmartuiPdfCloudTest { + public void uploadCloudPdf(WebDriver driver) throws Exception { + String projectToken = System.getenv("PROJECT_TOKEN"); + + // Download PDF from cloud session + String base64Content = (String) ((JavascriptExecutor) driver) + .executeAsyncScript("lambda-file-content=LambdaTest.pdf"); + + // Convert base64 to PDF file + byte[] pdfBytes = Base64.getDecoder().decode(base64Content); + File pdfFile = new File("downloaded.pdf"); + try (FileOutputStream fos = new FileOutputStream(pdfFile)) { + fos.write(pdfBytes); + } + + // Upload to SmartUI + SmartUIConfig config = new SmartUIConfig() + .withProjectToken(projectToken) + .withFetchResult(true); + + SmartUIPdf pdfUploader = new SmartUIPdf(config); + FormattedResults result = pdfUploader.uploadPDF(pdfFile.getAbsolutePath()); + + System.out.println("Upload result: " + result); + } +} +``` + + + + + +### Step 5: Configuration Options + +| Method | Description | +|-------|-------------| +| `.withProjectToken(token)` | Required. Your SmartUI project token. | +| `.withFetchResult(true)` | Optional. Returns structured test results. | +| `.withBuildName("v2.1")` | Optional. Assign a custom build name. | + +### Step 6: Run your tests + +```bash +mvn test +``` + +The SDK method provides programmatic control over PDF uploads and is ideal for integration into existing Java-based test automation frameworks. + +## Use Cases of Smart PDF Comparison -In summary, PDF comparison is a versatile tool that can streamline workflows, improve accuracy, and enhance productivity in many different sectors and use cases. \ No newline at end of file +- **Software Documentation**: Track changes and ensure consistency across document versions. +- **Legal & Compliance**: Spot differences in contracts or regulatory documents. +- **Design Validation**: Verify design updates and maintain visual consistency. +- **Proofreading**: Detect edits between document versions for quick review. +- **Quality Assurance**: Compare specs or blueprints to uphold standards. +- **Archiving**: Confirm integrity of records over time by highlighting modifications.