Skip to content

Commit

Permalink
fixed BROWSERSTACK_LOCAL_IDENTIFIER issue for native apps
Browse files Browse the repository at this point in the history
  • Loading branch information
anandbagmar committed Mar 6, 2024
1 parent e8d1c01 commit b3498f1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/znsio/teswiz/entities/TEST_CONTEXT.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ public class TEST_CONTEXT {
public static final String CURRENT_USER_PERSONA_DETAILS = "currentUserPersonaDetails";
public static final String UPDATED_BASE_URL_FOR_WEB = "updatedBaseUrlForWeb";
public static final String UPDATED_BROWSER_CONFIG_FILE_FOR_THIS_TEST = "updatedBrowserConfigFileForThisTest";
public static final String BROWSERSTACK_LOCAL_IDENTIFIER = "browserStackLocalIdentifier";
}
16 changes: 7 additions & 9 deletions src/main/java/com/znsio/teswiz/runner/BrowserStackSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class BrowserStackSetup {
private static final Logger LOGGER = LogManager.getLogger(BrowserStackSetup.class.getName());
private static final String DEVICE = "device";
private static Local bsLocal;
private static final String BROWSERSTACK_LOCAL_IDENTIFIER = Randomizer.randomize(10);

private BrowserStackSetup() {
LOGGER.debug("BrowserStackSetup - private constructor");
Expand Down Expand Up @@ -74,14 +75,12 @@ private static void addAppOrBrowserNameToBrowserStackCapablities(String deviceLa

private static void setupLocalTesting(String authenticationKey, Map loadedPlatformCapability) {
if(Setup.getBooleanValueFromConfigs(Setup.CLOUD_USE_LOCAL_TESTING)) {
String browserStackLocalIdentifier = Runner.getTestExecutionContext(Thread.currentThread().getId()).getTestStateAsString(TEST_CONTEXT.BROWSERSTACK_LOCAL_IDENTIFIER);
LOGGER.info(String.format(
"CLOUD_USE_LOCAL_TESTING=true. Setting up BrowserStackLocal testing using " + "identified: '%s'",
browserStackLocalIdentifier));
startBrowserStackLocal(authenticationKey, browserStackLocalIdentifier);
BROWSERSTACK_LOCAL_IDENTIFIER));
startBrowserStackLocal(authenticationKey, BROWSERSTACK_LOCAL_IDENTIFIER);
loadedPlatformCapability.put("browserstack.local", "true");
loadedPlatformCapability.put("browserstack.localIdentifier",
browserStackLocalIdentifier);
loadedPlatformCapability.put("browserstack.localIdentifier", BROWSERSTACK_LOCAL_IDENTIFIER);
}
}

Expand All @@ -94,7 +93,6 @@ static MutableCapabilities updateBrowserStackCapabilities(MutableCapabilities ca
Map<String, Map> loadedCapabilityFile = JsonFile.loadJsonFile(capabilityFile);
Map loadedPlatformCapability = loadedCapabilityFile.get(platformName);

String browserStackLocalIdentifier = Runner.getTestExecutionContext(Thread.currentThread().getId()).getTestStateAsString(TEST_CONTEXT.BROWSERSTACK_LOCAL_IDENTIFIER);
String subsetOfLogDir = Setup.getFromConfigs(Setup.LOG_DIR).replace("/", "")
.replace("\\", "");

Expand All @@ -111,11 +109,11 @@ static MutableCapabilities updateBrowserStackCapabilities(MutableCapabilities ca
if(Setup.getBooleanValueFromConfigs(Setup.CLOUD_USE_LOCAL_TESTING)) {
LOGGER.info(String.format(
"CLOUD_USE_LOCAL_TESTING=true. Setting up BrowserStackLocal testing using " + "identified: '%s'",
browserStackLocalIdentifier));
startBrowserStackLocal(authenticationKey, browserStackLocalIdentifier);
BROWSERSTACK_LOCAL_IDENTIFIER));
startBrowserStackLocal(authenticationKey, BROWSERSTACK_LOCAL_IDENTIFIER);
browserstackOptions.put(ACCEPT_INSECURE_CERTS, "true");
browserstackOptions.put("local", "true");
browserstackOptions.put("localIdentifier", browserStackLocalIdentifier);
browserstackOptions.put("localIdentifier", BROWSERSTACK_LOCAL_IDENTIFIER);
}
capabilities.setCapability("bstack:options", browserstackOptions);

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/znsio/teswiz/steps/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.znsio.teswiz.runner.Drivers;
import com.znsio.teswiz.runner.Runner;
import com.znsio.teswiz.runner.UserPersonaDetails;
import com.znsio.teswiz.tools.Randomizer;
import com.znsio.teswiz.tools.ReportPortalLogger;
import com.znsio.teswiz.tools.ScreenShotManager;
import io.cucumber.java.Scenario;
Expand All @@ -23,7 +22,6 @@ public class Hooks {
private static final Logger LOGGER = LogManager.getLogger(Hooks.class.getName());
private static final List<String> excludeLoggingSystemProperties = Arrays.asList("java.class.path", "java.library.path");
private static final List<String> excludeLoggingEnvVariables = Arrays.asList("KEY", "PASSWORD");
private static final String browserStackLocalIdentifier = Randomizer.randomize(10);

public void beforeScenario(Scenario scenario) {
long threadId = Thread.currentThread().getId();
Expand All @@ -37,7 +35,6 @@ public void beforeScenario(Scenario scenario) {
}
testExecutionContext.addTestState(TEST_CONTEXT.CURRENT_USER_PERSONA_DETAILS,
new UserPersonaDetails());
testExecutionContext.addTestState(TEST_CONTEXT.BROWSERSTACK_LOCAL_IDENTIFIER, browserStackLocalIdentifier);
SoftAssertions softly = new SoftAssertions();
testExecutionContext.addTestState(TEST_CONTEXT.SOFT_ASSERTIONS, softly);
addEnvironmentVariablesToReportPortal();
Expand Down

0 comments on commit b3498f1

Please sign in to comment.