Skip to content

Commit 651d2c7

Browse files
RushilK7Ishavyas9
authored andcommitted
pdf doc fix
1 parent 7a64aa6 commit 651d2c7

File tree

1 file changed

+155
-2
lines changed

1 file changed

+155
-2
lines changed

docs/smartui-pdf-comparison.md

Lines changed: 155 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,161 @@ 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+
## 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: Install the SmartUI Java SDK
208+
209+
Add the SmartUI Java SDK to your `pom.xml`:
210+
211+
```xml
212+
<dependency>
213+
<groupId>io.github.lambdatest</groupId>
214+
<artifactId>lambdatest-java-sdk</artifactId>
215+
<version>1.0.18</version>
216+
</dependency>
217+
```
218+
219+
### Step 2: Set up your credentials
220+
221+
<Tabs className="docs__val">
222+
223+
<TabItem value="terminal" label="Linux / MacOS" default>
224+
225+
<div className="lambdatest__codeblock">
226+
<CodeBlock className="language-bash">
227+
{`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
228+
export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"
229+
export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
230+
</CodeBlock>
231+
</div>
232+
233+
</TabItem>
234+
235+
<TabItem value="cmd" label="Windows-CMD" default>
236+
237+
<div className="lambdatest__codeblock">
238+
<CodeBlock className="language-powershell">
239+
{`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
240+
set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"
241+
set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
242+
</CodeBlock>
243+
</div>
244+
245+
</TabItem>
246+
247+
<TabItem value="powershell" label="Windows-PS" default>
248+
249+
<div className="lambdatest__codeblock">
250+
<CodeBlock className="language-powershell">
251+
{`$Env:LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
252+
$Env:LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"
253+
$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`
254+
255+
</CodeBlock>
256+
</div>
257+
258+
</TabItem>
259+
260+
</Tabs>
261+
262+
### Step 3: Upload PDFs using Java SDK
263+
264+
You can upload PDFs in two modes:
265+
266+
<Tabs className="docs__val">
267+
268+
<TabItem value="local" label="Local Mode" default>
269+
270+
Upload pre-existing PDFs from your local machine:
271+
272+
```java
273+
import io.github.lambdatest.SmartUIConfig;
274+
import io.github.lambdatest.SmartUIPdf;
275+
import io.github.lambdatest.models.FormattedResults;
276+
277+
public class SmartuiPdfLocalTest {
278+
public void uploadLocalPdf() throws Exception {
279+
String projectToken = System.getenv("PROJECT_TOKEN");
280+
281+
SmartUIConfig config = new SmartUIConfig()
282+
.withProjectToken(projectToken)
283+
.withFetchResult(true);
284+
285+
SmartUIPdf pdfUploader = new SmartUIPdf(config);
286+
287+
// Upload PDF file
288+
String pdfPath = "path/to/your/document.pdf";
289+
FormattedResults result = pdfUploader.uploadPDF(pdfPath);
290+
291+
System.out.println("Upload result: " + result);
292+
}
293+
}
294+
```
295+
296+
</TabItem>
297+
298+
<TabItem value="cloud" label="Cloud Mode">
299+
300+
Upload PDFs downloaded during LambdaTest cloud test execution:
301+
302+
```java
303+
import org.openqa.selenium.WebDriver;
304+
import org.openqa.selenium.JavascriptExecutor;
305+
import org.openqa.selenium.remote.RemoteWebDriver;
306+
import java.io.File;
307+
import java.io.FileOutputStream;
308+
import java.util.Base64;
309+
310+
public class SmartuiPdfCloudTest {
311+
public void uploadCloudPdf(WebDriver driver) throws Exception {
312+
String projectToken = System.getenv("PROJECT_TOKEN");
313+
314+
// Download PDF from cloud session
315+
String base64Content = (String) ((JavascriptExecutor) driver)
316+
.executeAsyncScript("lambda-file-content=LambdaTest.pdf");
317+
318+
// Convert base64 to PDF file
319+
byte[] pdfBytes = Base64.getDecoder().decode(base64Content);
320+
File pdfFile = new File("downloaded.pdf");
321+
try (FileOutputStream fos = new FileOutputStream(pdfFile)) {
322+
fos.write(pdfBytes);
323+
}
324+
325+
// Upload to SmartUI
326+
SmartUIConfig config = new SmartUIConfig()
327+
.withProjectToken(projectToken)
328+
.withFetchResult(true);
329+
330+
SmartUIPdf pdfUploader = new SmartUIPdf(config);
331+
FormattedResults result = pdfUploader.uploadPDF(pdfFile.getAbsolutePath());
332+
333+
System.out.println("Upload result: " + result);
334+
}
335+
}
336+
```
337+
338+
</TabItem>
339+
340+
</Tabs>
341+
342+
### Step 4: Configuration Options
343+
344+
| Method | Description |
345+
|-------|-------------|
346+
| `.withProjectToken(token)` | Required. Your SmartUI project token. |
347+
| `.withFetchResult(true)` | Optional. Returns structured test results. |
348+
| `.withBuildName("v2.1")` | Optional. Assign a custom build name. |
349+
350+
### Step 5: Run your tests
351+
352+
```bash
353+
mvn test
354+
```
355+
356+
The SDK method provides programmatic control over PDF uploads and is ideal for integration into existing Java-based test automation frameworks.
357+
203358
## Use Cases of Smart PDF Comparison
204359

205360
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.
@@ -213,5 +368,3 @@ This CLI method streamlines PDF uploads and result retrieval, making it ideal fo
213368
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.
214369

215370
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.
216-
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.

0 commit comments

Comments
 (0)