diff --git a/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 b/app-runner/Private/DeviceProviders/SauceLabsProvider.ps1 index c8c47a4..22f86f6 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-Warning "$($this.Platform): Terminate request failed: $_" + } + } + [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,6 +378,9 @@ class SauceLabsProvider : DeviceProvider { $bundleId = $ExecutablePath $this.CurrentPackageName = $bundleId + # Terminate the app so the next launch starts fresh. + $this.TerminateApp($baseUri, $bundleId) + Write-Host "Launching: $bundleId" -ForegroundColor Cyan if ($Arguments) { Write-Host " Arguments: $Arguments" -ForegroundColor Cyan