Skip to content

Instantly share code, notes, and snippets.

@mattonem
Last active February 8, 2022 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattonem/b7497307d43590d308a725c662fadda9 to your computer and use it in GitHub Desktop.
Save mattonem/b7497307d43590d308a725c662fadda9 to your computer and use it in GitHub Desktop.
LocalTesting Singleton
import com.browserstack.local.Local;
import java.util.Random;
import java.nio.charset.Charset;
public class LocalTestingSingleton {
private static Local bsLocal;
public static String localID;
private LocalTestingSingleton(){}
public static LocalTestingSingleton getInstance(){
if(bsLocal == null){
byte[] array = new byte[7];
new Random().nextBytes(array);
String localID = new String(array, Charset.forName("UTF-8"));
bsLocal = new Local();
HashMap<String, String> bsLocalArgs = new HashMap<String, String>();
bsLocalArgs.put("key", "<browserstack-accesskey>");
bsLocalArgs.put("localIdentifier", localID);
# starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs);
}
return bsLocal;
}
}
@mattonem
Copy link
Author

mattonem commented Feb 8, 2022

LocalTestingSingleton.getInstance()

@mattonem
Copy link
Author

mattonem commented Feb 8, 2022

LocalTestingSingleton .localID to get the local identifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment