Skip to content

Commit e857a5a

Browse files
authored
Added the new Test Script (#1)
* Added the new Test Script * Added new test script * Update: Added the .DS_Store in .gitignore * adding gitignore * Delete .DS_Store * Made changes to the files to optimise the code. * Removed workspace.xml * Made changes to the Readme.md file * Removed the folder target
1 parent 5094ba5 commit e857a5a

File tree

5 files changed

+390
-1
lines changed

5 files changed

+390
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
25+
.DS_Store
26+
.DS_Store

README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
11
# LT-appium-java-junit
2-
LT-appium-java-junit repo
2+
3+
## Prerequisites
4+
5+
To run your test script using JUnit with Appium, first you need to setup the environment.
6+
7+
1. Install JDK 1.6 or higher version
8+
2. Latest Selenium client and it’s WebDriver Bindings.
9+
3. Download Maven([Windows](https://maven.apache.org/download.cgi), [Linux](https://maven.apache.org/install.html), and [Mac](https://maven.apache.org/install.html)) or Ant. Maven supports JUnit out of the box. You would just have to define Appium dependencies in it’s project object model file or pom.xml file.
10+
4. Optional - To test your locally or privately hosted files, you need LambdaTest Tunnel binary file.
11+
12+
## Steps to Run your First Test
13+
14+
Step 1. Clone the Junit-Appium-Sample Repository.
15+
16+
```
17+
git clone https://github.com/LambdaTest/LT-appium-java-junit.git
18+
```
19+
20+
Step 2. Inside Junit-Appium-sample folder, set the Lambda-test Credentials. You can get these from your automation dashboard.
21+
22+
<p align="center">
23+
<b>For Linux/macOS:</b>
24+
25+
```
26+
export LT_USERNAME="YOUR_USERNAME"
27+
export LT_ACCESS_KEY="YOUR ACCESS KEY"
28+
```
29+
30+
<p align="center">
31+
<b>For Windows:</b>
32+
33+
```
34+
set LT_USERNAME="YOUR_USERNAME"
35+
set LT_ACCESS_KEY="YOUR ACCESS KEY"
36+
```
37+
38+
Step 3. Before running the Test
39+
40+
```
41+
mvn clean
42+
```
43+
44+
Step 4. To run your First Test.
45+
46+
```
47+
mvn test -P single
48+
```
49+
50+
Step 5. To run Parallel Test.
51+
52+
```
53+
mvn test -P parallel
54+
```
55+
56+
## See the Results
57+
58+
You can see the results of the test on Lambdatest [Automation Dashboard](https://automation.lambdatest.com/build)
59+
![Dashboard](https://github.com/LambdaTest/junit-selenium-sample/dashboard)
60+
61+
## Testing Locally Hosted or Privately Hosted Projects
62+
63+
To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name Lambda Tunnel. With Lambda Tunnel, you can test your locally hosted files before you make them live over the internet. You could even perform cross browser testing from different IP addresses belonging to various geographic locations. You can also use LambdaTest Tunnel to test web-apps and websites that are permissible inside your corporate firewall.
64+
65+
- Set tunnel value to True in test capabilities
66+
> OS specific instructions to download and setup tunnel binary can be found at the following links.
67+
>
68+
> - [Windows](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Windows)
69+
> - [Mac](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+MacOS)
70+
> - [Linux](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Linux)
71+
> After setting tunnel you can also see the active tunnel in our LambdaTest dashboard:
72+
> ![tunnel active](https://github.com/LambdaTest/Robot-Selenium-Sample/blob/master/tutorial-images/tn.PNG)
73+
74+
## About LambdaTest
75+
76+
[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel.

pom.xml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.lambdatest</groupId>
8+
<artifactId>lambdatest-junit-sample</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
13+
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<surefire.version>2.19.1</surefire.version>
18+
19+
<test.file></test.file>
20+
<config.file>default</config.file>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>junit</groupId>
26+
<artifactId>junit</artifactId>
27+
<version>4.12</version>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>commons-io</groupId>
32+
<artifactId>commons-io</artifactId>
33+
<version>1.3.2</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.seleniumhq.selenium</groupId>
38+
<artifactId>selenium-java</artifactId>
39+
<version>3.141.59</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.googlecode.json-simple</groupId>
44+
<artifactId>json-simple</artifactId>
45+
<version>1.1.1</version>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.appium</groupId>
50+
<artifactId>java-client</artifactId>
51+
<version>6.1.0</version>
52+
<scope>test</scope>
53+
</dependency>
54+
</dependencies>
55+
56+
57+
<build>
58+
<plugins>
59+
60+
<plugin>
61+
<artifactId>maven-compiler-plugin</artifactId>
62+
<version>3.0</version>
63+
<configuration>
64+
<source>1.8</source>
65+
<target>1.8</target>
66+
</configuration>
67+
</plugin>
68+
69+
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-surefire-plugin</artifactId>
73+
<version>2.12.4</version>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
78+
<profiles>
79+
80+
<profile>
81+
<id>parallel</id>
82+
<build>
83+
<plugins>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-surefire-plugin</artifactId>
87+
<configuration>
88+
<includes>
89+
<include>com/lambdatest/JUnitConcurrentTodo.java</include>
90+
</includes>
91+
</configuration>
92+
</plugin>
93+
</plugins>
94+
</build>
95+
</profile>
96+
97+
<profile>
98+
<id>single</id>
99+
<build>
100+
<plugins>
101+
<plugin>
102+
<groupId>org.apache.maven.plugins</groupId>
103+
<artifactId>maven-surefire-plugin</artifactId>
104+
<configuration>
105+
<includes>
106+
<include>com/lambdatest/NativeApp.java</include>
107+
</includes>
108+
</configuration>
109+
</plugin>
110+
</plugins>
111+
</build>
112+
</profile>
113+
114+
</profiles>
115+
116+
</project>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.lambdatest;
2+
3+
import io.appium.java_client.MobileBy;
4+
import org.junit.After;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
import org.openqa.selenium.remote.DesiredCapabilities;
8+
import org.openqa.selenium.remote.RemoteWebDriver;
9+
import org.openqa.selenium.By;
10+
11+
import org.openqa.selenium.support.ui.ExpectedConditions;
12+
import org.openqa.selenium.support.ui.WebDriverWait;
13+
14+
import java.net.MalformedURLException;
15+
import java.net.URL;
16+
17+
public class android {
18+
String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Enter the Username here
19+
: System.getenv("LT_USERNAME");
20+
String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Enter the Access key here
21+
: System.getenv("LT_ACCESS_KEY");
22+
public static RemoteWebDriver driver = null;
23+
public String gridURL = "@beta-hub.lambdatest.com/wd/hub";
24+
public String status = "passed";
25+
@Before
26+
public void setUp() throws Exception {
27+
DesiredCapabilities capabilities = new DesiredCapabilities();
28+
29+
capabilities.setCapability("build", "JUNIT Native App automation");
30+
capabilities.setCapability("name", "Java JUnit Android Pixel 6");
31+
capabilities.setCapability("platformName", "android");
32+
capabilities.setCapability("deviceName", "Pixel 6"); //Enter the name of the device here
33+
capabilities.setCapability("isRealMobile", true);
34+
capabilities.setCapability("platformVersion","12");
35+
capabilities.setCapability("app","App_ID"); //Enter the App ID here
36+
capabilities.setCapability("deviceOrientation", "PORTRAIT");
37+
capabilities.setCapability("console",true);
38+
capabilities.setCapability("network",true);
39+
capabilities.setCapability("visual",true);
40+
try
41+
{
42+
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + gridURL), capabilities);
43+
}
44+
catch (MalformedURLException e)
45+
{
46+
System.out.println("Invalid grid URL");
47+
} catch (Exception e)
48+
{
49+
System.out.println(e.getMessage());
50+
}
51+
}
52+
53+
@Test
54+
public void testSimple() throws Exception
55+
{
56+
try
57+
{
58+
WebDriverWait wait = new WebDriverWait(driver, 30);
59+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click();
60+
61+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click();;
62+
Thread.sleep(5000);
63+
driver.navigate().back();
64+
65+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click();
66+
67+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click();;
68+
69+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click();
70+
71+
wait.until(ExpectedConditions.elementToBeClickable(By.id("Browser"))).click();;
72+
Thread.sleep(10000);
73+
74+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/");
75+
76+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click();
77+
Thread.sleep(5000);
78+
driver.navigate().back();
79+
80+
status="passed";
81+
}
82+
catch (Exception e)
83+
{
84+
System.out.println(e.getMessage());
85+
status="failed";
86+
}
87+
}
88+
@After
89+
public void tearDown() throws Exception
90+
{
91+
if (driver != null)
92+
{
93+
driver.executeScript("lambda-status=" + status);
94+
driver.quit();
95+
}
96+
}
97+
}
98+

0 commit comments

Comments
 (0)