22# shellcheck shell=bash
33
44setup_environment () {
5- local setup_type=$1
5+ local setup_type=$1
66 local tech_stack=$2
77 local max_parallels
88
@@ -51,7 +51,7 @@ setup_environment() {
5151 check_return_value $? " $NOW_RUN_LOG_FILE " " ${setup_type} setup succeeded." " ❌ ${setup_type} setup failed. Check $log_file for details"
5252 ;;
5353 * )
54- log_warn " Unknown TECH_STACK: $TECH_STACK " " $NOW_RUN_LOG_FILE "
54+ log_warn " Unknown TECH_STACK: $tech_stack " " $NOW_RUN_LOG_FILE "
5555 return 1
5656 ;;
5757 esac
@@ -65,7 +65,7 @@ setup_web_java() {
6565 TARGET_DIR=" $WORKSPACE_DIR /$PROJECT_FOLDER /$REPO "
6666
6767 mkdir -p " $WORKSPACE_DIR /$PROJECT_FOLDER "
68-
68+
6969 clone_repository " $REPO " " $TARGET_DIR "
7070
7171 cd " $TARGET_DIR " || return 1
@@ -91,19 +91,19 @@ platforms:
9191$platform_yaml
9292EOF
9393
94- export BSTACK_PARALLELS=$parallels
94+ export BSTACK_PARALLELS=$parallels
9595 export BSTACK_PLATFORMS=$platform_yaml
96- export BROWSERSTACK_LOCAL=$local_flag
96+ export BROWSERSTACK_LOCAL=$local_flag
9797 export BROWSERSTACK_BUILD_NAME=" now-$NOW_OS -web-java-testng"
98- export BROWSERSTACK_PROJECT_NAME=" now-$NOW_OS -app "
99-
98+ export BROWSERSTACK_PROJECT_NAME=" now-$NOW_OS -web "
99+
100100 # === 6️⃣ Build and Run ===
101101 log_msg_to " ⚙️ Running 'mvn install -DskipTests'"
102102 log_info " Installing dependencies"
103103 mvn install -DskipTests >> " $NOW_RUN_LOG_FILE " 2>&1 || return 1
104104 log_success " Dependencies installed"
105-
106-
105+
106+
107107 log_section " Validate Environment Variables"
108108 log_info " BrowserStack Username: $BROWSERSTACK_USERNAME "
109109 log_info " BrowserStack Build: $BROWSERSTACK_BUILD_NAME "
@@ -134,7 +134,7 @@ setup_app_java() {
134134 TARGET_DIR=" $WORKSPACE_DIR /$PROJECT_FOLDER /$REPO "
135135 local app_url=$BROWSERSTACK_APP
136136 log_msg_to " APP_PLATFORM: $APP_PLATFORM " >> " $NOW_RUN_LOG_FILE " 2>&1
137-
137+
138138 clone_repository " $REPO " " $TARGET_DIR "
139139
140140 if [[ " $APP_PLATFORM " == " all" || " $APP_PLATFORM " == " android" ]]; then
169169 return 1 # Fail the function if clean fails
170170 fi
171171 log_success " Dependencies installed"
172-
172+
173173 log_section " Validate Environment Variables"
174174 log_info " BrowserStack Username: $BROWSERSTACK_USERNAME "
175175 log_info " BrowserStack Build: $BROWSERSTACK_BUILD_NAME "
@@ -195,38 +195,40 @@ setup_web_python() {
195195 local parallels=$2
196196 local log_file=$3
197197
198- REPO=" browserstack-examples- pytest"
198+ REPO=" now- pytest-browserstack "
199199 TARGET_DIR=" $WORKSPACE_DIR /$PROJECT_FOLDER /$REPO "
200200
201- clone_repository " $REPO " " $TARGET_DIR "
201+ clone_repository " $REPO " " $TARGET_DIR " " "
202202
203203 detect_setup_python_env
204204
205205 pip3 install -r requirements.txt >> " $NOW_RUN_LOG_FILE " 2>&1
206206 log_success " Dependencies installed"
207207
208208 # Update YAML at root level (browserstack.yml)
209- export BROWSERSTACK_CONFIG_FILE=" ./src/conf/browserstack_parallel .yml"
209+ export BROWSERSTACK_CONFIG_FILE=" ./browserstack .yml"
210210 platform_yaml=$( generate_web_platforms " $TEAM_PARALLELS_MAX_ALLOWED_WEB " " yaml" )
211211 export BSTACK_PLATFORMS=$platform_yaml
212212 cat >> " $BROWSERSTACK_CONFIG_FILE " << EOF
213-
214213platforms:
215214$platform_yaml
216215EOF
217216
218217 if is_domain_private; then
219218 local_flag=true
219+ else
220+ local_flag=false
220221 fi
221222
223+
222224 export BSTACK_PARALLELS=1
223225 export BROWSERSTACK_LOCAL=$local_flag
224226 export BSTACK_PLATFORMS=$platform_yaml
225227 export BROWSERSTACK_BUILD_NAME=" now-$NOW_OS -web-python-pytest"
226228 export BROWSERSTACK_PROJECT_NAME=" now-$NOW_OS -web"
227229
228230 report_bstack_local_status " $local_flag "
229-
231+
230232 log_section " Validate Environment Variables"
231233 log_info " BrowserStack Username: $BROWSERSTACK_USERNAME "
232234 log_info " BrowserStack Build: $BROWSERSTACK_BUILD_NAME "
@@ -236,15 +238,12 @@ EOF
236238 log_info " Platforms: \n$BSTACK_PLATFORMS "
237239
238240
239- print_tests_running_log_section " browserstack-sdk pytest -s src/test/suites/ *.py --browserstack.config ./src/conf/browserstack_parallel.yml "
240- log_msg_to " 🚀 Running 'browserstack-sdk pytest -s tests/bstack-sample-test .py'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
241+ print_tests_running_log_section " browserstack-sdk pytest -s tests/ *.py"
242+ 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/"
241243 # Run tests
242- browserstack-sdk pytest -s src/test/suites/* .py --browserstack.config ./src/conf/browserstack_parallel.yml >> " $NOW_RUN_LOG_FILE " 2>&1
243- # &
244- # cmd_pid=$!|| return 1
245-
246- # show_spinner "$cmd_pid"
247- # wait "$cmd_pid"
244+ browserstack-sdk pytest -s tests/* .py >> " $NOW_RUN_LOG_FILE " 2>&1 & cmd_pid=$! || return 1
245+ show_spinner " $cmd_pid "
246+ wait " $cmd_pid "
248247
249248 cd " $WORKSPACE_DIR /$PROJECT_FOLDER " || return 1
250249 return 0
289288 export BROWSERSTACK_LOCAL=true
290289 export BROWSERSTACK_BUILD_NAME=" now-$NOW_OS -app-python-pytest"
291290 export BROWSERSTACK_PROJECT_NAME=" now-$NOW_OS -app"
292-
291+
293292 log_section " Validate Environment Variables"
294293 log_info " BrowserStack Username: $BROWSERSTACK_USERNAME "
295294 log_info " BrowserStack Build: $BROWSERSTACK_BUILD_NAME "
@@ -319,7 +318,7 @@ setup_web_nodejs() {
319318 mkdir -p " $WORKSPACE_DIR /$PROJECT_FOLDER "
320319
321320 clone_repository " $REPO " " $TARGET_DIR "
322-
321+
323322
324323 # === 2️⃣ Install Dependencies ===
325324 log_msg_to " ⚙️ Running 'npm install'"
@@ -342,14 +341,14 @@ setup_web_nodejs() {
342341 export BROWSERSTACK_PROJECT_NAME=" now-$NOW_OS -web"
343342
344343 report_bstack_local_status " $local_flag "
345-
344+
346345 log_section " Validate Environment Variables"
347346 log_info " BrowserStack Username: $BROWSERSTACK_USERNAME "
348347 log_info " BrowserStack Build: $BROWSERSTACK_BUILD_NAME "
349348 log_info " Web Application Endpoint: $CX_TEST_URL "
350349 log_info " BrowserStack Local Flag: $BROWSERSTACK_LOCAL "
351350 log_info " Parallels per platform: $BSTACK_PARALLELS "
352- log_info " Platforms: \n$BSTACK_CAPS_JSON "
351+ log_info " Platforms: \n$BSTACK_CAPS_JSON "
353352
354353 # === 8️⃣ Run Tests ===
355354 log_msg_to " 🚀 Running 'npm run test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
@@ -396,7 +395,7 @@ setup_app_nodejs() {
396395 export BROWSERSTACK_APP=$app_url
397396 export BROWSERSTACK_BUILD_NAME=" now-$NOW_OS -app-nodejs-wdio"
398397 export BROWSERSTACK_PROJECT_NAME=" now-$NOW_OS -app"
399-
398+
400399 log_section " Validate Environment Variables"
401400 log_info " BrowserStack Username: $BROWSERSTACK_USERNAME "
402401 log_info " BrowserStack Build: $BROWSERSTACK_BUILD_NAME "
@@ -422,14 +421,24 @@ setup_app_nodejs() {
422421}
423422
424423clone_repository () {
425- repo_git=$1
426- install_folder=$2
427- test_folder=$3
428-
424+ local repo_git=$1
425+ local install_folder=$2
426+ local test_folder=$3
427+ local git_branch=$4
428+
429429 rm -rf " $install_folder "
430430 log_msg_to " 📦 Cloning repo $repo_git into $install_folder "
431431 log_info " Cloning repository: $repo_git "
432- git clone https://github.com/BrowserStackCE/$repo_git .git " $install_folder " >> " $NOW_RUN_LOG_FILE " 2>&1 || return 1
432+ # git clone https://github.com/BrowserStackCE/"$repo_git".git "$install_folder" >> "$NOW_RUN_LOG_FILE" 2>&1 || return 1
433+ if [ -z " $git_branch " ]; then
434+ # git_branch is null or empty
435+ git clone " https://github.com/BrowserStackCE/$repo_git .git" \
436+ " $install_folder " >> " $NOW_RUN_LOG_FILE " 2>&1 || return 1
437+ else
438+ # git_branch has a value
439+ git clone -b " $git_branch " " https://github.com/BrowserStackCE/$repo_git .git" \
440+ " $install_folder " >> " $NOW_RUN_LOG_FILE " 2>&1 || return 1
441+ fi
433442 log_msg_to " ✅ Cloned repository: $repo_git into $install_folder "
434443 cd " $install_folder /$test_folder " || return 1
435444}
0 commit comments