Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ System.out.println(bsLocal.isRunning());
bsLocal.stop();
```

### Disabling Error Logging
While creating the instance of Local, pass false to debugOutput.
```
// creates an instance of Local without debug output
Local bsLocal = new Local(false);
```

## Arguments

Apart from the key, all other BrowserStack Local modifiers are optional. For the full list of modifiers, refer [BrowserStack Local modifiers](https://www.browserstack.com/local-testing#modifiers). For examples, refer below -
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/browserstack/local/Local.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class Local {
private final Map<String, String> parameters;
private final Map<String, String> avoidValueParameters;

private static boolean debugOutput = true;

public Local() {
avoidValueParameters = new HashMap<String, String>();
avoidValueParameters.put("v", "-vvv");
Expand All @@ -45,6 +47,11 @@ public Local() {
parameters.put("proxyPass", "-proxyPass");
}

public Local(boolean debugOutput) {
this();
this.debugOutput = debugOutput;
}

/**
* Starts Local instance with options
*
Expand All @@ -56,7 +63,7 @@ public void start(Map<String, String> options) throws Exception {
if (options.get("binarypath") != null) {
binaryPath = options.get("binarypath");
} else {
LocalBinary lb = new LocalBinary();
LocalBinary lb = new LocalBinary(debugOutput);
binaryPath = lb.getBinaryPath();
}

Expand Down Expand Up @@ -109,7 +116,7 @@ public void stop(Map<String, String> options) throws Exception {
if (options.get("binarypath") != null) {
binaryPath = options.get("binarypath");
} else {
LocalBinary lb = new LocalBinary();
LocalBinary lb = new LocalBinary(debugOutput);
binaryPath = lb.getBinaryPath();
}
makeCommand(options, "stop");
Expand Down
67 changes: 57 additions & 10 deletions src/main/java/com/browserstack/local/LocalBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class LocalBinary {

private static final String BIN_URL = "https://bstack-local-prod.s3.amazonaws.com/";
private static boolean debugOutput = true;

private String httpPath;

Expand All @@ -25,11 +26,27 @@ class LocalBinary {
};

LocalBinary() throws LocalException {
initialize();
getBinary();
checkBinary();
try {
initialize();
getBinary();
checkBinary();
} catch (Exception ex) {
LocalException err = new LocalException("Error trying to download BrowserStackLocal binary");
if (debugOutput) {
System.err.println(err.toString());
System.err.println(ex.toString());
err.printStackTrace();
}
throw err;
}
}

LocalBinary(boolean debugOutput) throws LocalException {
this();
this.debugOutput = debugOutput;
}


private void initialize() throws LocalException {
String osname = System.getProperty("os.name").toLowerCase();
isOSWindows = osname.contains("windows");
Expand All @@ -51,7 +68,12 @@ private void initialize() throws LocalException {
binFileName = "BrowserStackLocal-linux-ia32";
}
} else {
throw new LocalException("Failed to detect OS type");
LocalException err = new LocalException("Failed to detect OS type");
if (debugOutput) {
System.err.println(err.toString());
err.printStackTrace();
}
throw err;
}

httpPath = BIN_URL + binFileName;
Expand Down Expand Up @@ -81,7 +103,12 @@ private void checkBinary() throws LocalException{
}
getBinary();
if(!validateBinary()){
throw new LocalException("BrowserStackLocal binary is corrupt");
LocalException err = new LocalException("BrowserStackLocal binary is corrupt");
if (debugOutput) {
System.err.println(err.toString());
err.printStackTrace();
}
throw err;
}
}
}
Expand All @@ -104,10 +131,20 @@ private boolean validateBinary() throws LocalException{

return validBinary;
}catch(IOException ex){
throw new LocalException(ex.toString());
LocalException err = new LocalException(ex.toString());
if (debugOutput) {
System.err.println(err.toString());
err.printStackTrace();
}
throw err;
}
catch(InterruptedException ex){
throw new LocalException(ex.toString());
LocalException err = new LocalException(ex.toString());
if (debugOutput) {
System.err.println(err.toString());
err.printStackTrace();
}
throw err;
}
}

Expand All @@ -133,8 +170,12 @@ private String getAvailableDirectory() throws LocalException {
else
i++;
}

throw new LocalException("Error trying to download BrowserStackLocal binary");
LocalException err = new LocalException("Error trying to download BrowserStackLocal binary");
if (debugOutput) {
System.err.println(err.toString());
err.printStackTrace();
}
throw err;
}

private boolean makePath(String path) {
Expand Down Expand Up @@ -163,7 +204,13 @@ private void downloadBinary(String destParentDir) throws LocalException {

changePermissions(binaryPath);
} catch (Exception e) {
throw new LocalException("Error trying to download BrowserStackLocal binary");
LocalException err = new LocalException("Error trying to download BrowserStackLocal binary");
if (debugOutput) {
System.err.println(err.toString());
System.err.println(e.toString());
err.printStackTrace();
}
throw err;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/browserstack/local/LocalException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.browserstack.local;

class LocalException extends Exception {
public class LocalException extends Exception {

LocalException(String message) {
super(message);
Expand Down