Skip to content

Commit e104bcc

Browse files
committed
proxy checks done
1 parent 49099f5 commit e104bcc

File tree

2 files changed

+65
-16
lines changed

2 files changed

+65
-16
lines changed

mac.sh

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,15 @@ APP_URL=""
2626
APP_PLATFORM="" # ios | android | all
2727

2828

29-
# ===== Error Patterns =====
30-
WEB_SETUP_ERRORS=("")
31-
WEB_LOCAL_ERRORS=("")
32-
33-
MOBILE_SETUP_ERRORS=("")
34-
MOBILE_LOCAL_ERRORS=("")
35-
3629
# ===== Example Platform Templates (replace with your full lists if available) =====
3730
WEB_PLATFORM_TEMPLATES=(
3831
"Windows|10|Chrome"
3932
"Windows|10|Firefox"
4033
"Windows|11|Edge"
4134
"Windows|11|Chrome"
4235
"Windows|8|Chrome"
43-
#"OS X|Monterey|Safari"
4436
"OS X|Monterey|Chrome"
4537
"OS X|Ventura|Chrome"
46-
#"OS X|Big Sur|Safari"
4738
"OS X|Catalina|Firefox"
4839
)
4940

@@ -193,7 +184,6 @@ APP_URL=""
193184
APP_PLATFORM="" # ios | android | all
194185

195186

196-
197187
# ===== Log files (runtime only; created on first write) =====
198188
# ===== Log files (per-run) =====
199189
LOG_DIR="$WORKSPACE_DIR/$PROJECT_FOLDER/logs"
@@ -826,7 +816,7 @@ setup_web_nodejs() {
826816
local_flag=true
827817
fi
828818

829-
Log local flag status
819+
#log_msg_to local flag status
830820
if [ "$local_flag" = "true" ]; then
831821
log_msg_to "✅ BrowserStack Local is ENABLED for this run." "$PRE_RUN_LOG_FILE"
832822
else
@@ -839,7 +829,7 @@ setup_web_nodejs() {
839829
export BROWSERSTACK_LOCAL=$local_flag
840830

841831
# === 8️⃣ Run Tests ===
842-
log_msg_to "🚀 Running 'npm run test'" "$GLOBAL" "$WEB_LOG_FILE"
832+
log_msg_to "🚀 Running 'npm run test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/" "$WEB_LOG_FILE"
843833
npm run test >> "$WEB_LOG_FILE" 2>&1 || true
844834

845835
# === 9️⃣ Wrap Up ===
@@ -1026,13 +1016,13 @@ PYEOF
10261016

10271017
# Log local flag status
10281018
if [ "$local_flag" = "true" ]; then
1029-
log_msg_to "⚠️ BrowserStack Local is ENABLED for this run." "$PRE_RUN_LOG_FILE"
1019+
log_msg_to "⚠️ BrowserStack Local is ENABLED for this run."
10301020
else
1031-
log_msg_to "⚠️ BrowserStack Local is DISABLED for this run." "$PRE_RUN_LOG_FILE"
1021+
log_msg_to "⚠️ BrowserStack Local is DISABLED for this run."
10321022
fi
10331023

10341024
# Run pytest with BrowserStack SDK from the chosen platform directory
1035-
log_msg_to "🚀 Running 'cd $run_dir && browserstack-sdk pytest -s bstack_sample.py'" "$PRE_RUN_LOG_FILE"
1025+
log_msg_to "🚀 Running 'cd $run_dir && browserstack-sdk pytest -s bstack_sample.py'"
10361026
(
10371027
cd "$run_dir" && browserstack-sdk pytest -s bstack_sample.py >> "$log_file" 2>&1 || true
10381028
)
@@ -1294,7 +1284,10 @@ fetch_plan_details
12941284

12951285
# Plan summary in pre-run log
12961286
log_msg_to "Plan summary: WEB_PLAN_FETCHED=$WEB_PLAN_FETCHED (team max=$TEAM_PARALLELS_MAX_ALLOWED_WEB), MOBILE_PLAN_FETCHED=$MOBILE_PLAN_FETCHED (team max=$TEAM_PARALLELS_MAX_ALLOWED_MOBILE)" "$GLOBAL"
1297-
1287+
log_msg_to "Checking proxy in environment" "$GLOBAL"
1288+
chmod +x proxy-check.sh
1289+
./proxy-check.sh
1290+
log_msg_to "Starting setup run..." "$GLOBAL"
12981291
run_setup
12991292

13001293
log_msg_to "Setup run finished." "$GLOBAL"

proxy-check.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env sh
2+
3+
# URL to test
4+
TEST_URL="https://www.browserstack.com/automate/browsers.json"
5+
6+
# Detect proxy from env (case insensitive)
7+
PROXY="${http_proxy:-${HTTP_PROXY:-${https_proxy:-${HTTPS_PROXY}}}}"
8+
9+
# Reset output variables
10+
export PROXY_HOST=""
11+
export PROXY_PORT=""
12+
13+
# Function: parse proxy url to host + port
14+
parse_proxy() {
15+
p="$1"
16+
# strip protocol e.g. http://, https://
17+
p="${p#http://}"
18+
p="${p#https://}"
19+
# strip credentials if any user:pass@
20+
p="${p#*[@]}"
21+
22+
# extract host and port
23+
export PROXY_HOST="${p%%:*}"
24+
export PROXY_PORT="${p##*:}"
25+
}
26+
27+
base64_encoded_creds=$(printf "%s" $BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY | base64 | tr -d '\n')
28+
29+
30+
# If no proxy configured, exit early
31+
if [ -z "$PROXY" ]; then
32+
echo "No proxy found in environment. Clearing proxy host and port variables."
33+
export PROXY_HOST=""
34+
export PROXY_PORT=""
35+
return 0 2>/dev/null || exit 0
36+
fi
37+
38+
echo "Proxy detected: $PROXY"
39+
parse_proxy "$PROXY"
40+
41+
echo "Testing reachability via proxy..."
42+
43+
44+
STATUS_CODE=$(curl -sS -o /dev/null -H "Authorization: Basic ${base64_encoded_creds}" -w "%{http_code}" --proxy "$PROXY" "$TEST_URL" 2>/dev/null)
45+
46+
if [ "${STATUS_CODE#2}" != "$STATUS_CODE" ]; then
47+
echo "✅ Reachable. HTTP $STATUS_CODE"
48+
echo "Exporting PROXY_HOST=$PROXY_HOST"
49+
echo "Exporting PROXY_PORT=$PROXY_PORT"
50+
export PROXY_HOST
51+
export PROXY_PORT
52+
else
53+
echo "❌ Not reachable (HTTP $STATUS_CODE). Clearing variables."
54+
export PROXY_HOST=""
55+
export PROXY_PORT=""
56+
fi

0 commit comments

Comments
 (0)