Skip to content

Commit f2baa82

Browse files
committed
created dedicated directories for java7 and java8
1 parent 2f1f069 commit f2baa82

12 files changed

+609
-0
lines changed

java_7/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# java-appium-app-browserstack
2+
3+
This repository demonstrates how to run Appium Java tests on BrowserStack App Automate.
4+
5+
## Setup
6+
7+
### Requirements
8+
9+
1. Java 8+
10+
11+
- If Java is not installed, follow these instructions:
12+
- For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable
13+
- For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/)
14+
15+
2. Maven
16+
17+
- If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi)
18+
- For installation, follow the instructions [here](https://maven.apache.org/install.html)
19+
20+
### Install the dependencies
21+
22+
To install the dependencies, run the following command in the project's base folder
23+
24+
```cmd
25+
mvn clean install
26+
```
27+
28+
## Getting Started
29+
30+
Getting Started with Appium tests in Java on BrowserStack couldn't be easier!
31+
32+
### Run your first test :
33+
34+
**1. Upload your Android or iOS App**
35+
36+
Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request :
37+
38+
```
39+
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
40+
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
41+
-F "file=@/path/to/apk/file"
42+
```
43+
44+
Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.
45+
46+
**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa).
47+
48+
**2. Configure and run your first test**
49+
50+
Open `BrowserStackSample.java` file in the `android` directory or `ios` directory :
51+
52+
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
53+
54+
- Replace `bs://<app-id>` with the URL obtained from app upload step
55+
56+
- Set the device and OS version
57+
58+
- If you have uploaded your own app update the test case
59+
60+
- To run the test, use the following command in the base directory :
61+
62+
- For Android test, run
63+
64+
```cmd
65+
mvn test -P android-first-test
66+
```
67+
68+
- For iOS test, run
69+
70+
```cmd
71+
mvn test -P ios-first-test
72+
```
73+
74+
- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)
75+
76+
---
77+
78+
### Use Local testing for apps that access resources hosted in development or testing environments :
79+
80+
**1. Upoad your Android or iOS App**
81+
82+
Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request :
83+
84+
```
85+
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
86+
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
87+
-F "file=@/path/to/apk/file"
88+
```
89+
90+
Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.
91+
92+
**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa).
93+
94+
**2. Configure and run your local test**
95+
96+
Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory :
97+
98+
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
99+
100+
- Replace `bs://<app-id>` with the URL obtained from app upload step
101+
102+
- Set the device and OS version
103+
104+
- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local.
105+
106+
- If you have uploaded your own app update the test case
107+
108+
- To run the test, use the following command in the base directory :
109+
110+
- For Android test, run
111+
112+
```cmd
113+
mvn test -P android-local-test
114+
```
115+
116+
- For iOS test, run
117+
118+
```cmd
119+
mvn test -P ios-local-test
120+
```
121+
122+
- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)
123+
124+
125+
## Integration with other Java frameworks
126+
127+
- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack)
128+
- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack)
129+
130+
## Getting Help
131+
132+
If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help).

