Skip to content

Commit c11bee4

Browse files
committed
log files corrections
1 parent e9cecad commit c11bee4

File tree

5 files changed

+45
-77
lines changed

5 files changed

+45
-77
lines changed

mac/common-utils.sh

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ LOG_DIR="$WORKSPACE_DIR/$PROJECT_FOLDER/logs"
1414
NOW_RUN_LOG_FILE=""
1515

1616
# ===== Global Variables =====
17-
USERNAME=""
18-
ACCESS_KEY=""
19-
TEST_TYPE="" # Web / App / Both
20-
TECH_STACK="" # Java / Python / JS
2117
CX_TEST_URL="$DEFAULT_TEST_URL"
2218

2319
WEB_PLAN_FETCHED=false
@@ -26,7 +22,6 @@ TEAM_PARALLELS_MAX_ALLOWED_WEB=0
2622
TEAM_PARALLELS_MAX_ALLOWED_MOBILE=0
2723

2824
# App specific globals
29-
APP_URL=""
3025
APP_PLATFORM="" # ios | android | all
3126

3227

@@ -133,8 +128,6 @@ upload_sample_app() {
133128
}
134129

135130
upload_custom_app() {
136-
local -n app_url=$1
137-
local -n platform=$2
138131
local app_platform=""
139132
local file_path
140133
file_path=$(osascript -e 'choose file with prompt "Select your .apk or .ipa file:" of type {"apk", "ipa"}' 2>/dev/null)
@@ -146,10 +139,8 @@ upload_custom_app() {
146139

147140
# Determine platform from file extension
148141
if [[ "$file_path" == *.ipa ]]; then
149-
platform="ios"
150142
app_platform="ios"
151143
elif [[ "$file_path" == *.apk ]]; then
152-
platform="android"
153144
app_platform="android"
154145
else
155146
log_msg_to "❌ Invalid file type. Must be .apk or .ipa"
@@ -162,6 +153,7 @@ upload_custom_app() {
162153
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
163154
-F "file=@$file_path")
164155

156+
local app_url
165157
app_url=$(echo "$upload_response" | grep -o '"app_url":"[^"]*' | cut -d'"' -f4)
166158
if [ -z "$app_url" ]; then
167159
log_msg_to "❌ Failed to upload app"
@@ -182,16 +174,18 @@ generate_web_platforms() {
182174
local max_total_parallels=$1
183175
local platformsListContentFormat=$2
184176
local platform="web"
177+
local platformsList=""
185178
export NOW_PLATFORM="$platform"
186-
local platformsList=$(pick_terminal_devices "$NOW_PLATFORM" $max_total_parallels "$platformsListContentFormat")
179+
platformsList=$(pick_terminal_devices "$NOW_PLATFORM" "$max_total_parallels" "$platformsListContentFormat")
187180
echo "$platformsList"
188181
}
189182

190183
generate_mobile_platforms() {
191184
local max_total_parallels=$1
192185
local platformsListContentFormat=$2
193186
local app_platform="$APP_PLATFORM"
194-
local platformsList=$(pick_terminal_devices "$app_platform" $max_total_parallels, "$platformsListContentFormat")
187+
local platformsList=""
188+
platformsList=$(pick_terminal_devices "$app_platform" "$max_total_parallels", "$platformsListContentFormat")
195189
echo "$platformsList"
196190
}
197191

@@ -317,7 +311,8 @@ identify_run_status_nodejs() {
317311

318312
local log_file=$1
319313
log_info "Identifying run status"
320-
local line=$(grep -m 1 -E "Spec Files:.*passed.*total" < "$log_file")
314+
local line=""
315+
line=$(grep -m 1 -E "Spec Files:.*passed.*total" < "$log_file")
321316
# If not found, fail
322317
if [[ -z "$line" ]]; then
323318
log_warn "❌ No test summary line found."
@@ -334,8 +329,6 @@ identify_run_status_nodejs() {
334329
log_error "❌ Error: No tests passed"
335330
return 1
336331
fi
337-
338-
return 1
339332
}
340333

341334

@@ -349,8 +342,6 @@ identify_run_status_python() {
349342

350343
echo "✅ Total Passed: $passed_sum"
351344

352-
local completed_test_count=passed_sum+warning_sum
353-
354345
# If not found, fail
355346
if [[ -z "$passed_sum" ]]; then
356347
log_warn "❌ No test summary line found."
@@ -365,8 +356,6 @@ identify_run_status_python() {
365356
log_error "❌ Error: No tests completed"
366357
return 1
367358
fi
368-
369-
return 1
370359
}
371360

372361
clear_old_logs() {

mac/env-prequisite-checks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ parse_proxy() {
1717
p="${p#http://}"
1818
p="${p#https://}"
1919
# strip credentials if any user:pass@
20-
p="${p#*[@]}"
20+
p="${p#*@}"
2121

2222
# extract host and port
2323
export PROXY_HOST="${p%%:*}"

mac/env-setup-run.sh

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Common setup function for both web and mobile
1+
#!/usr/bin/env bash
2+
# shellcheck shell=bash
3+
24
setup_environment() {
35
local setup_type=$1 # "web" or "mobile"
46
local tech_stack=$2
57
local max_parallels
6-
local setup_function
78

89
log_section "📦 Project Setup"
910

@@ -19,8 +20,6 @@ setup_environment() {
1920
log_msg_to "Starting ${setup_type} setup for $TECH_STACK" "$NOW_RUN_LOG_FILE"
2021

2122
local local_flag=false
22-
local attempt=1
23-
local run_status=1
2423

2524
# Calculate parallels
2625
local total_parallels
@@ -36,19 +35,19 @@ setup_environment() {
3635
java)
3736
"setup_${setup_type}_java" "$local_flag" "$parallels_per_platform" "$NOW_RUN_LOG_FILE"
3837
log_section "✅ Results"
39-
run_status=$(identify_run_status_java "$NOW_RUN_LOG_FILE")
38+
identify_run_status_java "$NOW_RUN_LOG_FILE"
4039
check_return_value $? "$NOW_RUN_LOG_FILE" "${setup_type} setup succeeded." "${setup_type} setup failed. Check $log_file for details"
4140
;;
4241
python)
4342
"setup_${setup_type}_python" "$local_flag" "$parallels_per_platform" "$NOW_RUN_LOG_FILE"
4443
log_section "✅ Results"
45-
run_status=$(identify_run_status_python "$NOW_RUN_LOG_FILE")
44+
identify_run_status_python "$NOW_RUN_LOG_FILE"
4645
check_return_value $? "$NOW_RUN_LOG_FILE" "${setup_type} setup succeeded." "${setup_type} setup failed. Check $log_file for details"
4746
;;
4847
nodejs)
4948
"setup_${setup_type}_nodejs" "$local_flag" "$parallels_per_platform" "$NOW_RUN_LOG_FILE"
5049
log_section "✅ Results"
51-
run_status=$(identify_run_status_nodejs "$NOW_RUN_LOG_FILE")
50+
identify_run_status_nodejs "$NOW_RUN_LOG_FILE"
5251
check_return_value $? "$NOW_RUN_LOG_FILE" "${setup_type} setup succeeded." "${setup_type} setup failed. Check $log_file for details"
5352
;;
5453
*)
@@ -67,7 +66,7 @@ setup_web_java() {
6766

6867
mkdir -p "$WORKSPACE_DIR/$PROJECT_FOLDER"
6968

70-
clone_repository $REPO $TARGET_DIR
69+
clone_repository "$REPO" "$TARGET_DIR"
7170

7271
cd "$TARGET_DIR"|| return 1
7372

@@ -101,7 +100,7 @@ EOF
101100
# === 6️⃣ Build and Run ===
102101
log_msg_to "⚙️ Running 'mvn install -DskipTests'"
103102
log_info "Installing dependencies"
104-
mvn install -DskipTests >> $NOW_RUN_LOG_FILE 2>&1 || return 1
103+
mvn install -DskipTests >> "$NOW_RUN_LOG_FILE" 2>&1 || return 1
105104
log_success "Dependencies installed"
106105

107106

@@ -115,13 +114,13 @@ EOF
115114

116115
print_tests_running_log_section "mvn test -P sample-test"
117116
log_msg_to "🚀 Running 'mvn test -P sample-test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
118-
mvn test -P sample-test >> $NOW_RUN_LOG_FILE 2>&1 &
117+
mvn test -P sample-test >> "$NOW_RUN_LOG_FILE" 2>&1 &
119118
cmd_pid=$!|| return 1
120119

121120
show_spinner "$cmd_pid"
122121
wait "$cmd_pid"
123122

124-
cd "$WORKSPACE_DIR/$PROJECT_FOLDER"
123+
cd "$WORKSPACE_DIR/$PROJECT_FOLDER" || return 1
125124
return 0
126125
}
127126

@@ -138,9 +137,9 @@ setup_app_java() {
138137
clone_repository $REPO $TARGET_DIR
139138

140139
if [[ "$APP_PLATFORM" == "all" || "$APP_PLATFORM" == "android" ]]; then
141-
cd android/testng-examples
140+
cd "android/testng-examples" || return 1
142141
else
143-
cd ios/testng-examples
142+
cd ios/testng-examples || return 1
144143
fi
145144

146145

@@ -162,7 +161,7 @@ EOF
162161
# Run Maven install first
163162
log_msg_to "⚙️ Running 'mvn clean'"
164163
log_info "Installing dependencies"
165-
if ! mvn clean >> $NOW_RUN_LOG_FILE 2>&1; then
164+
if ! mvn clean >> "$NOW_RUN_LOG_FILE" 2>&1; then
166165
log_msg_to "❌ 'mvn clean' FAILED. See $log_file for details."
167166
return 1 # Fail the function if clean fails
168167
fi
@@ -177,7 +176,7 @@ EOF
177176

178177
log_msg_to "🚀 Running 'mvn test -P sample-test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
179178
print_tests_running_log_section "mvn test -P sample-test"
180-
mvn test -P sample-test >> $NOW_RUN_LOG_FILE 2>&1 &
179+
mvn test -P sample-test >> "$NOW_RUN_LOG_FILE" 2>&1 &
181180
cmd_pid=$!|| return 1
182181

183182
show_spinner "$cmd_pid"
@@ -195,11 +194,11 @@ setup_web_python() {
195194
REPO="browserstack-examples-pytest"
196195
TARGET_DIR="$WORKSPACE_DIR/$PROJECT_FOLDER/$REPO"
197196

198-
clone_repository $REPO $TARGET_DIR
197+
clone_repository "$REPO" "$TARGET_DIR"
199198

200199
detect_setup_python_env
201200

202-
pip3 install -r requirements.txt >> $NOW_RUN_LOG_FILE 2>&1
201+
pip3 install -r requirements.txt >> "$NOW_RUN_LOG_FILE" 2>&1
203202
log_success "Dependencies installed"
204203

205204
# Update YAML at root level (browserstack.yml)
@@ -301,7 +300,7 @@ EOF
301300
)
302301

303302
deactivate
304-
cd "$WORKSPACE_DIR/$PROJECT_FOLDER"
303+
cd "$WORKSPACE_DIR/$PROJECT_FOLDER" || return 1
305304
return 0
306305
}
307306

@@ -352,7 +351,7 @@ setup_web_nodejs() {
352351
show_spinner "$cmd_pid"
353352
wait "$cmd_pid"
354353

355-
cd "$WORKSPACE_DIR/$PROJECT_FOLDER"
354+
cd "$WORKSPACE_DIR/$PROJECT_FOLDER" || return 1
356355
return 0
357356
}
358357

@@ -397,7 +396,7 @@ setup_app_nodejs() {
397396
# === 8️⃣ Run Tests ===
398397
log_msg_to "🚀 Running 'npm run test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
399398
print_tests_running_log_section "npm run test"
400-
npm run test >> $NOW_RUN_LOG_FILE 2>&1 || return 1 &
399+
npm run test >> "$NOW_RUN_LOG_FILE" 2>&1 || return 1 &
401400
cmd_pid=$!|| return 1
402401

403402
show_spinner "$cmd_pid"
@@ -406,7 +405,7 @@ setup_app_nodejs() {
406405
# === 9️⃣ Wrap Up ===
407406
log_msg_to "✅ Mobile JS setup and test execution completed successfully."
408407

409-
cd "$WORKSPACE_DIR/$PROJECT_FOLDER"
408+
cd "$WORKSPACE_DIR/$PROJECT_FOLDER" || return 1
410409
return 0
411410
}
412411

@@ -415,10 +414,10 @@ clone_repository() {
415414
install_folder=$2
416415
test_folder=$3
417416

418-
rm -rf $install_folder
417+
rm -rf "$install_folder"
419418
log_msg_to "📦 Cloning repo $repo_git into $install_folder"
420419
log_info "Cloning repository: $repo_git"
421-
git clone https://github.com/BrowserStackCE/$repo_git.git "$install_folder" >> $NOW_RUN_LOG_FILE 2>&1 || return 1
420+
git clone https://github.com/BrowserStackCE/$repo_git.git "$install_folder" >> "$NOW_RUN_LOG_FILE" 2>&1 || return 1
422421
log_msg_to "✅ Cloned repository: $repo_git into $install_folder"
423422
cd "$install_folder/$test_folder" || return 1
424423
}
@@ -432,36 +431,17 @@ run_setup_wrapper() {
432431
case "$test_type" in
433432
Web)
434433
if [ "$WEB_PLAN_FETCHED" == true ]; then
435-
run_setup $test_type $tech_stack
434+
run_setup "$test_type" "$tech_stack"
436435
else
437436
log_msg_to "⚠️ Skipping Web setup — Web plan not fetched"
438437
fi
439438
;;
440439
App)
441440
if [ "$MOBILE_PLAN_FETCHED" == true ]; then
442-
run_setup $test_type $tech_stack
443-
else
444-
log_msg_to "⚠️ Skipping Mobile setup — Mobile plan not fetched"
445-
fi
446-
;;
447-
Both)
448-
local ran_any=false
449-
if [ "$WEB_PLAN_FETCHED" == true ]; then
450-
run_setup $test_type $tech_stack
451-
ran_any=true
452-
else
453-
log_msg_to "⚠️ Skipping Web setup — Web plan not fetched"
454-
fi
455-
if [ "$MOBILE_PLAN_FETCHED" == true ]; then
456-
run_setup $test_type $tech_stack
457-
ran_any=true
441+
run_setup "$test_type" "$tech_stack"
458442
else
459443
log_msg_to "⚠️ Skipping Mobile setup — Mobile plan not fetched"
460444
fi
461-
if [ "$ran_any" == false ]; then
462-
log_msg_to "❌ Both Web and Mobile setup were skipped. Exiting."
463-
exit 1
464-
fi
465445
;;
466446
*)
467447
log_msg_to "❌ Invalid TEST_TYPE: $TEST_TYPE"
@@ -531,6 +511,7 @@ detect_setup_python_env() {
531511
exit 1
532512
}
533513

514+
# shellcheck source=/dev/null
534515
source .venv/bin/activate
535516
log_success "Virtual environment created and activated."
536517
}

mac/logging-utils.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ BOLD="\033[1m"
88
RESET="\033[0m"
99
GREEN="\033[32m"
1010
YELLOW="\033[33m"
11-
BLUE="\033[34m"
1211
CYAN="\033[36m"
1312
RED="\033[31m"
14-
GRAY="\033[90m"
1513
LIGHT_GRAY='\033[0;37m'
1614

1715
# ==============================================

0 commit comments

Comments
 (0)