Skip to content

Commit

Permalink
- Cancel ResetApp after test case.
Browse files Browse the repository at this point in the history
- Get all logs after a test.
  • Loading branch information
huaxing-yuan committed Mar 14, 2024
1 parent 1169239 commit ba6d605
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
40 changes: 31 additions & 9 deletions src/AxaFrance.WebEngine.MobileApp/TestCaseApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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);
}
*/
}


/// <inheritdoc/>
public override void Initialize()
Expand Down
2 changes: 0 additions & 2 deletions src/AxaFrance.WebEngine.MobileApp/TestSuiteApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public override void CleanUp(Settings s)
{
try
{
androidDriver.CloseApp();
androidDriver.Close();
}
catch { }
Expand All @@ -51,7 +50,6 @@ public override void CleanUp(Settings s)
{
try
{
iosDriver.CloseApp();
iosDriver.Close();
}
catch { }
Expand Down

0 comments on commit ba6d605

Please sign in to comment.