From 6106f3c34cbd4320c73c1f671975624490a3ea85 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 7 May 2026 10:20:10 +0200 Subject: [PATCH 1/3] Terminate iOS app before launch --- .../Private/DeviceProviders/SauceLabsProvider.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 b/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 index c8c47a4..861fcbf 100644 --- a/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 +++ b/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 @@ -361,6 +361,19 @@ class SauceLabsProvider : DeviceProvider { $bundleId = $ExecutablePath $this.CurrentPackageName = $bundleId + # Terminate first: without this, mobile: launchApp sometimes + # brings the app up without applying the supplied arguments. + try { + $terminateBody = @{ + script = 'mobile: terminateApp' + args = @{ bundleId = $bundleId } + } + $this.InvokeSauceLabsApi('POST', "$baseUri/execute/sync", $terminateBody, $false, $null) | Out-Null + } + catch { + Write-Debug "$($this.Platform): terminateApp pre-launch failed (app may not be running): $_" + } + Write-Host "Launching: $bundleId" -ForegroundColor Cyan if ($Arguments) { Write-Host " Arguments: $Arguments" -ForegroundColor Cyan From 08d3bcfbc31cf896a753205d33317fb89a0c30dc Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 7 May 2026 11:16:13 +0200 Subject: [PATCH 2/3] Terminate residual instance on both mobile platforms --- .../DeviceProviders/SauceLabsProvider.ps1 | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 b/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 index 861fcbf..6fcb5e7 100644 --- a/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 +++ b/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 @@ -304,6 +304,20 @@ class SauceLabsProvider : DeviceProvider { } } + [void] TerminateApp([string]$baseUri, [string]$packageName) { + $appParameter = if ($this.MobilePlatform -eq 'Android') { 'appId' } else { 'bundleId' } + try { + $body = @{ + script = 'mobile: terminateApp' + args = @{ $appParameter = $packageName } + } + $this.InvokeSauceLabsApi('POST', "$baseUri/execute/sync", $body, $false, $null) | Out-Null + } + catch { + Write-Debug "$($this.Platform): nothing to terminate (app likely not running): $_" + } + } + [hashtable] RunApplication([string]$ExecutablePath, [string[]]$Arguments, [string]$LogFilePath = $null, [string]$WorkingDirectory = $null) { Write-Debug "$($this.Platform): Running application: $ExecutablePath" @@ -327,6 +341,9 @@ class SauceLabsProvider : DeviceProvider { $activityName = $parsed.ActivityName $this.CurrentPackageName = $packageName + # Terminate the app so the next launch starts fresh. + $this.TerminateApp($baseUri, $packageName) + # Launch activity with Intent extras Write-Host "Launching: $packageName/$activityName" -ForegroundColor Cyan @@ -361,18 +378,8 @@ class SauceLabsProvider : DeviceProvider { $bundleId = $ExecutablePath $this.CurrentPackageName = $bundleId - # Terminate first: without this, mobile: launchApp sometimes - # brings the app up without applying the supplied arguments. - try { - $terminateBody = @{ - script = 'mobile: terminateApp' - args = @{ bundleId = $bundleId } - } - $this.InvokeSauceLabsApi('POST', "$baseUri/execute/sync", $terminateBody, $false, $null) | Out-Null - } - catch { - Write-Debug "$($this.Platform): terminateApp pre-launch failed (app may not be running): $_" - } + # Terminate the app so the next launch starts fresh. + $this.TerminateApp($baseUri, $bundleId) Write-Host "Launching: $bundleId" -ForegroundColor Cyan if ($Arguments) { From 73bd33d78c0a1f00e5a725687664706d4b045b57 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 7 May 2026 11:20:57 +0200 Subject: [PATCH 3/3] Better warning --- app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 b/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 index 6fcb5e7..22f86f6 100644 --- a/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 +++ b/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 @@ -314,7 +314,7 @@ class SauceLabsProvider : DeviceProvider { $this.InvokeSauceLabsApi('POST', "$baseUri/execute/sync", $body, $false, $null) | Out-Null } catch { - Write-Debug "$($this.Platform): nothing to terminate (app likely not running): $_" + Write-Warning "$($this.Platform): Terminate request failed: $_" } }