-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dd8960
commit f9b784f
Showing
18 changed files
with
196 additions
and
28 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
sample/src/DeviceTestingKitApp/Platforms/Android/MainActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace DeviceTestingKitApp.UITests; | ||
|
||
public static partial class _Config | ||
{ | ||
[ModuleInitializer] | ||
public static void Run() => Current = "android"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
sample/test/DeviceTestingKitApp.UITests/AppiumServerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using DeviceRunners.Appium; | ||
|
||
using OpenQA.Selenium.Appium.Enums; | ||
|
||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace DeviceTestingKitApp.UITests; | ||
|
||
public class AppiumServerTests : BaseUITests | ||
{ | ||
public AppiumServerTests(UITestsFixture fixture, ITestOutputHelper output) | ||
: base(fixture, output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void IsReady() | ||
{ | ||
var id = Driver.SessionId; | ||
|
||
Assert.NotNull(id); | ||
Assert.NotEmpty(id.ToString()); | ||
|
||
Assert.Equal(AppState.RunningInForeground, Driver.GetAppState()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/DeviceRunners.Appium/Extensions/AppiumTestBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using OpenQA.Selenium.Appium; | ||
using OpenQA.Selenium.Appium.Enums; | ||
|
||
namespace DeviceRunners.Appium; | ||
|
||
public static class AppiumDriverExtensions | ||
{ | ||
public static AppState GetAppState(this AppiumDriver driver) | ||
{ | ||
var automationName = driver.GetAutomationName()?.ToLowerInvariant(); | ||
|
||
return automationName switch | ||
{ | ||
"windows" => AppState.NotInstalled, | ||
"uiautomator2" => driver.GetAppState(driver.Capabilities.GetCapability(AndroidMobileCapabilityType.AppPackage)?.ToString()), | ||
_ => throw new ArgumentException($"Unknown automation name: '{automationName}'."), | ||
}; | ||
} | ||
|
||
public static string? GetAutomationName(this AppiumDriver driver) => | ||
driver.Capabilities.GetCapability("automationName")?.ToString(); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/DeviceRunners.Appium/PlatformExtensions/Android/AndroidAppiumTestAppBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Appium; | ||
using OpenQA.Selenium.Appium.Enums; | ||
|
||
namespace DeviceRunners.Appium; | ||
|
||
public class AndroidAppiumTestAppBuilder : AppiumTestAppBuilder | ||
{ | ||
public AndroidAppiumTestAppBuilder() | ||
{ | ||
AppiumOptions.AutomationName = "UIAutomator2"; | ||
AppiumOptions.PlatformName = "Android"; | ||
} | ||
|
||
public AndroidAppiumTestAppBuilder UseAppPackageFilePath(string filePath) | ||
{ | ||
AppiumOptions.App = filePath; | ||
return this; | ||
} | ||
|
||
public AndroidAppiumTestAppBuilder UseAppPackageName(string packageName, string activityName) | ||
{ | ||
AppiumOptions.AddAdditionalAppiumOption(AndroidMobileCapabilityType.AppPackage, packageName); | ||
AppiumOptions.AddAdditionalAppiumOption(AndroidMobileCapabilityType.AppActivity, activityName); | ||
return this; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/DeviceRunners.Appium/PlatformExtensions/Android/AndroidAppiumTestBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using OpenQA.Selenium.Appium; | ||
using OpenQA.Selenium.Appium.Android; | ||
|
||
namespace DeviceRunners.Appium; | ||
|
||
public static class AndroidAppiumTestBuilderExtensions | ||
{ | ||
public static AppiumTestBuilder AddAndroidApp(this AppiumTestBuilder builder, string appKey, string app, string? activityName = null) => | ||
builder.AddAndroidApp(appKey, appBuilder => | ||
{ | ||
switch (Path.GetExtension(app)?.ToLowerInvariant()) | ||
{ | ||
case ".apk": | ||
case ".apks": | ||
appBuilder.UseAppPackageFilePath(app); | ||
break; | ||
case ".aab": | ||
throw new ArgumentException( | ||
"App packages with the .aab extension is not supported by Appium. Only .apk and .apks are supported.", | ||
nameof(app)); | ||
default: | ||
appBuilder.UseAppPackageName(app, activityName ?? ".MainActivity"); | ||
break; | ||
} | ||
}); | ||
|
||
public static AppiumTestBuilder AddAndroidApp(this AppiumTestBuilder builder, string appKey, Action<AndroidAppiumTestAppBuilder> appBuilderAction) => | ||
builder.AddApp<AndroidAppiumTestAppBuilder, DriverFactory>(appKey, appBuilderAction); | ||
|
||
class DriverFactory : IAppiumDriverFactory | ||
{ | ||
public AppiumDriver CreateDriver(AppiumDriverManagerOptions options, AppiumServiceManager appium) => | ||
new AndroidDriver(appium.Service.ServiceUrl, options.Options); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/DeviceRunners.Appium/PlatformExtensions/AppiumTestAppBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using OpenQA.Selenium.Appium; | ||
|
||
namespace DeviceRunners.Appium; | ||
|
||
public abstract class AppiumTestAppBuilder | ||
{ | ||
public AppiumOptions AppiumOptions { get; } = new(); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/DeviceRunners.Appium/PlatformExtensions/AppiumTestBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace DeviceRunners.Appium; | ||
|
||
public static class AppiumTestBuilderExtensions | ||
{ | ||
internal static AppiumTestBuilder AddApp<TAppiumTestAppBuilder, TAppiumDriverFactory>(this AppiumTestBuilder builder, string appKey, Action<TAppiumTestAppBuilder> appBuilderAction) | ||
where TAppiumTestAppBuilder : AppiumTestAppBuilder, new() | ||
where TAppiumDriverFactory : IAppiumDriverFactory, new() | ||
{ | ||
var appBuilder = new TAppiumTestAppBuilder(); | ||
|
||
appBuilderAction?.Invoke(appBuilder); | ||
|
||
return builder.AddApp(appKey, new AppiumDriverManagerOptions | ||
{ | ||
Options = appBuilder.AppiumOptions, | ||
DriverFactory = new TAppiumDriverFactory(), | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/DeviceRunners.Appium/PlatformExtensions/Windows/WindowsAppiumTestAppBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using OpenQA.Selenium.Appium; | ||
|
||
namespace DeviceRunners.Appium; | ||
|
||
public class WindowsAppiumTestAppBuilder : AppiumTestAppBuilder | ||
{ | ||
public WindowsAppiumTestAppBuilder() | ||
{ | ||
AppiumOptions.AutomationName = "windows"; | ||
AppiumOptions.PlatformName = "Windows"; | ||
AppiumOptions.DeviceName = "WindowsPC"; | ||
} | ||
|
||
public WindowsAppiumTestAppBuilder UseApp(string executablePathOrAppId) | ||
{ | ||
AppiumOptions.App = executablePathOrAppId; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters