Skip to content

Commit

Permalink
Added lots more code
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Aug 30, 2024
1 parent 8d196c9 commit f128a6d
Show file tree
Hide file tree
Showing 66 changed files with 992 additions and 140 deletions.
29 changes: 25 additions & 4 deletions DeviceRunners.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,23 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7FD9E644-B76
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EE37724C-5FEF-46BB-AD80-CD002CC7FF54}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.UITests.XunitTests", "sample\test\DeviceTestingKitApp.UITests\DeviceTestingKitApp.UITests.XunitTests.csproj", "{7F8A6736-38CC-42DE-A609-399FC3C7FFEA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.UITests.XunitTests", "sample\test\DeviceTestingKitApp.UITests.XunitTests\DeviceTestingKitApp.UITests.XunitTests.csproj", "{7F8A6736-38CC-42DE-A609-399FC3C7FFEA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.UITests.XunitTests.Windows", "sample\test\DeviceTestingKitApp.UITests.Windows\DeviceTestingKitApp.UITests.XunitTests.Windows.csproj", "{C2A34B21-6334-4B31-9617-D1648C6B0A50}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.UITests.XunitTests.Windows", "sample\test\DeviceTestingKitApp.UITests.XunitTests.Windows\DeviceTestingKitApp.UITests.XunitTests.Windows.csproj", "{C2A34B21-6334-4B31-9617-D1648C6B0A50}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.UITests.XunitTests.Android", "sample\test\DeviceTestingKitApp.UITests.Android\DeviceTestingKitApp.UITests.XunitTests.Android.csproj", "{34618A8D-7BA5-4999-8049-3220DC63648C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.UITests.XunitTests.Android", "sample\test\DeviceTestingKitApp.UITests.XunitTests.Android\DeviceTestingKitApp.UITests.XunitTests.Android.csproj", "{34618A8D-7BA5-4999-8049-3220DC63648C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceRunners.UIAutomation.Appium", "src\DeviceRunners.UIAutomation.Appium\DeviceRunners.UIAutomation.Appium.csproj", "{B1A52689-AE30-4136-9502-AD2B6A6D154A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceRunners.UIAutomation", "src\DeviceRunners.UIAutomation\DeviceRunners.UIAutomation.csproj", "{4B514D48-D89C-457D-B2DE-F7822A7225B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceTestingKitApp.UITests.NUnitTests", "DeviceTestingKitApp.UITests.NUnitTests\DeviceTestingKitApp.UITests.NUnitTests.csproj", "{03A0F40A-9234-4DCE-AC34-0A1138525DD4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.UITests.NUnitTests", "sample\test\DeviceTestingKitApp.UITests.NUnitTests\DeviceTestingKitApp.UITests.NUnitTests.csproj", "{03A0F40A-9234-4DCE-AC34-0A1138525DD4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceRunners.UIAutomation.Selenium", "src\DeviceRunners.UIAutomation.Selenium\DeviceRunners.UIAutomation.Selenium.csproj", "{CBF6C8E0-681A-426C-9A44-91125AB3208C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceRunners.UIAutomation.Tests", "test\DeviceRunners.UIAutomation.Tests\DeviceRunners.UIAutomation.Tests.csproj", "{7A1A6BC4-CDAF-4A5F-8CAD-85E387F7B64F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceRunners.UIAutomation.Appium.Tests", "test\DeviceRunners.UIAutomation.Appium.Tests\DeviceRunners.UIAutomation.Appium.Tests.csproj", "{5C4E5D7E-B768-4C68-A94A-27EFEE9E20E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -173,6 +179,18 @@ Global
{03A0F40A-9234-4DCE-AC34-0A1138525DD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03A0F40A-9234-4DCE-AC34-0A1138525DD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03A0F40A-9234-4DCE-AC34-0A1138525DD4}.Release|Any CPU.Build.0 = Release|Any CPU
{CBF6C8E0-681A-426C-9A44-91125AB3208C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBF6C8E0-681A-426C-9A44-91125AB3208C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBF6C8E0-681A-426C-9A44-91125AB3208C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBF6C8E0-681A-426C-9A44-91125AB3208C}.Release|Any CPU.Build.0 = Release|Any CPU
{7A1A6BC4-CDAF-4A5F-8CAD-85E387F7B64F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A1A6BC4-CDAF-4A5F-8CAD-85E387F7B64F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A1A6BC4-CDAF-4A5F-8CAD-85E387F7B64F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A1A6BC4-CDAF-4A5F-8CAD-85E387F7B64F}.Release|Any CPU.Build.0 = Release|Any CPU
{5C4E5D7E-B768-4C68-A94A-27EFEE9E20E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C4E5D7E-B768-4C68-A94A-27EFEE9E20E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C4E5D7E-B768-4C68-A94A-27EFEE9E20E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C4E5D7E-B768-4C68-A94A-27EFEE9E20E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -205,6 +223,9 @@ Global
{B1A52689-AE30-4136-9502-AD2B6A6D154A} = {DBF1C119-C96C-4DD3-810B-52451603475C}
{4B514D48-D89C-457D-B2DE-F7822A7225B9} = {DBF1C119-C96C-4DD3-810B-52451603475C}
{03A0F40A-9234-4DCE-AC34-0A1138525DD4} = {EE37724C-5FEF-46BB-AD80-CD002CC7FF54}
{CBF6C8E0-681A-426C-9A44-91125AB3208C} = {DBF1C119-C96C-4DD3-810B-52451603475C}
{7A1A6BC4-CDAF-4A5F-8CAD-85E387F7B64F} = {5073EAFD-FF7B-4C4E-84D2-3AA38A91DE73}
{5C4E5D7E-B768-4C68-A94A-27EFEE9E20E1} = {5073EAFD-FF7B-4C4E-84D2-3AA38A91DE73}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2DABD41C-B083-429E-AE1E-971CFF8DC199}
Expand Down
15 changes: 0 additions & 15 deletions DeviceTestingKitApp.UITests.NUnitTests/UnitTest1.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework.Internal;

namespace DeviceTestingKitApp.UITests.NUnitTests;

public class AppiumServerTests : BaseUITests
{
public AppiumServerTests(string appKey)
: base(appKey)
{
}

[Test]
public void IsReady()
{
//var id = Driver.SessionId;

//Assert.NotNull(id);
//Assert.NotEmpty(id.ToString());

//Assert.Equal(AppState.RunningInForeground, Driver.GetAppState());

Assert.Pass();
}
}
65 changes: 65 additions & 0 deletions sample/test/DeviceTestingKitApp.UITests.NUnitTests/BaseUITests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Xml.Linq;

using DeviceRunners.UIAutomation;
using DeviceRunners.UIAutomation.Appium;

using NUnit.Framework.Internal;

namespace DeviceTestingKitApp.UITests.NUnitTests;

[TestFixture("android")]
[TestFixture("windows")]
[Parallelizable(ParallelScope.All)]
public abstract class BaseUITests
{
private readonly string _testKey;

private AutomationTestSuite _automationTestSuite;
private IAutomatedApp _app;

public BaseUITests(string testKey)
{
_testKey = testKey;
}

protected IAutomatedApp App => _app;

protected TextWriter Output => TestContext.Out;

[SetUp]
public void SetUp()
{
_automationTestSuite = UITestsSetupFixture.TestSuite;
_app = _automationTestSuite.StartApp(_testKey);

//DeviceBy = new UITestsDeviceBy(Driver);
}

[TearDown]
public void TearDown()
{
if (App?.GetPageSource() is string source && !string.IsNullOrWhiteSpace(source))
Output.WriteLine($"Last page source:{Environment.NewLine}{XDocument.Parse(source)}");
else
Output.WriteLine("Page source is empty");

if (App?.GetScreenshot() is { } screenshot)
Output.WriteLine($"Last screenshot:{Environment.NewLine}{screenshot.ToBase64String()}");
else
Output.WriteLine("No screenshot available");

_automationTestSuite.StopApp(_testKey);
}

//protected UITestsDeviceBy DeviceBy { get; }

//protected class UITestsDeviceBy(AppiumDriver driver)
//{
// public By AutomationId(string id) =>
// driver switch
// {
// WindowsDriver => MobileBy.AccessibilityId(id),
// _ => MobileBy.Id(id)
// };
//}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\DeviceRunners.UIAutomation.Appium\DeviceRunners.UIAutomation.Appium.csproj" />
<ProjectReference Include="..\src\DeviceRunners.UIAutomation\DeviceRunners.UIAutomation.csproj" />
<ProjectReference Include="..\..\..\src\DeviceRunners.UIAutomation.Appium\DeviceRunners.UIAutomation.Appium.csproj" />
<ProjectReference Include="..\..\..\src\DeviceRunners.UIAutomation\DeviceRunners.UIAutomation.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using DeviceRunners.UIAutomation;
using DeviceRunners.UIAutomation.Appium;

using NUnit.Framework.Internal;

namespace DeviceTestingKitApp.UITests.NUnitTests;

[SetUpFixture]
public class UITestsSetupFixture
{
[OneTimeSetUp]
public void OneTimeSetUp()
{
var builder = AutomationTestSuiteBuilder.Create()
.AddAppium(options => options
.UseServiceAddress("127.0.0.1", 4723)
.AddLogger(new TestContextLogger())
.AddAndroidApp("android", options => options
.UsePackageName("com.companyname.devicetestingkitapp")
.UseActivityName(".MainActivity"))
.AddWindowsApp("windows", options => options
.UseAppId("com.companyname.devicetestingkitapp_9zz4h110yvjzm!App")))
;
//.AddSelenium(options => options
// .AddWebApp("https://dot.net/"));

TestSuite = builder.Build();
}

[OneTimeTearDown]
public void OneTimeTearDown()
{
TestSuite.Dispose();
}

public static AutomationTestSuite TestSuite { get; private set; }

class TestContextLogger : IAppiumDiagnosticLogger
{
public void Log(string message) =>
TestContext.Out.WriteLine(message);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\DeviceTestingKitApp.UITests.XunitTests\DeviceTestingKitApp.UITests.XunitTests.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.CompilerServices;

namespace DeviceTestingKitApp.UITests;
namespace DeviceTestingKitApp.UITests.XunitTests;

public static partial class _Config
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\DeviceTestingKitApp.UITests.XunitTests\DeviceTestingKitApp.UITests.XunitTests.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.CompilerServices;

namespace DeviceTestingKitApp.UITests;
namespace DeviceTestingKitApp.UITests.XunitTests;

public static partial class _Config
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using DeviceRunners.UIAutomation.Appium;

using OpenQA.Selenium.Appium.Enums;

using Xunit;
using Xunit.Abstractions;

namespace DeviceTestingKitApp.UITests;
namespace DeviceTestingKitApp.UITests.XunitTests;

public class AppiumServerTests : BaseUITests
{
Expand All @@ -17,11 +15,12 @@ public AppiumServerTests(UITestsFixture fixture, ITestOutputHelper output)
[Fact]
public void IsReady()
{
var id = Driver.SessionId;
if (App is not AppiumAutomatedApp appiumApp)
return;

var id = appiumApp.Driver.SessionId;

Assert.NotNull(id);
Assert.NotEmpty(id.ToString());

Assert.Equal(AppState.RunningInForeground, Driver.GetAppState());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using System.Xml.Linq;

using DeviceRunners.UIAutomation;
using DeviceRunners.UIAutomation.Appium;

using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace DeviceTestingKitApp.UITests;
namespace DeviceTestingKitApp.UITests.XunitTests;

[Collection(UITestsCollection.CollectionName)]
public abstract class BaseUITests : IDisposable
Expand All @@ -22,8 +21,6 @@ public BaseUITests(UITestsFixture fixture, ITestOutputHelper output)
App = _automationTestSuite.StartApp(_Config.Current);
Output = output;

DeviceBy = new UITestsDeviceBy(Driver);

_xunitTest = GetTest(Output as TestOutputHelper);
}

Expand All @@ -33,37 +30,19 @@ public BaseUITests(UITestsFixture fixture, ITestOutputHelper output)

public void Dispose()
{
Output.WriteLine("Last page source:");
if (App.GetPageSource() is string source && !string.IsNullOrWhiteSpace(source))
Output.WriteLine(XDocument.Parse(source).ToString());
if (App?.GetPageSource() is string source && !string.IsNullOrWhiteSpace(source))
Output.WriteLine($"Last page source:{Environment.NewLine}{XDocument.Parse(source)}");
else
Output.WriteLine("Page source is empty");

Output.WriteLine("Last screenshot:");
if (App.GetScreenshot() is { } screenshot)
{
Output.WriteLine(screenshot.ToBase64String());
}
if (App?.GetScreenshot() is { } screenshot)
Output.WriteLine($"Last screenshot:{Environment.NewLine}{screenshot.ToBase64String()}");
else
{
Output.WriteLine("No screenshot available");
}

_automationTestSuite.StopApp(_Config.Current);
}

protected UITestsDeviceBy DeviceBy { get; }

protected class UITestsDeviceBy(AppiumDriver driver)
{
public By AutomationId(string id) =>
driver switch
{
WindowsDriver => MobileBy.AccessibilityId(id),
_ => MobileBy.Id(id)
};
}

[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "test")]
static extern ref ITest GetTest(TestOutputHelper? output);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<IsPackable>false</IsPackable>
<IsXunitTestProject>true</IsXunitTestProject>
<IsTestProject>true</IsTestProject>
<RootNamespace>DeviceTestingKitApp.UITests</RootNamespace>
<RootNamespace>DeviceTestingKitApp.UITests.XunitTests</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit f128a6d

Please sign in to comment.