From 53037ed0aa9e9b4197d6d461ad08fbc158ccb3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Mon, 20 Feb 2023 20:55:47 +0100 Subject: [PATCH] Retry Appium local server starting (#35) --- .../Applications/ApplicationFactory.cs | 7 +++++-- .../Applications/LocalApplicationFactory.cs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/ApplicationFactory.cs b/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/ApplicationFactory.cs index 1c63ebf..016d1d0 100644 --- a/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/ApplicationFactory.cs +++ b/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/ApplicationFactory.cs @@ -13,6 +13,8 @@ namespace Aquality.Appium.Mobile.Applications { public abstract class ApplicationFactory : IApplicationFactory { + protected virtual IActionRetrier ActionRetrier => new CustomActionRetrier(); + public abstract IMobileApplication Application { get; } protected virtual AppiumDriver GetDriver(Uri serviceUrl) @@ -20,7 +22,7 @@ protected virtual AppiumDriver GetDriver(Uri serviceUrl) var platformName = AqualityServices.ApplicationProfile.PlatformName; var driverOptions = AqualityServices.ApplicationProfile.DriverSettings.AppiumOptions; var commandTimeout = AqualityServices.Get().Command; - return new CustomActionRetrier().DoWithRetry( + return ActionRetrier.DoWithRetry( () => CreateSession(platformName, serviceUrl, driverOptions, commandTimeout)); } @@ -52,7 +54,8 @@ protected class CustomActionRetrier : ActionRetrier "appium settings app is not running", "socket hang up", "stream was destroyed", - "invalid or unrecognized response" + "invalid or unrecognized response", + "has been expired" }; public CustomActionRetrier() diff --git a/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/LocalApplicationFactory.cs b/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/LocalApplicationFactory.cs index 74f1253..73b9671 100644 --- a/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/LocalApplicationFactory.cs +++ b/Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/LocalApplicationFactory.cs @@ -1,4 +1,5 @@ using OpenQA.Selenium.Appium.Service; +using OpenQA.Selenium.Appium.Service.Exceptions; namespace Aquality.Appium.Mobile.Applications { @@ -9,7 +10,7 @@ public override IMobileApplication Application get { var service = new AppiumServiceBuilder().WithArguments(AqualityServices.LocalServiceSettings.ServerOptions).Build(); - service.Start(); + ActionRetrier.DoWithRetry(service.Start, new [] { typeof(AppiumServerHasNotBeenStartedLocallyException)} ); var driver = GetDriver(service.ServiceUrl); LogApplicationIsReady(); return new Application(driver, service);