Skip to content

Commit 2832c09

Browse files
authored
stability fixes (#26)
* stability fixes * stability fixes - do not erase username and access key * stability fixes - do not remove one time setting vars
1 parent 5147086 commit 2832c09

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

mac/common-utils.sh

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ is_private_ip() {
301301
}
302302

303303
is_domain_private() {
304+
local is_cx_domain_private=100
304305
domain=${CX_TEST_URL#*://} # remove protocol
305306
domain=${domain%%/*} # remove everything after first "/"
306307
log_msg_to "Website domain: $domain"
@@ -466,6 +467,8 @@ detect_os() {
466467
}
467468

468469
print_env_vars() {
470+
local test_type=$1
471+
local tech_stack=$2
469472
log_section "✅ Environment Variables"
470473
log_info "BrowserStack Username: $BROWSERSTACK_USERNAME"
471474
log_info "BrowserStack Project Name: $BROWSERSTACK_PROJECT_NAME"
@@ -490,23 +493,24 @@ print_env_vars() {
490493

491494
clean_env_vars() {
492495
log_section "✅ Clean Environment Variables"
493-
export BROWSERSTACK_USERNAME=""
494-
export BROWSERSTACK_ACCESS_KEY=""
495-
export BROWSERSTACK_APP=""
496-
export BSTACK_CAPS_JSON=""
497-
export BSTACK_PLATFORMS=""
498-
export CX_TEST_URL=""
499-
export NOW_WEB_DOMAIN=""
500-
export BROWSERSTACK_PROJECT_NAME=""
501-
export BROWSERSTACK_BUILD_NAME=""
502-
export BROWSERSTACK_LOCAL_CUSTOM=""
503-
export BROWSERSTACK_LOCAL=""
504-
export BSTACK_PARALLELS=""
505-
export APP_PLATFORM=""
506-
export NOW_PLATFORM=""
507-
export BSTACK_CAPS_JSON=""
508-
export BSTACK_PLATFORMS=""
509-
export BROWSERSTACK_APP
496+
497+
# list of variables to unset
498+
vars=(
499+
BSTACK_CAPS_JSON
500+
BSTACK_PLATFORMS
501+
BROWSERSTACK_PROJECT_NAME
502+
BROWSERSTACK_BUILD_NAME
503+
BROWSERSTACK_LOCAL_CUSTOM
504+
BROWSERSTACK_LOCAL
505+
)
506+
507+
# unset each variable safely
508+
for var in "${vars[@]}"; do
509+
unset "$var"
510+
done
510511

511512
log_info "Cleared environment variables."
513+
514+
log_info "Terminating any running BrowserStack Local instances."
515+
pgrep '[B]rowserStack' | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 || true
512516
}

mac/env-setup-run.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ EOF
103103
mvn install -DskipTests >> "$NOW_RUN_LOG_FILE" 2>&1 || return 1
104104
log_success "Dependencies installed"
105105

106-
print_env_vars
106+
print_env_vars "$test_type" "$tech_stack"
107107

108108

109109
print_tests_running_log_section "mvn test -P sample-test"
@@ -163,7 +163,7 @@ EOF
163163
fi
164164
log_success "Dependencies installed"
165165

166-
print_env_vars
166+
print_env_vars "$test_type" "$tech_stack"
167167

168168
log_msg_to "🚀 Running 'mvn test -P sample-test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
169169
print_tests_running_log_section "mvn test -P sample-test"
@@ -217,7 +217,7 @@ EOF
217217

218218
report_bstack_local_status "$local_flag"
219219

220-
print_env_vars
220+
print_env_vars "$test_type" "$tech_stack"
221221

222222
print_tests_running_log_section "browserstack-sdk pytest -s tests/*.py"
223223
log_msg_to "🚀 Running 'browserstack-sdk pytest -s tests/*.py'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
@@ -271,7 +271,7 @@ EOF
271271
export BROWSERSTACK_BUILD_NAME="now-$NOW_OS-app-python-pytest"
272272
export BROWSERSTACK_PROJECT_NAME="now-$NOW_OS-app"
273273

274-
print_env_vars
274+
print_env_vars "$test_type" "$tech_stack"
275275

276276
print_tests_running_log_section "cd $run_dir && browserstack-sdk pytest -s bstack-sample.py"
277277
# Run pytest with BrowserStack SDK from the chosen platform directory
@@ -311,7 +311,8 @@ setup_web_nodejs() {
311311
export BSTACK_PARALLELS=$parallels
312312

313313
if is_domain_private; then
314-
local_flag=true
314+
log_msg_to "Entered in Is domain private condition"
315+
local_flag="true"
315316
fi
316317

317318
export BROWSERSTACK_LOCAL_CUSTOM=$local_flag
@@ -320,7 +321,7 @@ setup_web_nodejs() {
320321

321322
report_bstack_local_status "$local_flag"
322323

323-
print_env_vars
324+
print_env_vars "$test_type" "$tech_stack"
324325

325326
# === 8️⃣ Run Tests ===
326327
log_msg_to "🚀 Running 'npm run test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
@@ -368,7 +369,7 @@ setup_app_nodejs() {
368369
export BROWSERSTACK_BUILD_NAME="now-$NOW_OS-app-nodejs-wdio"
369370
export BROWSERSTACK_PROJECT_NAME="now-$NOW_OS-app"
370371

371-
print_env_vars
372+
print_env_vars "$test_type" "$tech_stack"
372373

373374
# === 8️⃣ Run Tests ===
374375
log_msg_to "🚀 Running 'npm run test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"

mac/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ TSTACK=$3 # Tech Stack from env (for silent mode)
3030
log_section "🧭 Setup Summary – BrowserStack NOW"
3131
log_info "Timestamp: $(date '+%Y-%m-%d %H:%M:%S')"
3232

33+
trap clean_env_vars EXIT # runs cleanup on script exit
3334
clean_env_vars
3435
detect_os
3536
setup_workspace

0 commit comments

Comments
 (0)