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 #823 from Magenic/feature/UseAppiumAlpha
Browse files Browse the repository at this point in the history
Update to use Appium 5 beta
  • Loading branch information
TroyWalshProf authored Oct 22, 2021
2 parents 841b6b1 + 49c3b63 commit 004a96b
Show file tree
Hide file tree
Showing 30 changed files with 247 additions and 150 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ jobs:
test-winapp:
name: WinApp
#Disable until we get AppiumUpdate
if: ${{ false }}
needs: waitOld
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- run: |
Start-Process -FilePath "C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"
- name: Install Appium
run: npm install -g appium
- name: Run Appium
run: invoke-expression 'cmd /c start appium'
shell: pwsh
- id: builder
uses: ./.github/workflows/buildtest-action
Expand All @@ -137,8 +137,7 @@ jobs:
test-appium:
name: Appium
# Skip when dependabot PR - Dependabot PRs cannot access action secrets
if: ${{ false }}
#Disable until we get AppiumUpdate if: github.actor != 'dependabot[bot]'
if: github.actor != 'dependabot[bot]'
needs: waitOld
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -436,8 +435,7 @@ jobs:
# Skip when dependabot PR - Dependabot PRs cannot access action secrets
if: github.actor != 'dependabot[bot]'
runs-on: windows-latest
needs: [test-untils, test-mongo, test-database, test-webservice, test-base, test-email, test-framework, test-specflow, test-specflownunit, test-composite, test-selenpomlazy, test-selenutil, test-selengen, getVersion]
#Disable until we get AppiumUpdate needs: [test-appium, test-winapp, test-untils, test-mongo, test-database, test-webservice, test-base, test-email, test-framework, test-specflow, test-specflownunit, test-composite, test-selenpomlazy, test-selenutil, test-selengen, getVersion]
needs: [test-appium, test-winapp, test-untils, test-mongo, test-database, test-webservice, test-base, test-email, test-framework, test-specflow, test-specflownunit, test-composite, test-selenpomlazy, test-selenutil, test-selengen, getVersion]
steps:
- name: Set up JDK 11
uses: actions/setup-java@v1
Expand Down
10 changes: 5 additions & 5 deletions Framework/AppiumUnitTests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
<!-- Device settings -->
<add key="PlatformName" value="Android" />
<add key="PlatformVersion" value="6.0" />
<add key="DeviceName" value="Android GoogleAPI Emulator" />
<add key="DeviceName" value="Android Emulator" />
<add key="BrowserName" value="Chrome" />

<add key="WebSiteBase" value="https://magenicautomation.azurewebsites.net/" />

Expand Down Expand Up @@ -73,10 +74,9 @@
<add key="SavePagesourceOnFail" value="YES" />
</AppiumMaqs>
<AppiumCapsMaqs>
<!--<add key="sauce:options" value="{username: 'magenicMAQSService', accessKey: 'NEVER_ADD', appiumVersion: '1.20.2', orientation: 'portrait' }" />-->
<add key="username" value="magenicMAQSService" />
<add key="accessKey" value="NEVER_ENTER_THIS_VALUE" />
<add key="deviceName" value="Android Emulator" />
<add key="deviceOrientation" value="portrait" />
<add key="browserName" value="Chrome" />
<add key="accessKey" value="NEVER_ADD'" />
<add key="appiumVersion" value="1.20.2" />
</AppiumCapsMaqs>
</configuration>
10 changes: 5 additions & 5 deletions Framework/AppiumUnitTests/AppiumConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
using Magenic.Maqs.BaseAppiumTest;
using Magenic.Maqs.Utilities.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Support.UI;
using System;

