Skip to content

Commit dff8989

Browse files
authored
Merge pull request #12 from raghuhit/buildVariantsSupport
Build variants support
2 parents aa740ae + cf85281 commit dff8989

10 files changed

Lines changed: 704 additions & 355 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ build/
44
.classpath
55
.settings/
66
bin/
7+
.idea/
8+
out/
9+
espresso-browserstack/

README.md

Lines changed: 77 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,58 @@ This repository contains the source code for BrowserStack's Gradle plugin.
44

55
<br/>
66

7-
>Note: For now this plugin supports Espresso tests.
7+
## PURPOSE
88

9-
## Espresso
9+
This plugin consists of two types of tasks:
1010

11-
Add to build.gradle:
11+
1. Builds, uploads and starts Espresso tests on BrowserStack AppAutomate.
12+
2. Builds and uploads apk to BrowserStack AppLive for manual testing.
1213

13-
plugins {
14-
id: com.browserstack.gradle
15-
}
14+
## USAGE
1615

17-
runDebugBuildOnBrowserstack {
18-
username = "<username>"
19-
accessKey = "<accessKey>"
20-
devices = ['Google Pixel-7.1']
21-
}
16+
### Add to build.gradle
2217

18+
#### Add plugin dependency to module's build.gradle
2319

24-
Supported parameters:
20+
```
21+
plugins {
22+
id "com.browserstack.gradle" version "2.3.0"
23+
}
24+
```
25+
26+
#### Add browserStackConfig parameters to module's build.gradle
27+
28+
```
29+
browserStackConfig {
30+
username = "<browserstack_username>"
31+
accessKey = "<browserstack_access_key>"
32+
devices = ['Google Pixel-7.1']
33+
}
34+
```
35+
36+
### Tasks
37+
38+
#### Espresso test task
39+
Builds, uploads and start Espresso tests on BrowserStack AppAutomate.
40+
41+
##### Gradle command
42+
43+
gradle clean execute${buildVariantName}TestsOnBrowserstack
44+
45+
For running tests on a project with no variants, you can simply run following command for uploading and running tests on debug apk:
46+
47+
```
48+
gradle clean executeDebugTestsOnBrowserstack
49+
```
50+
51+
And for projects with productFlavors, replace ${buildVariantName} with your build variant name, for example if your productFlavor name is "phone" and you want to test debug build type of this variant then command will be
52+
53+
```
54+
gradle clean executePhoneDebugTestsOnBrowserstack
55+
56+
```
57+
58+
##### Supported browserStackConfig parameters
2559

2660
username: String
2761
accessKey: String
@@ -39,45 +73,51 @@ Supported parameters:
3973
callbackURL: String
4074
networkProfile: String
4175

76+
> Note: username, accessKey and devices are mandatory parameters. Visit https://www.browserstack.com/app-automate/espresso/get-started to get started with Espresso Tests on BrowserStack and also to know more about the above mentioned parameters.
4277
43-
> Note: username, accessKey and devices are compulsory parameters. Visit https://www.browserstack.com/app-automate/espresso/get-started to get started with Espresso Tests on BrowserStack and also to know more about the above mentioned parameters.
44-
45-
> Note: List of supported devices and be found [here](https://api.browserstack.com/app-automate/espresso/devices.json) (basic auth required).
46-
47-
To run an Espresso test on BrowserStack using this plugin, use the following command:
78+
> Note: List of supported devices and be found [here](https://api.browserstack.com/app-automate/espresso/devices.json) (basic auth required). For example :``` curl -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" https://api-cloud.browserstack.com/app-automate/devices.json ```
4879
49-
gradle runDebugBuildOnBrowserstack
80+
> Note: You can also set the values of username and accessKey in environment variables with names BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY, respectively. If you do this, then there is no need to set this parameters in browserStackConfig block.
5081
51-
This will execute the following:
82+
##### Internal steps
5283

53-
1. Build debug and test apks, as dependencies are declared on `assembleDebug` and `assembleDebugAndroidTest` tasks.
84+
1. Build debug and test apks, as dependencies are declared on `assemble${buildvariantName}` and `assemble${buildvariantName}AndroidTest` tasks.
5485
2. Find the latest apks in the app directory recursively.
55-
3. Upload both the apks on BrowserStack platform.
86+
3. Upload both the apks on BrowserStack AppAutomate platform.
5687
4. Execute Espresso test using the uploaded apps on the devices mentioned.
5788

58-
### Using this plugin in android studio
89+
#### Upload to AppLive task
5990

60-
Add this plugin to your `buildscript`:
91+
##### Gradle command
6192

62-
```
63-
buildscript {
64-
repositories {
65-
maven {
66-
url "https://plugins.gradle.org/m2/"
67-
}
68-
}
69-
dependencies {
70-
classpath 'com.browserstack.gradle:com.browserstack.gradle.gradle.plugin:2.2.0'
71-
}
72-
}
73-
```
93+
gradle clean upload${buildVariantName}ToBrowserstackAppLive
7494

75-
and apply it in your module build.gradle
95+
For running tests on a project with no variants, you can simply run following command for uploading debug apk:
7696

7797
```
78-
apply plugin: 'com.browserstack.gradle'
98+
gradle clean uploadDebugToBrowserstackAppLive
7999
```
80100

101+
And for projects with productFlavors, replace ${buildVariantName} with your build variant name, for example if your productFlavor name is "phone" and you want to upload debug build type of this variant then command will be gradle clean uploadPhoneDebugToBrowserstackAppLive.
102+
103+
##### Supported browserStackConfig parameters
104+
105+
username: String
106+
accessKey: String
107+
108+
> Note: username and accessKey are mandatory parameters.
109+
110+
##### Internal steps
111+
112+
1. Build debug and test apks, as dependencies are declared on `assemble${buildvariantName}` .
113+
2. Find the latest apk in the app directory recursively.
114+
3. Upload the apk on BrowserStack AppLive platform.
115+
116+
117+
> Note: You can also set the values of username and accessKey in environment variables with names BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY, respectively. If you do this, then there is no need to set these parameters in browserStackConfig block.
118+
119+
> Note: You can also see all possible tasks by running "gradle tasks -all"
120+
81121
### Development
82122

83123
Build the plugin

build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'com.gradle.plugin-publish' version '0.9.10'
44
}
55

6-
version '2.2.0'
6+
version '2.3.0'
77

88
pluginBundle {
99
website = 'https://www.browserstack.com'
@@ -19,3 +19,12 @@ pluginBundle {
1919
}
2020
}
2121
}
22+
23+
repositories {
24+
mavenCentral()
25+
}
26+
27+
dependencies {
28+
// https://mvnrepository.com/artifact/com.android.tools.build/gradle
29+
compile group: 'com.android.tools.build', name: 'gradle', version: '2.3.0'
30+
}

