Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #782 from Magenic/poc/Inversion
Browse files Browse the repository at this point in the history
Maqs 7.0 Alpha
  • Loading branch information
TroyWalshProf authored Sep 2, 2021
2 parents 50003c1 + 960a261 commit 7f96ac9
Show file tree
Hide file tree
Showing 172 changed files with 2,666 additions and 1,718 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- id: builder
env:
MagenicMaqs:ConfigJsonEnvRunOverride: ENV
MagenicMaqs:ConfigJsonEnvRun: ENV
MagenicMaqs:ConfigJsonEnv: ENV
MagenicMaqs:EnvOnly: ENV
uses: ./.github/workflows/buildtest-action
with:
bt-param: 'Framework/UtilitiesUnitTests/UtilitiesUnitTests.csproj --settings Framework/Parallel.RunSettings --logger trx --results-directory "${{github.workspace}}/artifactTests/untils/testResults/" /p:CoverletOutput="${{github.workspace}}/artifactTests/untils/" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
Expand Down Expand Up @@ -304,7 +309,6 @@ jobs:
artifactTests/specflow/**/*.xml
artifactTests/specflow/testResults/
test-composite:
name: Composite
needs: waitOld
Expand Down Expand Up @@ -596,6 +600,3 @@ jobs:
}
}
console.error("Failed to find related draft release");
4 changes: 2 additions & 2 deletions Framework/AppiumUnitTests/AppiumConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void GetPlatformNameTest()
{
Assert.AreEqual("Android", AppiumConfig.GetPlatformName());
}

/// <summary>
/// Test for getting mobile OS version
/// </summary>
Expand Down Expand Up @@ -68,7 +68,7 @@ public void GetDeviceNameTest()
[TestCategory(TestCategories.Selenium)]
public void GetCommandTimeout()
{
TimeSpan initTimeout = AppiumConfig.GetCommandTimeout();
TimeSpan initTimeout = AppiumConfig.GetMobileCommandTimeout();

Assert.AreEqual(200, initTimeout.TotalSeconds);
}
Expand Down
7 changes: 3 additions & 4 deletions Framework/AppiumUnitTests/AppiumIosUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.iOS;
using System.IO;

namespace AppiumUnitTests
Expand Down Expand Up @@ -58,7 +57,7 @@ public void AssertFuncFailPath()

Log = new FileLogger(string.Empty, "AssertFuncFailPath.txt", MessageType.GENERIC, true);
AppiumSoftAssert appiumSoftAssert = new AppiumSoftAssert(TestObject);
string logLocation = ((FileLogger)Log).FilePath;
string logLocation = ((IFileLogger)Log).FilePath;
string screenShotLocation = $"{logLocation.Substring(0, logLocation.LastIndexOf('.'))} assertName (1).Png";

bool isFalse = appiumSoftAssert.Assert(() => Assert.IsTrue(false), "assertName");
Expand All @@ -85,8 +84,8 @@ protected override AppiumDriver<IWebElement> GetMobileDevice()
options.AddAdditionalCapability("browserName", "Safari");
options.AddAdditionalCapability("username", Config.GetValueForSection(ConfigSection.AppiumCapsMaqs, "userName"));
options.AddAdditionalCapability("accessKey", Config.GetValueForSection(ConfigSection.AppiumCapsMaqs, "accessKey"));
return AppiumDriverFactory.GetIOSDriver(AppiumConfig.GetMobileHubUrl(), options, AppiumConfig.GetCommandTimeout());

return AppiumDriverFactory.GetIOSDriver(AppiumConfig.GetMobileHubUrl(), options, AppiumConfig.GetMobileCommandTimeout());
}
}
}
16 changes: 7 additions & 9 deletions Framework/AppiumUnitTests/AppiumTestObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void GetAndCloseDriverTest()
[TestCategory(TestCategories.Appium)]
public void GetAndCloseDriverTestFromManager()
{
this.TestObject.GetDriverManager<MobileDriverManager>().Dispose();
this.TestObject.GetDriverManager<AppiumDriverManager>().Dispose();
}

/// <summary>
Expand All @@ -65,9 +65,7 @@ public void GetAndCloseDriverTestFromManager()
public void OverrideDriverRespected()
{
var driver = AppiumDriverFactory.GetDefaultMobileDriver();
this.TestObject.OverrideWebDriver(driver);

Assert.AreEqual(driver, this.AppiumDriver);
this.TestObject.OverrideAppiumDriver(driver);
}