namespace AppiumUnitTests
{
using OpenQA.Selenium;

/// <summary>
/// Appium Config Unit Tests
/// </summary>
Expand All @@ -29,6 +28,7 @@ public class AppiumConfigTests
public static void Initialize(TestContext testContext)
{
Config.UpdateWithVSTestContext(testContext);
Config.AddTestSettingValue("sauce:options", JsonConvert.SerializeObject(AppiumConfig.GetCapabilitiesAsStrings()), ConfigSection.AppiumCapsMaqs);
}

/// <summary>
Expand Down Expand Up @@ -58,7 +58,7 @@ public void GetPlatformVersionTest()
[TestCategory(TestCategories.Appium)]
public void GetDeviceNameTest()
{
Assert.AreEqual("Android GoogleAPI Emulator", AppiumConfig.GetDeviceName());
Assert.AreEqual("Android Emulator", AppiumConfig.GetDeviceName());
}

/// <summary>
Expand All @@ -80,7 +80,7 @@ public void GetCommandTimeout()
[TestCategory(TestCategories.Appium)]
public void MobileDeviceTest()
{
AppiumDriver<IWebElement> driver = AppiumDriverFactory.GetDefaultMobileDriver();
AppiumDriver driver = AppiumDriverFactory.GetDefaultMobileDriver();

try
{
Expand Down Expand Up @@ -110,7 +110,7 @@ public void GetMobileHubUrlTest()
[TestCategory(TestCategories.Appium)]
public void GetWaitDriverTest()
{
AppiumDriver<IWebElement> driver = AppiumDriverFactory.GetDefaultMobileDriver();
AppiumDriver driver = AppiumDriverFactory.GetDefaultMobileDriver();
WebDriverWait wait = AppiumUtilities.GetDefaultWaitDriver(driver);
try
{
Expand Down
26 changes: 17 additions & 9 deletions Framework/AppiumUnitTests/AppiumIosUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using Magenic.Maqs.Utilities.Helper;
using Magenic.Maqs.Utilities.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using System.Collections.Generic;
using System.IO;

namespace AppiumUnitTests
Expand Down Expand Up @@ -73,17 +75,23 @@ public void AssertFuncFailPath()
/// Sets capabilities for testing the iOS Driver creation
/// </summary>
/// <returns>iOS instance of the Appium Driver</returns>
protected override AppiumDriver<IWebElement> GetMobileDevice()
protected override AppiumDriver GetMobileDevice()
{
AppiumOptions options = new AppiumOptions();
AppiumOptions options = new AppiumOptions
{
DeviceName = "iPhone 13 Simulator",
PlatformName = "iOS",
PlatformVersion = "15.0",
BrowserName = "Safari"
};

options.AddAdditionalCapability("deviceName", "iPhone 8 Simulator");
options.AddAdditionalCapability("deviceOrientation", "portrait");
options.AddAdditionalCapability("platformVersion", "12.2");
options.AddAdditionalCapability("platformName", "iOS");
options.AddAdditionalCapability("browserName", "Safari");
options.AddAdditionalCapability("username", Config.GetValueForSection(ConfigSection.AppiumCapsMaqs, "userName"));
options.AddAdditionalCapability("accessKey", Config.GetValueForSection(ConfigSection.AppiumCapsMaqs, "accessKey"));
var sauceCreds = Config.GetValueForSection(ConfigSection.AppiumCapsMaqs, "sauce:options");

// Use Appium 1.22 for running iOS tests
sauceCreds = sauceCreds.Replace("1.20.2", "1.22.0");

options.AddAdditionalAppiumOption("sauce:options", JsonConvert.DeserializeObject<Dictionary<string, string>>(sauceCreds));
options.AddAdditionalAppiumOption("deviceOrientation", "portrait");

return AppiumDriverFactory.GetIOSDriver(AppiumConfig.GetMobileHubUrl(), options, AppiumConfig.GetMobileCommandTimeout());
}
Expand Down
2 changes: 1 addition & 1 deletion Framework/AppiumUnitTests/AppiumTestObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void AppiumTestObjectTest()
[TestCategory(TestCategories.Appium)]
public void GetAndCloseDriverTest()
{
AppiumDriver<IWebElement> driver = AppiumDriverFactory.GetDefaultMobileDriver();
AppiumDriver driver = AppiumDriverFactory.GetDefaultMobileDriver();
try
{
Assert.IsNotNull(driver);
Expand Down
24 changes: 12 additions & 12 deletions Framework/AppiumUnitTests/AppiumUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ namespace AppiumUnitTests
/// Appium Utilities Unit Tests
/// </summary>
[TestClass]
[TestCategory(TestCategories.Appium)]
public class AppiumUtilitiesTests : BaseAppiumTest
{
/// <summary>
/// Verify we can create a Appium test object with a Appium driver
/// </summary>
[TestMethod]
public void CreateAppiumTestObjectWithDriver()
{
AppiumTestObject newObject = new AppiumTestObject(this.AppiumDriver, this.TestObject.Log, "test");
Assert.AreEqual(this.AppiumDriver, newObject.AppiumDriver);
Assert.AreEqual(this.Log, newObject.Log);
}

/// <summary>
/// Verify a bad create fails in the right way
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
[ExpectedException(typeof(WebDriverException))]
public void BadCreate()
{
Expand All @@ -36,7 +47,6 @@ public void BadCreate()
/// Verify CaptureScreenshot works - Validating that the screenshot was created
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void CaptureScreenshotTest()
{
AppiumUtilities.CaptureScreenshot(this.TestObject.AppiumDriver, this.TestObject);
Expand All @@ -49,7 +59,6 @@ public void CaptureScreenshotTest()
/// Verify CaptureScreenshot works with console logger - Validating that the screenshot was not created
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void CaptureScreenshotWithConsoleLoggerTest()
{
// Create a console logger and calculate the file location
Expand All @@ -67,7 +76,6 @@ public void CaptureScreenshotWithConsoleLoggerTest()
/// Verify that CaptureScreenshot properly handles exceptions and returns false
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void CaptureScreenshotThrownException()
{
FileLogger tempLogger = new FileLogger
Expand All @@ -84,7 +92,6 @@ public void CaptureScreenshotThrownException()
/// Verify when a screenshot is captured it is associated to the test object
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void CaptureScreenshotTestObjectAssociation()
{
AppiumUtilities.CaptureScreenshot(this.TestObject.AppiumDriver, this.TestObject);
Expand All @@ -97,7 +104,6 @@ public void CaptureScreenshotTestObjectAssociation()
/// Verify SavePageSource works - Validating that the Page Source file was created
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void SavePageSourceTest()
{
AppiumUtilities.SavePageSource(this.TestObject.AppiumDriver, this.TestObject);
Expand All @@ -112,7 +118,6 @@ public void SavePageSourceTest()
/// Verify that SavePageSource properly handles exceptions and returns false
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void SavePageSourceThrownException()
{
FileLogger tempLogger = new FileLogger
Expand All @@ -129,7 +134,6 @@ public void SavePageSourceThrownException()
/// Verify that SavePageSource creates Directory if it does not exist already
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void SavePageSourceNoExistingDirectory()
{
string pageSourcePath = AppiumUtilities.SavePageSource(this.AppiumDriver, this.TestObject, "TempTestDirectory", "SavePSNoDir");
Expand All @@ -141,7 +145,6 @@ public void SavePageSourceNoExistingDirectory()
/// Verify when a page source is saved it is associated to the test object
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void SavedPageSourceTestObjectAssociation()
{
string pageSourcePath = AppiumUtilities.SavePageSource(this.AppiumDriver, this.TestObject, "TempTestDirectory", "TestObjAssoc");
Expand All @@ -153,7 +156,6 @@ public void SavedPageSourceTestObjectAssociation()
/// Test lazy element
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void AppiumLazyTest()
{
Assert.IsNotNull(this.TestObject.AppiumDriver);
Expand All @@ -175,7 +177,6 @@ public void AppiumLazyTest()
/// Test lazy parent element and finds
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void AppiumLazyParentTest()
{
this.AppiumDriver.Navigate().GoToUrl(Config.GetValueForSection(ConfigSection.AppiumMaqs, "WebSiteBase"));
Expand All @@ -198,7 +199,6 @@ public void AppiumLazyParentTest()
/// Test lazy element wait overrides
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Appium)]
public void AppiumLazyWaitOverride()
{
TimeSpan overrideTimeSpan = TimeSpan.FromSeconds(10);
Expand Down
9 changes: 4 additions & 5 deletions Framework/AppiumUnitTests/AppiumWinAppUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Magenic.Maqs.Utilities.Helper;
using Magenic.Maqs.Utilities.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using System;
using System.IO;
Expand Down Expand Up @@ -48,7 +47,7 @@ public void AppiumWinAppDriverTest()
this.SoftAssert.Assert(() => Assert.IsTrue(NotepadApplication.TextEditor.Displayed, "Expect displayed"));
this.SoftAssert.Assert(() => Assert.IsFalse(NotepadApplication.DontSave.ExistsNow, "Expect not to exist now"));

this.SoftAssert.Assert(() => Assert.AreEqual(testString, this.AppiumDriver.FindElementByName("Text Editor").Text));
this.SoftAssert.Assert(() => Assert.AreEqual(testString, this.AppiumDriver.FindElement(MobileBy.Name("Text Editor")).Text));

NotepadApplication.OverrideDriver(null);
this.SoftAssert.Assert(() => Assert.AreEqual(null, NotepadApplication.GetAppiumDriver()));
Expand Down Expand Up @@ -97,11 +96,11 @@ protected override void BeforeCleanup(TestResultType resultType)
/// Sets capabilities for testing the Windows application driver creation
/// </summary>
/// <returns>Windows application driver instance of the Appium Driver</returns>
protected override AppiumDriver<IWebElement> GetMobileDevice()
protected override AppiumDriver GetMobileDevice()
{
AppiumOptions options = new AppiumOptions();
options.AddAdditionalCapability("app", $"{Environment.SystemDirectory}\\notepad.exe");
return AppiumDriverFactory.GetWindowsDriver(new Uri("http://127.0.0.1:4723"), options, TimeSpan.FromSeconds(30));
options.App = $"{Environment.SystemDirectory}\\notepad.exe";
return AppiumDriverFactory.GetWindowsDriver(new Uri("http://127.0.0.1:4723/wd/hub"), options, TimeSpan.FromSeconds(30));
}
}
}
11 changes: 5 additions & 6 deletions Framework/AppiumUnitTests/NotepadPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Magenic.Maqs.BaseAppiumTest;
using Magenic.Maqs.Utilities.Logging;
using Magenic.Maqs.Utilities.Performance;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;

namespace AppiumUnitTests
Expand All @@ -31,31 +30,31 @@ public NotepadPageModel(IAppiumTestObject testObject)
/// </summary>
private LazyMobileElement Document
{
get { return this.GetLazyElement(By.ClassName("Notepad"), "Document"); }
get { return this.GetLazyElement(MobileBy.ClassName("Notepad"), "Document"); }
}

/// <summary>
/// Gets the text editor
/// </summary>
public LazyMobileElement TextEditor
{
get { return this.GetLazyElement(Document, By.Name("Text Editor"), "Text Editor"); }
get { return this.GetLazyElement(Document, MobileBy.Name("Text Editor"), "Text Editor"); }
}

/// <summary>
/// Get the close button
/// </summary>
private LazyMobileElement Close
{
get { return this.GetLazyElement(By.Name("Close"), "Close"); }
get { return this.GetLazyElement(MobileBy.Name("Close"), "Close"); }
}

/// <summary>
/// Get the don't save button
/// </summary>
public LazyMobileElement DontSave
{
get { return this.GetLazyElement(By.Name("Don't Save"), "Don't Save"); }
get { return this.GetLazyElement(MobileBy.Name("Don't Save"), "Don't Save"); }
}

public void CloseAndDontSave()
Expand All @@ -77,7 +76,7 @@ public override bool IsPageLoaded()
/// Get web driver
/// </summary>
/// <returns>The web driver</returns>
public AppiumDriver<IWebElement> GetAppiumDriver()
public AppiumDriver GetAppiumDriver()
{
return this.AppiumDriver;
}
Expand Down
Loading

0 comments on commit 004a96b

Please sign in to comment.