Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'com.gradle.plugin-publish' version '0.11.0'
}

version '3.1.2'
version '3.1.3'

pluginBundle {
website = 'https://www.browserstack.com'
Expand All @@ -17,7 +17,7 @@ pluginBundle {
description = 'Runs Espresso tests on BrowserStack'
tags = ['espresso', 'test', 'browserstack', 'app', 'automate',
'app-automate', 'appautomate', 'app-live', 'applive']
version = '3.1.2'
version = '3.1.3'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void apply(Project project) {
task.setGroup(DEFAULT_GROUP);
task.setDescription("Uploads app / tests to AppAutomate and executes them");
// Run Espresso tests without building the apk and test apk
if (!project.hasProperty("skipBuildingApks")) {
if (!project.hasProperty("skipBuildingApks") || Boolean.parseBoolean(project.property("skipBuildingApks").toString()) == false) {
task.dependsOn("assemble" + appVariantName, "assemble" + appVariantName + "AndroidTest");
}
task.setAppVariantBaseName(applicationVariant.getBaseName());
Expand All @@ -51,6 +51,12 @@ public void apply(Project project) {
task.setConfigFilePath(browserStackConfigExtension.getConfigFilePath());
task.setHost(Constants.BROWSERSTACK_API_HOST);
task.setDebug(browserStackConfigExtension.isDebug());
if(project.hasProperty("mainAPKPath")){
task.setMainAPKPath(project.property("mainAPKPath").toString());
}
if(project.hasProperty("testAPKPath")){
task.setTestAPKPath(project.property("testAPKPath").toString());
}
});

project.getTasks().create("upload" + appVariantName + "ToBrowserstackAppLive", AppLiveUploadTask.class, (task) -> {
Expand Down
79 changes: 69 additions & 10 deletions src/main/java/com/browserstack/gradle/BrowserStackTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
Expand Down Expand Up @@ -40,6 +41,14 @@ public class BrowserStackTask extends DefaultTask {
@Optional
public String command ;

@Input
@Optional
public String mainAPKPath;

@Input
@Optional
public String testAPKPath;

public void setAppVariantBaseName(String appVariantBaseName) {
this.appVariantBaseName = appVariantBaseName;
}
Expand Down Expand Up @@ -80,6 +89,14 @@ public void setHost(String host) {

public void setCommand(String command) { this.command = command; }

public String getMainAPKPath() { return mainAPKPath; }

public void setMainAPKPath(String mainAPKPath) { this.mainAPKPath = mainAPKPath; }

public String getTestAPKPath() {return testAPKPath; }

public void setTestAPKPath(String testAPKPath) { this.testAPKPath = testAPKPath; }

protected JSONObject constructDefaultBuildParams() { JSONObject params = new JSONObject();

params.put("app", app);
Expand Down Expand Up @@ -152,21 +169,60 @@ public static Path findMostRecentPath(List<Path> paths) {
return mostRecentPath;
}

private boolean isPathRelative(String apkPath){
if(apkPath.startsWith("./")){
return true;
}
return false;
}
private String getAbsolutePath(String apkPath, String currentWorkingDirectory){
if(isPathRelative(apkPath)){
return currentWorkingDirectory + apkPath.substring(1);
}
return apkPath;
}
public Map<String, Path> locateApks(boolean ignoreTestPath) throws IOException {
Path debugApkPath;
Path testApkPath;
String dir = System.getProperty("user.dir");
List<Path> appApkFiles = new ArrayList<>();
List<Path> testApkFiles = new ArrayList<>();
Files.find(Paths.get(dir), Constants.APP_SEARCH_MAX_DEPTH, (filePath, fileAttr) -> isValidFile(filePath, fileAttr))
.forEach(f -> {

if (f.toString().endsWith("-androidTest.apk")) {
testApkFiles.add(f);
} else {
appApkFiles.add(f);
}
});
final Boolean[] isAPKFileCreated = {false,false}; // 1st element stores true if main apk is read from path provided by client and false otherwise. 2nd element is for test apk.
if(mainAPKPath != null){
isAPKFileCreated[0] = true;
try {
Files.find(Paths.get(getAbsolutePath(mainAPKPath, dir)), 1, (filePath, fileAttr) -> isValidAPKFile(filePath, fileAttr))
.forEach(f -> {
appApkFiles.add(f);
});
}catch (NoSuchFileException e ){
throw new IOException("Invalid File Path: Please provide a valid main APK path");
}
}
if(testAPKPath != null){
isAPKFileCreated[1] = true;
try {
Files.find(Paths.get(getAbsolutePath(testAPKPath, dir)), 1, (filePath, fileAttr) -> isValidAPKFile(filePath, fileAttr))
.forEach(f -> {
testApkFiles.add(f);
});
}catch(NoSuchFileException e ){
throw new IOException("Invalid File Path: Please provide a valid test APK path");
}
}

if(!isAPKFileCreated[0] || !isAPKFileCreated[1]) {
Files.find(Paths.get(dir), Constants.APP_SEARCH_MAX_DEPTH, (filePath, fileAttr) -> isValidFile(filePath, fileAttr))
.forEach(f -> {
if (f.toString().endsWith("-androidTest.apk")) {
if(!isAPKFileCreated[1]) {
testApkFiles.add(f);
}
} else if (!isAPKFileCreated[0]) {
appApkFiles.add(f);
}
});
}
debugApkPath = findMostRecentPath(appApkFiles);
testApkPath = findMostRecentPath(testApkFiles);

Expand All @@ -188,7 +244,10 @@ public Map<String, Path> locateApks(boolean ignoreTestPath) throws IOException {
}

private boolean isValidFile(Path filePath, BasicFileAttributes fileAttr) {
return fileAttr.isRegularFile() && filePath.toString().endsWith(".apk") && filePath.getFileName().toString()
return isValidAPKFile(filePath, fileAttr) && filePath.getFileName().toString()
.contains(appVariantBaseName);
}
private boolean isValidAPKFile(Path filePath, BasicFileAttributes fileAttr) {
return fileAttr.isRegularFile() && filePath.toString().endsWith(".apk") ;
}
}
Loading