java_7/pom.xml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.browserstack</groupId>
6+
<artifactId>java-browserstack</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>java-browserstack</name>
9+
<description>Java appium app browserstack</description>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<surefire.version>2.19.1</surefire.version>
14+
<test.file></test.file>
15+
<config.file>default</config.file>
16+
</properties>
17+
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>commons-io</groupId>
22+
<artifactId>commons-io</artifactId>
23+
<version>1.3.2</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>io.appium</groupId>
27+
<artifactId>java-client</artifactId>
28+
<version>7.0.0</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.browserstack</groupId>
32+
<artifactId>browserstack-local-java</artifactId>
33+
<version>1.0.3</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.googlecode.json-simple</groupId>
37+
<artifactId>json-simple</artifactId>
38+
<version>1.1.1</version>
39+
</dependency>
40+
</dependencies>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<version>2.22.2</version>
48+
</plugin>
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-compiler-plugin</artifactId>
52+
<version>3.8.1</version>
53+
<configuration>
54+
<source>1.8</source>
55+
<target>1.8</target>
56+
</configuration>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
<profiles>
62+
<profile>
63+
<id>android-first-test</id>
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.codehaus.mojo</groupId>
68+
<artifactId>exec-maven-plugin</artifactId>
69+
<version>1.1.1</version>
70+
<executions>
71+
<execution>
72+
<phase>test</phase>
73+
<goals>
74+
<goal>java</goal>
75+
</goals>
76+
<configuration>
77+
<mainClass>android.BrowserStackSample</mainClass>
78+
<classpathScope>test</classpathScope>
79+
</configuration>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
</profile>
86+
<profile>
87+
<id>android-local-test</id>
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.codehaus.mojo</groupId>
92+
<artifactId>exec-maven-plugin</artifactId>
93+
<version>1.1.1</version>
94+
<executions>
95+
<execution>
96+
<phase>test</phase>
97+
<goals>
98+
<goal>java</goal>
99+
</goals>
100+
<configuration>
101+
<mainClass>android.BrowserStackSampleLocal</mainClass>
102+
<classpathScope>test</classpathScope>
103+
</configuration>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
</profile>
110+
<profile>
111+
<id>ios-first-test</id>
112+
<build>
113+
<plugins>
114+
<plugin>
115+
<groupId>org.codehaus.mojo</groupId>
116+
<artifactId>exec-maven-plugin</artifactId>
117+
<version>1.1.1</version>
118+
<executions>
119+
<execution>
120+
<phase>test</phase>
121+
<goals>
122+
<goal>java</goal>
123+
</goals>
124+
<configuration>
125+
<mainClass>ios.BrowserStackSample</mainClass>
126+
<classpathScope>test</classpathScope>
127+
</configuration>
128+
</execution>
129+
</executions>
130+
</plugin>
131+
</plugins>
132+
</build>
133+
</profile>
134+
<profile>
135+
<id>ios-local-test</id>
136+
<build>
137+
<plugins>
138+
<plugin>
139+
<groupId>org.codehaus.mojo</groupId>
140+
<artifactId>exec-maven-plugin</artifactId>
141+
<version>1.1.1</version>
142+
<executions>
143+
<execution>
144+
<phase>test</phase>
145+
<goals>
146+
<goal>java</goal>
147+
</goals>
148+
<configuration>
149+
<mainClass>ios.BrowserStackSampleLocal</mainClass>
150+
<classpathScope>test</classpathScope>
151+
</configuration>
152+
</execution>
153+
</executions>
154+
</plugin>
155+
</plugins>
156+
</build>
157+
</profile>
158+
</profiles>
159+
160+
</project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package android;
2+
3+
import java.net.URL;
4+
import java.util.List;
5+
import java.util.function.Function;
6+
import java.net.MalformedURLException;
7+
8+
import io.appium.java_client.MobileBy;
9+
import io.appium.java_client.android.AndroidDriver;
10+
import io.appium.java_client.android.AndroidElement;
11+
12+
import org.openqa.selenium.support.ui.ExpectedConditions;
13+
import org.openqa.selenium.support.ui.WebDriverWait;
14+
import org.openqa.selenium.WebDriver;
15+
import org.openqa.selenium.remote.DesiredCapabilities;
16+
17+
18+
public class BrowserStackSample {
19+
20+
public static void main(String[] args) throws MalformedURLException, InterruptedException {
21+
22+
DesiredCapabilities caps = new DesiredCapabilities();
23+
24+
// Set your access credentials
25+
caps.setCapability("browserstack.user", "YOUR_USERNAME");
26+
caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY");
27+
28+
// Set URL of the application under test
29+
caps.setCapability("app", "bs://<app-id>");
30+
31+
// Specify device and os_version for testing
32+
caps.setCapability("device", "Google Pixel 3");
33+
caps.setCapability("os_version", "9.0");
34+
35+
// Set other BrowserStack capabilities
36+
caps.setCapability("project", "First Java Project");
37+
caps.setCapability("build", "browserstack-build-1");
38+
caps.setCapability("name", "first_test");
39+
40+
41+
// Initialise the remote Webdriver using BrowserStack remote URL
42+
// and desired capabilities defined above
43+
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(
44+
new URL("http://hub.browserstack.com/wd/hub"), caps);
45+
46+
47+
// Test case for the BrowserStack sample Android app.
48+
// If you have uploaded your app, update the test case here.
49+
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
50+
ExpectedConditions.elementToBeClickable(
51+
MobileBy.AccessibilityId("Search Wikipedia")));
52+
searchElement.click();
53+
AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until(
54+
ExpectedConditions.elementToBeClickable(
55+
MobileBy.id("org.wikipedia.alpha:id/search_src_text")));
56+
insertTextElement.sendKeys("BrowserStack");
57+
Thread.sleep(5000);
58+
List<AndroidElement> allProductsName = driver.findElementsByClassName(
59+
"android.widget.TextView");
60+
assert(allProductsName.size() > 0);
61+
62+
63+
// Invoke driver.quit() after the test is done to indicate that the test is completed.
64+
driver.quit();
65+
66+
}
67+
68+
}

0 commit comments

Comments
 (0)