Skip to content

Commit 3ac9126

Browse files
authored
Merge pull request LambdaTest#1165 from amanchopra1905/stage
running first test smart ui
2 parents a0162c1 + d2e94e1 commit 3ac9126

File tree

3 files changed

+258
-95
lines changed

3 files changed

+258
-95
lines changed
20.9 KB
Loading

docs/smartui-running-your-first-test.md

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ url: https://www.lambdatest.com/support/docs/smartui-running-your-first-test/
1919
site_name: LambdaTest
2020
slug: smartui-running-your-first-test/
2121
---
22+
23+
import Tabs from '@theme/Tabs';
24+
import TabItem from '@theme/TabItem';
25+
import CodeBlock from '@theme/CodeBlock';
26+
import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys";
27+
2228
<script type="application/ld+json"
2329
dangerouslySetInnerHTML={{ __html: JSON.stringify({
2430
"@context": "https://schema.org",
@@ -41,4 +47,174 @@ slug: smartui-running-your-first-test/
4147
}]
4248
})
4349
}}
44-
></script>
50+
></script>
51+
This guide will walk you through the process of running your first visual regression test using SmartUI, a powerful feature of LambdaTest that ensures your web applications look flawless across all browsers and devices.
52+
## Prerequisites
53+
54+
- Basic understanding of Command Line Interface and Selenium is required.
55+
- Login to [LambdaTest SmartUI](https://smartui.lambdatest.com/) with your credentials.
56+
57+
The following steps will guide you in running your first Visual Regression test on LambdaTest platform using SmartUI Selenium SDK integration.
58+
59+
## Step 1: Create a SmartUI Project
60+
The first step is to create a project with the application in which we will combine all your builds run on the project. To create a SmartUI Project, follow these steps:
61+
62+
- Go to [Projects page](https://smartui.lambdatest.com/) and click on the **New Project** button.
63+
- Select the platform as <b>CLI</b> for executing your **SDK** tests.
64+
- Add name of the project, approver's name, and tags for any filter or easy navigation.
65+
- Click on the **Continue** button.
66+
67+
Now select your desired framework and click on the **Configure** button. For the demo purpose we will select the Java framework.
68+
69+
## Step 2: Configure your Test Suite dependencies
70+
71+
You can use your own project to configure and test it. For demo purposes, we are using the sample repository.
72+
73+
:::tip Sample repo
74+
Download or Clone the code sample code repository from the LambdaTest GitHub repository to run the tests on the SmartUI.
75+
76+
<a href="https://github.com/LambdaTest/smartui-java-testng-sample" target="_blank" className="github__anchor"><img loading="lazy" src={require('../assets/images/icons/github.png').default} alt="Image" className="doc_img"/> View on GitHub</a>
77+
:::
78+
79+
- Add the following dependency in your `pom.xml` file
80+
81+
```xml title="pom.xml"
82+
<dependency>
83+
<groupId>io.github.lambdatest</groupId>
84+
<artifactId>lambdatest-java-sdk</artifactId>
85+
<version>1.0.2</version>
86+
</dependency>
87+
```
88+
89+
:::note
90+
You can check the latest version of [lambdatest-java-sdk]( https://mvnrepository.com/artifact/io.github.lambdatest/lambdatest-java-sdk) and update the latest version accordingly.
91+
:::
92+
93+
- Install your CLI and required modules for running SmartUI SDK and compile your defined dependencies in the `pom.xml` file:
94+
95+
```zsh
96+
npm i @lambdatest/smartui-cli
97+
mvn clean compile
98+
```
99+
100+
## Step 3: Setup your Project Token and Environment Variables
101+
102+
Setup your project token show in the **SmartUI** app after, creating your project.
103+
104+
<Tabs className="docs__val" groupId="language">
105+
106+
<TabItem value="MacOS/Linux" label="MacOS/Linux" default>
107+
<div className="lambdatest__codeblock">
108+
<CodeBlock className="language-bash">
109+
{`export LT_USERNAME="${YOUR_LAMBDATEST_USERNAME()}"
110+
export LT_ACCESS_KEY="${YOUR_LAMBDATEST_ACCESS_KEY()}"
111+
export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
112+
</CodeBlock>
113+
</div>
114+
</TabItem>
115+
116+
<TabItem value="Windows" label="Windows - CMD">
117+
<div className="lambdatest__codeblock">
118+
<CodeBlock className="language-bash">
119+
{`set LT_USERNAME="${YOUR_LAMBDATEST_USERNAME()}"
120+
set LT_ACCESS_KEY="${YOUR_LAMBDATEST_ACCESS_KEY()}"
121+
set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
122+
</CodeBlock>
123+
</div>
124+
</TabItem>
125+
126+
<TabItem value="Powershell" label="Windows-PS">
127+
<div className="lambdatest__codeblock">
128+
<CodeBlock className="language-bash">
129+
{`$Env:LT_USERNAME="${YOUR_LAMBDATEST_USERNAME()}"
130+
$Env:LT_ACCESS_KEY="${YOUR_LAMBDATEST_ACCESS_KEY()}"
131+
$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"`}
132+
</CodeBlock>
133+
</div>
134+
</TabItem>
135+
136+
</Tabs>
137+
138+
<img loading="lazy" src={require('../assets/images/smart-visual-testing/running-first-test/1.png').default} alt="cmd" width="768" height="373" className="doc_img"/>
139+
140+
## Step 4: Create and Configure SmartUI Config
141+
You can now configure your project configurations on using various available options to run your tests with the SmartUI integration. To generate the configuration file, please execute the following command:
142+
143+
```bash
144+
npx smartui config:create .smartui.json
145+
```
146+
Once, the configuration file will be created, you will be seeing the default configuration pre-filled in the configuration file:
147+
148+
```javascript title="/smartui-sdk-project/.smartui.json"
149+
{
150+
"web": {
151+
"browsers": [
152+
"chrome",
153+
"firefox",
154+
"safari",
155+
"edge"
156+
],
157+
"viewports": [
158+
[
159+
1920
160+
],
161+
[
162+
1366
163+
],
164+
[
165+
1028
166+
]
167+
] // Full Page screenshots are captured by default for web viewports
168+
},
169+
"mobile": {
170+
"devices": [
171+
"iPhone 14", //iPhone 14 viewport
172+
"Galaxy S24" //Galaxy S24 viewport
173+
],
174+
"fullPage": true, //Full Page is true by default for mobile viewports
175+
"orientation": "portrait" //Change to "landscape" for landscape snapshot
176+
},
177+
"waitForTimeout": 1000, //Optional (Should only be used in case lazy-loading/async components are present)
178+
"waitForPageRender": 50000, //Optional (Should only be used in case of websites which take more than 30s to load)
179+
"enableJavaScript": false, //Enable javascript for all the screenshots of the project
180+
"allowedHostnames": [] //Additional hostnames to capture assets from
181+
}
182+
```
183+
:::info Advanced options in SmartUI configuration
184+
- For capturing fullpage or viewport screenshots, please refer to this [documentation](/docs/smartui-sdk-config-options/#12-viewports)
185+
- For the list of available mobile viewports, please refer to this [documentation](/docs/smartui-sdk-config-options/#list-of-supported-device-viewports)
186+
- For more information about SmartUI config global options, please refer to this [documentation](/docs/smartui-sdk-config-options/#3-global-options-optional).
187+
:::
188+
189+
## Step 5: Adding SmartUI function to take screenshot
190+
You can incorporate SmartUI into your custom `Selenium` automation test (any platform) script by adding the `smartuiSnapshot` function in the required segment of selenium script of which we would like to take the screenshot, as shown below:
191+
192+
```java
193+
import io.github.lambdatest.*; //Importing the lambdatest-java SDK
194+
//Rest of your code here
195+
196+
@Test
197+
public void basicTest() throws Exception {
198+
String spanText;
199+
System.out.println("Loading URL");
200+
201+
driver.get("<Required URL>");
202+
// ... test code snippet
203+
// highlight-next-line
204+
SmartUISnapshot.smartuiSnapshot(driver, "<Screenshot Name>");
205+
}
206+
```
207+
208+
## Step 6: Execute the Tests on SmartUI Cloud
209+
Execute `visual regression tests` on SmartUI using the following commands
210+
211+
```bash
212+
npx smartui --config .smartui.json exec -- mvn test -D suite=sdk-cloud.xml
213+
```
214+
:::note
215+
You may use the `npx smartui --help` command in case you are facing issues during the execution of SmartUI commands in the CLI.
216+
:::
217+
218+
You can see the Smart UI dashboard to view the results. This will help you identify the Mismatches from the existing `Baseline` build and do the required visual testing.
219+
220+
<img loading="lazy" src={require('../assets/images/smart-visual-testing/smartui-sdk-results-primer.webp').default} alt="cmd" width="768" height="373" className="doc_img"/>

0 commit comments

Comments
 (0)