@@ -6,14 +6,14 @@ $script:PROJECT_FOLDER = "NOW"
66
77$script :GLOBAL_DIR = Join-Path $WORKSPACE_DIR $PROJECT_FOLDER
88$script :LOG_DIR = Join-Path $GLOBAL_DIR " logs"
9- $script :GLOBAL_LOG = Join-Path $LOG_DIR " global.log "
10- $script :WEB_LOG = Join-Path $LOG_DIR " web_run_result.log "
11- $script :MOBILE_LOG = Join-Path $LOG_DIR " mobile_run_result.log "
9+ $script :GLOBAL_LOG = " "
10+ $script :WEB_LOG = " "
11+ $script :MOBILE_LOG = " "
1212
1313# Script state
1414$script :BROWSERSTACK_USERNAME = " "
1515$script :BROWSERSTACK_ACCESS_KEY = " "
16- $script :TEST_TYPE = " " # Web / App / Both
16+ $script :TEST_TYPE = " " # Web / App
1717$script :TECH_STACK = " " # Java / Python / JS
1818[double ]$script :PARALLEL_PERCENTAGE = 1.00
1919
@@ -58,10 +58,16 @@ function Clear-OldLogs {
5858 if (! (Test-Path $LOG_DIR )) {
5959 New-Item - ItemType Directory - Path $LOG_DIR | Out-Null
6060 }
61- ' ' | Out-File - FilePath $GLOBAL_LOG - Encoding UTF8
62- ' ' | Out-File - FilePath $WEB_LOG - Encoding UTF8
63- ' ' | Out-File - FilePath $MOBILE_LOG - Encoding UTF8
64- Log- Line " ✅ Logs cleared and fresh run initiated." $GLOBAL_LOG
61+
62+ $legacyLogs = @ (" global.log" , " web_run_result.log" , " mobile_run_result.log" )
63+ foreach ($legacy in $legacyLogs ) {
64+ $legacyPath = Join-Path $LOG_DIR $legacy
65+ if (Test-Path $legacyPath ) {
66+ Remove-Item - Path $legacyPath - Force - ErrorAction SilentlyContinue
67+ }
68+ }
69+
70+ Log- Line " ✅ Logs directory cleaned. Legacy files removed." $GLOBAL_LOG
6571}
6672
6773# ===== Git Clone =====
@@ -304,39 +310,49 @@ function Get-BasicAuthHeader {
304310function Fetch-Plan-Details {
305311 param ([string ]$TestType )
306312
307- Log- Line " ℹ️ Fetching BrowserStack plan for $TestType " $GLOBAL_LOG
313+ if ([string ]::IsNullOrWhiteSpace($TestType )) {
314+ throw " Test type is required to fetch plan details."
315+ }
316+
317+ $normalized = $TestType.ToLowerInvariant ()
318+ Log- Line " ℹ️ Fetching BrowserStack plan for $normalized " $GLOBAL_LOG
319+
308320 $auth = Get-BasicAuthHeader - User $BROWSERSTACK_USERNAME - Key $BROWSERSTACK_ACCESS_KEY
309321 $headers = @ { Authorization = $auth }
310322
311- if ($TestType -in @ (" Web" , " Both" , " web" , " both" )) {
312- try {
313- $resp = Invoke-RestMethod - Method Get - Uri " https://api.browserstack.com/automate/plan.json" - Headers $headers
314- $script :WEB_PLAN_FETCHED = $true
315- $script :TEAM_PARALLELS_MAX_ALLOWED_WEB = [int ]$resp.parallel_sessions_max_allowed
316- Log- Line " ✅ Web Testing Plan fetched: Team max parallel sessions = $TEAM_PARALLELS_MAX_ALLOWED_WEB " $GLOBAL_LOG
317- } catch {
318- Log- Line " ❌ Web Testing Plan fetch failed ($ ( $_.Exception.Message ) )" $GLOBAL_LOG
323+ switch ($normalized ) {
324+ " web" {
325+ try {
326+ $resp = Invoke-RestMethod - Method Get - Uri " https://api.browserstack.com/automate/plan.json" - Headers $headers
327+ $script :WEB_PLAN_FETCHED = $true
328+ $script :TEAM_PARALLELS_MAX_ALLOWED_WEB = [int ]$resp.parallel_sessions_max_allowed
329+ Log- Line " ✅ Web Testing Plan fetched: Team max parallel sessions = $TEAM_PARALLELS_MAX_ALLOWED_WEB " $GLOBAL_LOG
330+ } catch {
331+ Log- Line " ❌ Web Testing Plan fetch failed ($ ( $_.Exception.Message ) )" $GLOBAL_LOG
332+ }
333+ if (-not $WEB_PLAN_FETCHED ) {
334+ throw " Unable to fetch Web Testing plan details."
335+ }
319336 }
320- }
321- if ($TestType -in @ (" App" , " Both" , " app" , " both" )) {
322- try {
323- $resp2 = Invoke-RestMethod - Method Get - Uri " https://api-cloud.browserstack.com/app-automate/plan.json" - Headers $headers
324- $script :MOBILE_PLAN_FETCHED = $true
325- $script :TEAM_PARALLELS_MAX_ALLOWED_MOBILE = [int ]$resp2.parallel_sessions_max_allowed
326- Log- Line " ✅ Mobile App Testing Plan fetched: Team max parallel sessions = $TEAM_PARALLELS_MAX_ALLOWED_MOBILE " $GLOBAL_LOG
327- } catch {
328- Log- Line " ❌ Mobile App Testing Plan fetch failed ($ ( $_.Exception.Message ) )" $GLOBAL_LOG
337+ " app" {
338+ try {
339+ $resp2 = Invoke-RestMethod - Method Get - Uri " https://api-cloud.browserstack.com/app-automate/plan.json" - Headers $headers
340+ $script :MOBILE_PLAN_FETCHED = $true
341+ $script :TEAM_PARALLELS_MAX_ALLOWED_MOBILE = [int ]$resp2.parallel_sessions_max_allowed
342+ Log- Line " ✅ Mobile App Testing Plan fetched: Team max parallel sessions = $TEAM_PARALLELS_MAX_ALLOWED_MOBILE " $GLOBAL_LOG
343+ } catch {
344+ Log- Line " ❌ Mobile App Testing Plan fetch failed ($ ( $_.Exception.Message ) )" $GLOBAL_LOG
345+ }
346+ if (-not $MOBILE_PLAN_FETCHED ) {
347+ throw " Unable to fetch Mobile App Testing plan details."
348+ }
349+ }
350+ default {
351+ throw " Unsupported TEST_TYPE: $TestType . Allowed values: Web, App."
329352 }
330353 }
331354
332- if ( ($TestType -match " ^Web$|^web$" -and -not $WEB_PLAN_FETCHED ) -or
333- ($TestType -match " ^App$|^app$" -and -not $MOBILE_PLAN_FETCHED ) -or
334- ($TestType -match " ^Both$|^both$" -and -not ($WEB_PLAN_FETCHED -or $MOBILE_PLAN_FETCHED )) ) {
335- Log- Line " ❌ Unauthorized to fetch required plan(s) or failed request(s). Exiting." $GLOBAL_LOG
336- throw " Plan fetch failed"
337- }
338-
339- Log- Line " ℹ️ Plan summary: Web $WEB_PLAN_FETCHED ($TEAM_PARALLELS_MAX_ALLOWED_WEB max), Mobile $MOBILE_PLAN_FETCHED ($TEAM_PARALLELS_MAX_ALLOWED_MOBILE max)" $GLOBAL_LOG
355+ Log- Line " ℹ️ Plan summary: Web fetched=$WEB_PLAN_FETCHED (team max=$TEAM_PARALLELS_MAX_ALLOWED_WEB ), Mobile fetched=$MOBILE_PLAN_FETCHED (team max=$TEAM_PARALLELS_MAX_ALLOWED_MOBILE )" $GLOBAL_LOG
340356}
341357
342358
0 commit comments