Skip to content

Commit 2bb8eb8

Browse files
extension testing selenium junit java
0 parents  commit 2bb8eb8

9 files changed

+637
-0
lines changed

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Compiled class file
2+
*.class
3+
settings.json
4+
5+
# Log file
6+
*.log
7+
8+
# BlueJ files
9+
*.ctxt
10+
11+
# Mobile Tools for Java (J2ME)
12+
.mtj.tmp/
13+
14+
# Package Files #
15+
*.jar
16+
*.war
17+
*.nar
18+
*.ear
19+
*.zip
20+
*.tar.gz
21+
*.rar
22+
23+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24+
hs_err_pid*
25+
target/
26+
.idea/

.gitpod.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tasks:
2+
- init: mvn test

LambdatestScreenshotExtension.crx

608 KB
Binary file not shown.

README.md

+258
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
# Run Selenium Tests With JUnit On LambdaTest (Extension Upload Testing Example)
2+
3+
![image](https://user-images.githubusercontent.com/70570645/171432631-dcc31b10-6590-4877-98c0-4ac702fbd441.png)
4+
5+
<p align="center">
6+
<a href="https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample" target="_bank">Blog</a>
7+
&nbsp; &#8901; &nbsp;
8+
<a href="https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample" target="_bank">Docs</a>
9+
&nbsp; &#8901; &nbsp;
10+
<a href="https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample" target="_bank">Learning Hub</a>
11+
&nbsp; &#8901; &nbsp;
12+
<a href="https://www.lambdatest.com/newsletter/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample" target="_bank">Newsletter</a>
13+
&nbsp; &#8901; &nbsp;
14+
<a href="https://www.lambdatest.com/certifications/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample" target="_bank">Certifications</a>
15+
&nbsp; &#8901; &nbsp;
16+
<a href="https://www.youtube.com/c/LambdaTest" target="_bank">YouTube</a>
17+
</p>
18+
&emsp;
19+
&emsp;
20+
&emsp;
21+
22+
*Learn how to use JUnit framework to configure and run your Java automation testing scripts on the LambdaTest platform*
23+
24+
[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register)
25+
26+
27+
## Table Of Contents
28+
29+
* [Pre-requisites](#pre-requisites)
30+
* [Run Your First Test](#run-your-first-test)
31+
* [Parallel Testing With JUnit](#run-parallel-tests-using-junit)
32+
* [Local Testing With JUnit](#testing-locally-hosted-or-privately-hosted-projects)
33+
34+
## Pre-requisites
35+
36+
Before you can start performing Java automation testing with Selenium, you would need to:
37+
38+
- Install the latest **Java development environment** i.e. **JDK 1.6** or higher. We recommend using the latest version.
39+
40+
- Download the latest **Selenium Client** and its **WebDriver bindings** from the [official website](https://www.selenium.dev/downloads/). Latest versions of Selenium Client and WebDriver are ideal for running your automation script on LambdaTest Selenium cloud grid.
41+
42+
- Install **Maven** which supports **JUnit** framework out of the box. **Maven** can be downloaded and installed following the steps from [the official website](https://maven.apache.org/). Maven can also be installed easily on **Linux/MacOS** using [Homebrew](https://brew.sh/) package manager.
43+
44+
- You would have to add the following maven dependency to your `pom.xml` file if working on your local project.
45+
```xml
46+
<dependency>
47+
<groupId>junit</groupId>
48+
<artifactId>junit</artifactId>
49+
<version>4.12</version>
50+
<scope>test</scope>
51+
</dependency>
52+
```
53+
54+
### Cloning Repo And Installing Dependencies
55+
56+
**Step 1:** Clone the LambdaTest’s JUnit-Selenium-Sample repository and navigate to the code directory as shown below:
57+
58+
```bash
59+
git clone https://github.com/LambdaTest/junit-selenium-sample
60+
cd junit-selenium-sample
61+
```
62+
63+
You may also want to run the command below to check for outdated dependencies.
64+
65+
```bash
66+
mvn versions:display-dependency-updates
67+
```
68+
69+
### Setting Up Your Authentication
70+
71+
Make sure you have your LambdaTest credentials with you to run test automation scripts. You can get these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build) or by your [LambdaTest Profile](https://accounts.lambdatest.com/login).
72+
73+
**Step 2:** Set LambdaTest **Username** and **Access Key** in environment variables.
74+
75+
* For **Linux/macOS**:
76+
77+
```bash
78+
export LT_USERNAME="YOUR_USERNAME"
79+
export LT_ACCESS_KEY="YOUR ACCESS KEY"
80+
```
81+
* For **Windows**:
82+
```bash
83+
set LT_USERNAME="YOUR_USERNAME"
84+
set LT_ACCESS_KEY="YOUR ACCESS KEY"
85+
```
86+
87+
## Run Your First Test
88+
89+
>**Test Scenario**: Checkout sample [JUnitTodo.java](https://github.com/LambdaTest/junit-selenium-sample/blob/master/src/test/java/com/lambdatest/JUnitTodo.java) file. This JUnit Selenium script tests a sample to-do list app by marking couple items as done, adding a new item to the list and finally displaying the count of pending items as output.
90+
91+
### Configuring your Test Capabilities
92+
93+
**Step 3:** In the test script, you need to update your test capabilities. In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. The capabilities object in the above code are defined as:
94+
95+
```java
96+
DesiredCapabilities capabilities = new DesiredCapabilities();
97+
capabilities.setCapability("browserName", "chrome");
98+
capabilities.setCapability("version", "latest");
99+
capabilities.setCapability("platform", "Windows 10"); // If this cap isn't specified, it will just get the any
100+
// available one
101+
capabilities.setCapability("build", "Junit Testing Example");
102+
capabilities.setCapability("name", "GeoLocation Test");
103+
capabilities.setCapability("plugin", "git-junit");
104+
105+
// Chrome options to add extension file (Works with file size upto 10MB)
106+
ChromeOptions options = new ChromeOptions ();
107+
options.addExtensions (new File("./LambdatestScreenshotExtension.crx"));
108+
caps.setCapability(ChromeOptions.CAPABILITY, options);
109+
```
110+
111+
### Upload extension on to Lambda Storage and use in automation tests for Large extensions
112+
- To upload the extension.zip file onto the lambda storage, you can use the extensions API we have :
113+
- Apid Doc URL: https://www.lambdatest.com/support/docs/api-doc/#/extensions/UploadExtensions
114+
Authorization: Basic Auth (LambdaTest Credentials)
115+
Body: form-data{ key: extensions value: file.zip }
116+
117+
You have to upload the original extension zip file instead of the crx file.Note.
118+
Attaching a sample LT extension for your reference.
119+
Extension: https://drive.google.com/file/d/1dvq4bhEOfmCrpG6ekdaIg9UB8tr9z3NJ/view?usp=sharing
120+
Once you have uploaded the Zip file, you'll get the `s3_url` which can be used in the respective capability.
121+
122+
```java
123+
String[] extention = {"https://automation-prod-user-files.s3.amazonaws.com/extensions/orgId-XXXX/2.1.0_0.zip"};
124+
capabilities.setCapability("lambda:loadExtension", extention);
125+
```
126+
You can generate capabilities for your test requirements with the help of our inbuilt [Desired Capability Generator](https://www.lambdatest.com/capabilities-generator/).
127+
128+
You can generate capabilities for your test requirements with the help of our inbuilt [Desired Capability Generator](https://www.lambdatest.com/capabilities-generator/).
129+
130+
### Executing the Test
131+
132+
**Step 4:** The tests can be executed in the terminal using the following command.
133+
134+
```bash
135+
mvn test -P single
136+
```
137+
138+
Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build).
139+
140+
## Run Parallel Tests Using JUnit
141+
142+
Check out the [Parallelized.java](https://github.com/LambdaTest/junit-selenium-sample/blob/master/src/test/java/com/lambdatest/Parallelized.java) class we have used for running our Parallel Tests using JUnit.
143+
144+
145+
Check out the [JUnitConcurrentTodo.java](https://github.com/LambdaTest/junit-selenium-sample/blob/master/src/test/java/com/lambdatest/JUnitConcurrentTodo.java) file for executing parallel test using JUnit automation framework.
146+
147+
### Executing Parallel Tests Using JUnit
148+
149+
To run parallel tests using **JUnit**, we would have to execute the below command in the terminal:
150+
151+
```bash
152+
mvn test -P parallel
153+
```
154+
155+
## Testing Locally Hosted Or Privately Hosted Projects
156+
157+
You can test your locally hosted or privately hosted projects with LambdaTest Selenium grid using LambdaTest Tunnel. All you would have to do is set up an SSH tunnel using tunnel and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are live.
158+
159+
Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information.
160+
161+
Here’s how you can establish LambdaTest Tunnel.
162+
163+
Download the binary file of:
164+
* [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip)
165+
* [LambdaTest Tunnel for macOS](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip)
166+
* [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip)
167+
168+
Open command prompt and navigate to the binary folder.
169+
170+
Run the following command:
171+
172+
```bash
173+
LT -user {user’s login email} -key {user’s access key}
174+
```
175+
So if your user name is [email protected] and key is 123456, the command would be:
176+
177+
```bash
178+
LT -user [email protected] -key 123456
179+
```
180+
Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below :
181+
182+
**Tunnel Capability**
183+
184+
```java
185+
DesiredCapabilities capabilities = new DesiredCapabilities();
186+
capabilities.setCapability("tunnel", true);
187+
```
188+
189+
## Tutorials 📙
190+
191+
Check out our latest tutorials on JUnit automation testing 👇
192+
193+
* [JUnit 5 vs TestNG: Choosing the Right Frameworks for Selenium Automation Testing](https://www.lambdatest.com/blog/junit-5-vs-testng/)
194+
* [TestNG vs JUnit: Which Testing Framework Should You Choose?](https://www.lambdatest.com/blog/testng-vs-junit-which-testing-framework-should-you-choose/)
195+
* [JUnit With Selenium](https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/)
196+
* [JUnit Environment Setup](https://www.lambdatest.com/blog/setup-junit-environment/)
197+
* [How to Run JUnit Selenium Tests Using TestNG?](https://www.lambdatest.com/blog/test-example-junit-and-testng-in-selenium/)
198+
* [[Complete JUnit 5 Mockito Tutorial for Unit Testing]](https://www.lambdatest.com/blog/junit5-mockito-tutorial/)
199+
* [Parallel Testing with JUnit 5 and Selenium [Tutorial]](https://www.lambdatest.com/blog/parallel-testing-with-junit5-and-selenium/)
200+
* [How to Execute JUnit 4 Tests with JUnit 5 [Tutorial]](https://www.lambdatest.com/blog/execute-junit4-tests-with-junit5/)
201+
* [How to Run JUnit Tests from the Command Line?](https://www.lambdatest.com/blog/run-junit-from-command-line/)
202+
* [How to Minimize Browsers in Selenium WebDriver Using JUnit?](https://www.lambdatest.com/blog/minimize-browsers-in-selenium-webdriver/)
203+
* [How to use @RepeatedTest Annotations in JUnit 5?](https://www.lambdatest.com/blog/repeatedtest-annotation-in-junit-5/)
204+
* [A Comprehensive Guide on JUnit 5 Extensions](https://www.lambdatest.com/blog/junit5-extensions/)
205+
* [How to Run JUnit Selenium Tests Using TestNG?](https://www.lambdatest.com/blog/test-example-junit-and-testng-in-selenium/)
206+
* [JUnit Parameterized Test for Selenium Automation with Examples](https://www.lambdatest.com/blog/junit-parameterized-test-selenium/)
207+
* [JUnit Asserts with Examples](https://www.lambdatest.com/blog/junit-assertions-example-for-selenium-testing/)
208+
* [Tutorial on JUnit Annotations with Examples](https://www.lambdatest.com/blog/tutorial-on-junit-annotations-in-selenium-with-examples/)
209+
* [Automated Testing with JUnit and Selenium for Browser Compatibility](https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/)
210+
211+
For video tutorials on Selenium JUnit, please refer to our [JUnit Tutorial Playlist](https://www.youtube.com/playlist?list=PLZMWkkQEwOPn68qzCGJl07ZbnI7Ix5zKU). ▶️
212+
213+
Subscribe To Our [LambdaTest YouTube Channel 🔔](https://www.youtube.com/c/LambdaTest) and keep up-to-date on the latest video tutorial around software testing world.
214+
215+
## Documentation & Resources :books:
216+
217+
218+
Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing.
219+
220+
* [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample)
221+
* [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample)
222+
* [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample)
223+
224+
## LambdaTest Community :busts_in_silhouette:
225+
226+
The [LambdaTest Community](https://community.lambdatest.com/) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎
227+
228+
## What's New At LambdaTest ❓
229+
230+
To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
231+
232+
## About LambdaTest
233+
234+
[LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs.
235+
236+
### Features
237+
238+
* Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
239+
* Real-time cross browser testing on 3000+ environments.
240+
* Test on Real device cloud
241+
* Blazing fast test automation with HyperExecute
242+
* Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
243+
* Smart Visual Regression Testing on cloud
244+
* 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
245+
* Automated Screenshot testing across multiple browsers in a single click.
246+
* Local testing of web and mobile apps.
247+
* Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
248+
* Geolocation testing of web and mobile apps across 53+ countries.
249+
* LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
250+
251+
252+
[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register)
253+
254+
255+
## We are here to help you :headphones:
256+
257+
* Got a query? we are available 24x7 to help. [Contact Us]([email protected])
258+
* For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=junit-selenium-sample)
376 KB
Loading

pom.xml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.lambdatest</groupId>
6+
<artifactId>lambdatest-junit-sample</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<surefire.version>2.19.1</surefire.version>
13+
14+
<test.file></test.file>
15+
<config.file>default</config.file>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.13.1</version>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>commons-io</groupId>
27+
<artifactId>commons-io</artifactId>
28+
<version>2.7</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.seleniumhq.selenium</groupId>
33+
<artifactId>selenium-java</artifactId>
34+
<version>3.141.59</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.googlecode.json-simple</groupId>
39+
<artifactId>json-simple</artifactId>
40+
<version>1.1.1</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
46+
<build>
47+
<plugins>
48+
49+
<plugin>
50+
<artifactId>maven-compiler-plugin</artifactId>
51+
<version>3.0</version>
52+
<configuration>
53+
<source>1.8</source>
54+
<target>1.8</target>
55+
</configuration>
56+
</plugin>
57+
58+
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-surefire-plugin</artifactId>
62+
<version>2.12.4</version>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
<profiles>
68+
69+
<profile>
70+
<id>parallel</id>
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-surefire-plugin</artifactId>
76+
<configuration>
77+
<includes>
78+
<include>com/lambdatest/JUnitConcurrentTodo.java</include>
79+
</includes>
80+
</configuration>
81+
</plugin>
82+
</plugins>
83+
</build>
84+
</profile>
85+
86+
<profile>
87+
<id>single</id>
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-surefire-plugin</artifactId>
93+
<configuration>
94+
<includes>
95+
<include>com/lambdatest/Extension.java</include>
96+
</includes>
97+
</configuration>
98+
</plugin>
99+
</plugins>
100+
</build>
101+
</profile>
102+
103+
</profiles>
104+
105+
</project>

0 commit comments

Comments
 (0)