Skip to content

Commit ce4bf85

Browse files
authored
Merge pull request #2159 from RushilK7/stage
smartui <> pdf doc fix
2 parents 2e9b9ef + 66eb381 commit ce4bf85

File tree

1 file changed

+174
-8
lines changed

1 file changed

+174
-8
lines changed

docs/smartui-pdf-comparison.md

Lines changed: 174 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,184 @@ smartui upload-pdf ./spec.pdf --fetch-results results.json
200200

201201
This CLI method streamlines PDF uploads and result retrieval, making it ideal for CI/CD pipelines and automated workflows.
202202

203-
## Use Cases of Smart PDF Comparison
203+
## Option 3: Uploading PDFs via SmartUI Java SDK
204+
205+
For developers who prefer programmatic control, SmartUI provides a Java SDK to upload PDFs and manage visual regression testing programmatically.
206+
207+
### Step 1: Clone the Sample Project
208+
209+
First, clone the sample project to get started:
210+
211+
```bash
212+
git clone https://github.com/LambdaTest/junit-selenium-sample.git
213+
cd junit-selenium-sample
214+
```
215+
216+
### Step 2: Install the SmartUI Java SDK
217+
218+
Add the SmartUI Java SDK to your `pom.xml`:
219+
220+
```xml
221+
<dependency>
222+
<groupId>io.github.lambdatest</groupId>
223+
<artifactId>lambdatest-java-sdk</artifactId>
224+
<version>1.0.18</version>
225+
</dependency>
226+
```
227+
228+
Then compile your project:
229+
230+
```bash
231+
mvn clean compile
232+
```
233+
234+
### Step 3: Set up your credentials
235+
236+
<Tabs className="docs__val">
237+
238+
<TabItem value="terminal" label="Linux / MacOS" default>
239+
240+
<div className="lambdatest__codeblock">
241+
<CodeBlock className="language-bash">
242+
{`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
243+
export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"
244+
export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
245+
</CodeBlock>
246+
</div>
247+
248+
</TabItem>
249+
250+
<TabItem value="cmd" label="Windows-CMD" default>
251+
252+
<div className="lambdatest__codeblock">
253+
<CodeBlock className="language-powershell">
254+
{`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
255+
set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"
256+
set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
257+
</CodeBlock>
258+
</div>
204259

205-
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.
260+
</TabItem>
261+
262+
<TabItem value="powershell" label="Windows-PS" default>
263+
264+
<div className="lambdatest__codeblock">
265+
<CodeBlock className="language-powershell">
266+
{`$Env:LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
267+
$Env:LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"
268+
$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
269+
</CodeBlock>
270+
</div>
271+
272+
</TabItem>
273+
274+
</Tabs>
275+
276+
### Step 4: Upload PDFs using Java SDK
277+
278+
You can upload PDFs in two modes:
279+
280+
<Tabs className="docs__val">
281+
282+
<TabItem value="local" label="Local Mode" default>
206283

207-
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.
284+
Upload pre-existing PDFs from your local machine:
208285

209-
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.
286+
> 📁 **Sample File**: [`SmartuiPdfLocalTest.java`](https://github.com/LambdaTest/junit-selenium-sample/blob/master/src/test/java/com/smartuiPdf/SmartuiPdfLocalTest.java)
210287
211-
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.
288+
```java
289+
import io.github.lambdatest.SmartUIConfig;
290+
import io.github.lambdatest.SmartUIPdf;
291+
import io.github.lambdatest.models.FormattedResults;
212292

213-
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.
293+
public class SmartuiPdfLocalTest {
294+
public void uploadLocalPdf() throws Exception {
295+
String projectToken = System.getenv("PROJECT_TOKEN");
296+
297+
SmartUIConfig config = new SmartUIConfig()
298+
.withProjectToken(projectToken)
299+
.withFetchResult(true);
214300

215-
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.
301+
SmartUIPdf pdfUploader = new SmartUIPdf(config);
302+
303+
// Upload PDF file
304+
String pdfPath = "path/to/your/document.pdf";
305+
FormattedResults result = pdfUploader.uploadPDF(pdfPath);
306+
307+
System.out.println("Upload result: " + result);
308+
}
309+
}
310+
```
311+
312+
</TabItem>
313+
314+
<TabItem value="cloud" label="Cloud Mode">
315+
316+
Upload PDFs downloaded during LambdaTest cloud test execution:
317+
318+
> 📁 **Sample File**: [`SmartuiPdfCloudTest.java`](https://github.com/LambdaTest/junit-selenium-sample/blob/master/src/test/java/com/smartuiPdf/SmartuiPdfCloudTest.java)
319+
320+
```java
321+
import org.openqa.selenium.WebDriver;
322+
import org.openqa.selenium.JavascriptExecutor;
323+
import org.openqa.selenium.remote.RemoteWebDriver;
324+
import java.io.File;
325+
import java.io.FileOutputStream;
326+
import java.util.Base64;
327+
328+
public class SmartuiPdfCloudTest {
329+
public void uploadCloudPdf(WebDriver driver) throws Exception {
330+
String projectToken = System.getenv("PROJECT_TOKEN");
331+
332+
// Download PDF from cloud session
333+
String base64Content = (String) ((JavascriptExecutor) driver)
334+
.executeAsyncScript("lambda-file-content=LambdaTest.pdf");
335+
336+
// Convert base64 to PDF file
337+
byte[] pdfBytes = Base64.getDecoder().decode(base64Content);
338+
File pdfFile = new File("downloaded.pdf");
339+
try (FileOutputStream fos = new FileOutputStream(pdfFile)) {
340+
fos.write(pdfBytes);
341+
}
342+
343+
// Upload to SmartUI
344+
SmartUIConfig config = new SmartUIConfig()
345+
.withProjectToken(projectToken)
346+
.withFetchResult(true);
347+
348+
SmartUIPdf pdfUploader = new SmartUIPdf(config);
349+
FormattedResults result = pdfUploader.uploadPDF(pdfFile.getAbsolutePath());
350+
351+
System.out.println("Upload result: " + result);
352+
}
353+
}
354+
```
355+
356+
</TabItem>
357+
358+
</Tabs>
359+
360+
### Step 5: Configuration Options
361+
362+
| Method | Description |
363+
|-------|-------------|
364+
| `.withProjectToken(token)` | Required. Your SmartUI project token. |
365+
| `.withFetchResult(true)` | Optional. Returns structured test results. |
366+
| `.withBuildName("v2.1")` | Optional. Assign a custom build name. |
367+
368+
### Step 6: Run your tests
369+
370+
```bash
371+
mvn test
372+
```
373+
374+
The SDK method provides programmatic control over PDF uploads and is ideal for integration into existing Java-based test automation frameworks.
375+
376+
## Use Cases of Smart PDF Comparison
216377

217-
In summary, PDF comparison is a versatile tool that can streamline workflows, improve accuracy, and enhance productivity in many different sectors and use cases.
378+
- **Software Documentation**: Track changes and ensure consistency across document versions.
379+
- **Legal & Compliance**: Spot differences in contracts or regulatory documents.
380+
- **Design Validation**: Verify design updates and maintain visual consistency.
381+
- **Proofreading**: Detect edits between document versions for quick review.
382+
- **Quality Assurance**: Compare specs or blueprints to uphold standards.
383+
- **Archiving**: Confirm integrity of records over time by highlighting modifications.

0 commit comments

Comments
 (0)