/// <summary>
Expand All @@ -76,13 +74,13 @@ public void OverrideDriverRespected()
[TestMethod]
public void SeparateLazyElementInteractions()
{
MobileDriverManager newDriver = new MobileDriverManager(() => AppiumDriverFactory.GetDefaultMobileDriver(), this.TestObject);
newDriver.GetMobileDriver().Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/");
AppiumDriverManager newDriver = new AppiumDriverManager(() => AppiumDriverFactory.GetDefaultMobileDriver(), this.TestObject);
newDriver.GetAppiumDriver().Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/");
this.ManagerStore.Add("test", newDriver);

this.TestObject.AppiumDriver.Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/Automation");

LazyMobileElement topNew = new LazyMobileElement(this.TestObject, newDriver.GetMobileDriver(), By.CssSelector("*"));
LazyMobileElement topNew = new LazyMobileElement(this.TestObject, newDriver.GetAppiumDriver(), By.CssSelector("*"));
LazyMobileElement topDefault = new LazyMobileElement(this.TestObject, By.CssSelector("*"));

Assert.AreNotEqual(topNew.Text, topDefault.Text);
Expand All @@ -96,7 +94,7 @@ public void SeparateLazyElementInteractions()
public void OverrideDriverFuncRespected()
{
var driver = AppiumDriverFactory.GetDefaultMobileDriver();
this.TestObject.OverrideWebDriver(() => driver);
this.TestObject.OverrideAppiumDriver(() => driver);

Assert.AreEqual(driver, this.AppiumDriver);
}
Expand All @@ -108,7 +106,7 @@ public void OverrideDriverFuncRespected()
[TestCategory(TestCategories.Appium)]
public void GetRespected()
{
Assert.AreEqual(this.TestObject.GetDriverManager<MobileDriverManager>().Get(), this.AppiumDriver);
Assert.AreEqual(this.TestObject.GetDriverManager<AppiumDriverManager>().Get(), this.AppiumDriver);
}
}
}
8 changes: 4 additions & 4 deletions Framework/AppiumUnitTests/AppiumUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void BadCreate()
{
AppiumDriverFactory.CreateDriver(() => throw new AccessViolationException("Should fail"));
}