src/main/java/com/browserstack/gradle/AppUploadTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class AppUploadTask extends BrowserStackTask {
99

10-
private void displayTestURL(String app_url){
10+
private void displayTestURL(String app_url) {
1111
String app_hashed_id = app_url.substring(5);
1212
System.out.println("Start testing at " + Constants.APP_LIVE_HOST + "/#app_hashed_id=" + app_hashed_id);
1313
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
package com.browserstack.gradle;
2+
3+
// This class is for getting browserstack configuration from gradle file.
4+
public class BrowserStackConfigExtension {
5+
6+
private String username = System.getenv("BROWSERSTACK_USERNAME");
7+
private String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
8+
9+
private String[] classes, annotations, packages, sizes, otherApps;
10+
11+
private boolean video = Constants.DEFAULT_VIDEO;
12+
private boolean deviceLogs = Constants.DEFAULT_DEVICE_LOGS;
13+
private boolean local = Constants.DEFAULT_LOCAL;
14+
private boolean networkLogs = Constants.DEFAULT_NETWORK_LOGS;
15+
16+
String[] devices;
17+
18+
private String callbackURL, localIdentifier, networkProfile;
19+
20+
public String getUsername() {
21+
return username;
22+
}
23+
24+
public String getAccessKey() {
25+
return accessKey;
26+
}
27+
28+
public String[] getClasses() {
29+
if (classes == null) {
30+
classes = new String[0];
31+
}
32+
return classes;
33+
}
34+
35+
public String[] getAnnotations() {
36+
if (annotations == null) {
37+
annotations = new String[0];
38+
}
39+
return annotations;
40+
}
41+
42+
public String[] getPackages() {
43+
if (packages == null) {
44+
packages = new String[0];
45+
}
46+
return packages;
47+
}
48+
49+
public String[] getSizes() {
50+
if (sizes == null) {
51+
sizes = new String[0];
52+
}
53+
return sizes;
54+
}
55+
56+
public String[] getOtherApps() {
57+
if (otherApps == null) {
58+
otherApps = new String[0];
59+
}
60+
return otherApps;
61+
}
62+
63+
public boolean isVideo() {
64+
return video;
65+
}
66+
67+
public boolean isDeviceLogs() {
68+
return deviceLogs;
69+
}
70+
71+
public boolean isLocal() {
72+
return local;
73+
}
74+
75+
public boolean isNetworkLogs() {
76+
return networkLogs;
77+
}
78+
79+
public String[] getDevices() {
80+
return devices;
81+
}
82+
83+
public String getCallbackURL() {
84+
return callbackURL;
85+
}
86+
87+
public String getLocalIdentifier() {
88+
return localIdentifier;
89+
}
90+
91+
public String getNetworkProfile() {
92+
return networkProfile;
93+
}
94+
95+
public void setUsername(String username) {
96+
this.username = username;
97+
}
98+
99+
public void setAccessKey(String accessKey) {
100+
this.accessKey = accessKey;
101+
}
102+
103+
public void setClasses(String[] classes) {
104+
this.classes = classes;
105+
}
106+
107+
public void setAnnotations(String[] annotations) {
108+
this.annotations = annotations;
109+
}
110+
111+
public void setPackages(String[] packages) {
112+
this.packages = packages;
113+
}
114+
115+
public void setSizes(String[] sizes) {
116+
this.sizes = sizes;
117+
}
118+
119+
public void setOtherApps(String[] otherApps) {
120+
this.otherApps = otherApps;
121+
}
122+
123+
public void setVideo(boolean video) {
124+
this.video = video;
125+
}
126+
127+
public void setDeviceLogs(boolean deviceLogs) {
128+
this.deviceLogs = deviceLogs;
129+
}
130+
131+
public void setLocal(boolean local) {
132+
this.local = local;
133+
}
134+
135+
public void setNetworkLogs(boolean networkLogs) {
136+
this.networkLogs = networkLogs;
137+
}
138+
139+
public void setDevices(String[] devices) {
140+
this.devices = devices;
141+
}
142+
143+
public void setCallbackURL(String callbackURL) {
144+
this.callbackURL = callbackURL;
145+
}
146+
147+
public void setLocalIdentifier(String localIdentifier) {
148+
this.localIdentifier = localIdentifier;
149+
}
150+
151+
public void setNetworkProfile(String networkProfile) {
152+
this.networkProfile = networkProfile;
153+
}
154+
}

0 commit comments

Comments
 (0)