From ba6d605404fd8ac6e43d7eff12eb89cf37bb8651 Mon Sep 17 00:00:00 2001 From: Huaxing YUAN Date: Thu, 14 Mar 2024 15:33:01 +0100 Subject: [PATCH] - Cancel ResetApp after test case. - Get all logs after a test. --- .../TestCaseApp.cs | 40 ++++++++++++++----- .../TestSuiteApp.cs | 2 - 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/AxaFrance.WebEngine.MobileApp/TestCaseApp.cs b/src/AxaFrance.WebEngine.MobileApp/TestCaseApp.cs index 49208c3..2803b81 100644 --- a/src/AxaFrance.WebEngine.MobileApp/TestCaseApp.cs +++ b/src/AxaFrance.WebEngine.MobileApp/TestCaseApp.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // Modified By: YUAN Huaxing, at: 2022-5-13 18:26 using OpenQA.Selenium.Appium; +using OpenQA.Selenium.Appium.Android; +using OpenQA.Selenium.Appium.iOS; using System; using System.Text; @@ -16,18 +18,23 @@ public class TestCaseApp : TestCase public override string Cleanup() { try - { - StringBuilder sb = new StringBuilder(); + { var l = (Context as AppiumDriver).Manage().Logs; - var logs = l.GetLog("server"); - foreach (var log in logs) + foreach(var logType in l.AvailableLogTypes) { - if (log.Timestamp > startDate) + StringBuilder sb = new StringBuilder(); + var logs = l.GetLog(logType); + foreach (var log in logs) { - sb.AppendLine($"[{log.Level}] {log.Timestamp} {log.Message}"); + if (log.Timestamp > startDate) + { + sb.AppendLine($"[{log.Level}] {log.Timestamp} {log.Message}"); + } } + DebugLogger.WriteLine($"Log for {logType}"); + DebugLogger.WriteLine(sb.ToString()); } - DebugLogger.WriteLine(sb.ToString()); + } catch (Exception ex) { @@ -36,9 +43,10 @@ public override string Cleanup() try { - if (Context is AppiumDriver appiumDriver) + + if (Context is AppiumDriver appiumDriver && !string.IsNullOrEmpty(Settings.Instance.AppPackageName)) { - appiumDriver.ResetApp(); + ResetApp(appiumDriver); } } catch (Exception ex) @@ -50,6 +58,20 @@ public override string Cleanup() } + private void ResetApp(AppiumDriver appiumDriver) + { + DebugLogger.WriteLine("Dont reset app, please do a proper login/logout on each test scenario"); + //get current package name, terminate it and reset it + /* + if (appiumDriver is AndroidDriver ad) + { + var packageName = ad.CurrentPackage; + appiumDriver.TerminateApp(packageName); + appiumDriver.ActivateApp(packageName); + } + */ + } + /// public override void Initialize() diff --git a/src/AxaFrance.WebEngine.MobileApp/TestSuiteApp.cs b/src/AxaFrance.WebEngine.MobileApp/TestSuiteApp.cs index 44826c5..40e5340 100644 --- a/src/AxaFrance.WebEngine.MobileApp/TestSuiteApp.cs +++ b/src/AxaFrance.WebEngine.MobileApp/TestSuiteApp.cs @@ -36,7 +36,6 @@ public override void CleanUp(Settings s) { try { - androidDriver.CloseApp(); androidDriver.Close(); } catch { } @@ -51,7 +50,6 @@ public override void CleanUp(Settings s) { try { - iosDriver.CloseApp(); iosDriver.Close(); } catch { }