Last active
February 8, 2022 17:05
-
-
Save mattonem/b7497307d43590d308a725c662fadda9 to your computer and use it in GitHub Desktop.
LocalTesting Singleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
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
LocalTestingSingleton.getInstance()