/// <summary>
/// Verify CaptureScreenshot works - Validating that the screenshot was created
/// </summary>
Expand All @@ -40,7 +40,7 @@ public void BadCreate()
public void CaptureScreenshotTest()
{
AppiumUtilities.CaptureScreenshot(this.TestObject.AppiumDriver, this.TestObject);
string filePath = Path.ChangeExtension(((FileLogger)this.Log).FilePath, ".Png");
string filePath = Path.ChangeExtension(((IFileLogger)this.Log).FilePath, ".Png");
Assert.IsTrue(File.Exists(filePath), "Fail to find screenshot");
File.Delete(filePath);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public void CaptureScreenshotThrownException()
public void CaptureScreenshotTestObjectAssociation()
{
AppiumUtilities.CaptureScreenshot(this.TestObject.AppiumDriver, this.TestObject);
string filePath = Path.ChangeExtension(((FileLogger)this.Log).FilePath, ".Png");
string filePath = Path.ChangeExtension(((IFileLogger)this.Log).FilePath, ".Png");
Assert.IsTrue(this.TestObject.ContainsAssociatedFile(filePath), "Failed to find screenshot");
File.Delete(filePath);
}
Expand All @@ -101,7 +101,7 @@ public void CaptureScreenshotTestObjectAssociation()
public void SavePageSourceTest()
{
AppiumUtilities.SavePageSource(this.TestObject.AppiumDriver, this.TestObject);
string logLocation = ((FileLogger)this.Log).FilePath;
string logLocation = ((IFileLogger)this.Log).FilePath;
string pageSourceFilelocation = $"{logLocation.Substring(0, logLocation.LastIndexOf('.'))}_PS.txt";

Assert.IsTrue(File.Exists(pageSourceFilelocation), "Failed to find page source");
Expand Down
28 changes: 25 additions & 3 deletions Framework/AppiumUnitTests/AppiumWinAppUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System;
using System.IO;

namespace AppiumUnitTests
{
Expand Down Expand Up @@ -58,13 +58,35 @@ public void AppiumWinAppDriverTest()
this.SoftAssert.FailTestIfAssertFailed();
}

/// <summary>
/// Verify SavePageSource works with console logger
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void CapturePageSourceWithConsoleLoggerTest()
{
string name = Guid.NewGuid().ToString();
string path = Path.Combine(Path.GetDirectoryName((this.Log as FileLogger).FilePath), $"PageSource{name}.txt");

// Create a console logger and calculate the file location
ConsoleLogger consoleLogger = new ConsoleLogger();
this.TestObject.Log = consoleLogger;

// Capture page source
bool success = AppiumUtilities.SavePageSource(this.TestObject.AppiumDriver, this.TestObject, name);

// Make sure we can save the page source
Assert.IsTrue(success, "Page source file should have been saved");
Assert.IsTrue(File.Exists(path));
}

/// <summary>
/// Cleanup after application
/// </summary>
protected override void BeforeLoggingTeardown(TestResultType resultType)
protected override void BeforeCleanup(TestResultType resultType)
{
// Make sure we get all the logging info
base.BeforeLoggingTeardown(resultType);
base.BeforeCleanup(resultType);

// Cleanup after the app
NotepadApplication?.CloseAndDontSave();
Expand Down
3 changes: 3 additions & 0 deletions Framework/AppiumUnitTests/BaseFrameworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
using Magenic.Maqs.Utilities.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Diagnostics.CodeAnalysis;
using Assert = NUnit.Framework.Assert;
using PlatformType = Magenic.Maqs.BaseAppiumTest.PlatformType;

namespace AppiumUnitTests
{
Expand Down
9 changes: 4 additions & 5 deletions Framework/AppiumUnitTests/NotepadPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Magenic.Maqs.Utilities.Performance;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using System.Diagnostics.CodeAnalysis;

namespace AppiumUnitTests
{
Expand All @@ -22,7 +21,7 @@ public class NotepadPageModel : BaseAppiumPageModel
/// Initializes a new instance of the <see cref="SeleniumPageModel"/> class
/// </summary>
/// <param name="testObject">The base Appium test object</param>
public NotepadPageModel(AppiumTestObject testObject)
public NotepadPageModel(IAppiumTestObject testObject)
: base(testObject)
{
}
Expand Down Expand Up @@ -87,7 +86,7 @@ public AppiumDriver<IWebElement> GetAppiumDriver()
/// Get logger
/// </summary>
/// <returns>The logger</returns>
public Logger GetLogger()
public ILogger GetLogger()
{
return this.Log;
}
Expand All @@ -96,7 +95,7 @@ public Logger GetLogger()
/// Get test object
/// </summary>
/// <returns>The test object</returns>
public AppiumTestObject GetTestObject()
public IAppiumTestObject GetTestObject()
{
return this.TestObject;
}
Expand All @@ -105,7 +104,7 @@ public AppiumTestObject GetTestObject()
/// Get performance timer collection
/// </summary>
/// <returns>The performance timer collection</returns>
public PerfTimerCollection GetPerfTimerCollection()
public IPerfTimerCollection GetPerfTimerCollection()
{
return this.PerfTimerCollection;
}
Expand Down
73 changes: 36 additions & 37 deletions Framework/BaseAppiumTest/AppiumConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// </copyright>
// <summary>This is the Appium Configuration class</summary>
//--------------------------------------------------
using Magenic.Maqs.Utilities.Data;
using Magenic.Maqs.Utilities.Helper;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -79,73 +78,73 @@ public static Uri GetMobileHubUrl()
}

/// <summary>
/// Get if we should save page source on fail
/// Get the wait timespan
/// </summary>
/// <returns>True if we want to save page source on fail</returns>
public static bool GetSavePagesourceOnFail()
/// <returns>The wait time span</returns>
public static TimeSpan GetMobileWaitTime()
{
return Config.GetValueForSection(ConfigSection.AppiumMaqs, "SavePagesourceOnFail").Equals("Yes", StringComparison.CurrentCultureIgnoreCase);
return TimeSpan.FromMilliseconds(Convert.ToInt32(Config.GetValueForSection(ConfigSection.AppiumMaqs, "MobileWaitTime", "0")));
}

/// <summary>
/// Get if we should save screenshots on soft alert fails
/// Get the timeout timespan
/// </summary>
/// <returns>True if we want to save screenshots on soft alert fails</returns>
public static bool GetSoftAssertScreenshot()
/// <returns>The timeout time span</returns>
public static TimeSpan GetMobileTimeout()
{
return Config.GetValueForSection(ConfigSection.AppiumMaqs, "SoftAssertScreenshot").Equals("Yes", StringComparison.CurrentCultureIgnoreCase);
return TimeSpan.FromMilliseconds(Convert.ToInt32(Config.GetValueForSection(ConfigSection.AppiumMaqs, "MobileTimeout", "0")));
}

/// <summary>
/// Get the capabilities as a dictionary
/// Get the initialize Appium timeout timespan
/// </summary>
/// <returns>Dictionary of capabilities</returns>
public static Dictionary<string, string> GetCapabilitiesAsStrings()
/// <returns>The initialize timeout</returns>
public static TimeSpan GetMobileCommandTimeout()
{
return Config.GetSection(ConfigSection.AppiumCapsMaqs);
string value = Config.GetValueForSection(ConfigSection.AppiumMaqs, "MobileCommandTimeout", "60000");

if (!int.TryParse(value, out int timeout))
{
throw new ArgumentException($"MobileCommandTimeout in {ConfigSection.AppiumMaqs} should be a number but the current value is: {value}");
}

return TimeSpan.FromMilliseconds(timeout);
}

/// <summary>
/// Get the capabilities as a dictionary
/// Get if we should save page source on fail
/// </summary>
/// <returns>Dictionary of capabilities</returns>
public static Dictionary<string, object> GetCapabilitiesAsObjects()
/// <returns>True if we want to save page source on fail</returns>
public static bool GetSavePagesourceOnFail()
{
return GetCapabilitiesAsStrings().ToDictionary(pair => pair.Key, pair => (object)pair.Value);
return Config.GetValueForSection(ConfigSection.AppiumMaqs, "SavePagesourceOnFail").Equals("Yes", StringComparison.CurrentCultureIgnoreCase);
}

/// <summary>
/// Get the wait timespan
/// Get if we should save screenshots on soft alert fails
/// </summary>
/// <returns>The wait time span</returns>
public static TimeSpan GetMobileWaitTime()
/// <returns>True if we want to save screenshots on soft alert fails</returns>
public static bool GetSoftAssertScreenshot()
{
return TimeSpan.FromMilliseconds(Convert.ToInt32(Config.GetValueForSection(ConfigSection.AppiumMaqs, "MobileWaitTime", "0")));
return Config.GetValueForSection(ConfigSection.AppiumMaqs, "SoftAssertScreenshot").Equals("Yes", StringComparison.CurrentCultureIgnoreCase);
}

/// <summary>
/// Get the timeout timespan
/// Get the capabilities as a dictionary
/// </summary>
/// <returns>The timeout time span</returns>
public static TimeSpan GetMobileTimeout()
/// <returns>Dictionary of capabilities</returns>
public static Dictionary<string, string> GetCapabilitiesAsStrings()
{
return TimeSpan.FromMilliseconds(Convert.ToInt32(Config.GetValueForSection(ConfigSection.AppiumMaqs, "MobileTimeout", "0")));
return Config.GetSectionDictionary(ConfigSection.AppiumCapsMaqs);
}

/// <summary>
/// Get the initialize Appium timeout timespan
/// Get the capabilities as a dictionary
/// </summary>
/// <returns>The initialize timeout</returns>
public static TimeSpan GetCommandTimeout()
/// <returns>Dictionary of capabilities</returns>
public static Dictionary<string, object> GetCapabilitiesAsObjects()
{
string value = Config.GetValueForSection(ConfigSection.AppiumMaqs, "MobileCommandTimeout", "60000");

if (!int.TryParse(value, out int timeout))
{
throw new ArgumentException($"MobileCommandTimeout in {ConfigSection.AppiumMaqs} should be a number but the current value is: {value}");
}

return TimeSpan.FromMilliseconds(timeout);
return GetCapabilitiesAsStrings().ToDictionary(pair => pair.Key, pair => (object)pair.Value);
}

/// <summary>
Expand Down Expand Up @@ -174,7 +173,7 @@ public static PlatformType GetDeviceType(string platform)
case "WINDOWS":
return PlatformType.Windows;
default:
throw new ArgumentException(StringProcessor.SafeFormatter($"Device type '{platform}' is not supported"));
throw new ArgumentException($"Device type '{platform}' is not supported");
}
}
}
Expand Down
Loading

0 comments on commit 7f96ac9

Please sign in to comment.