Skip to content

Commit 81403a2

Browse files
authored
Update Aquality.Selenium.Core version (#25)
* Update Aquality.Selenium.Core version *Support overriding of capabilities from environment variables Use GetValueDictionaryOrEmpty in DeviceSettings *Support FindChildElements feature for Screen via ScreenElement property * Add documentation to screen methods. * Make ElementFactory property static in to make it possible to be used during the field initialization
1 parent c9248dc commit 81403a2

File tree

10 files changed

+124
-37
lines changed

10 files changed

+124
-37
lines changed

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Applications/ApplicationFactory.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using OpenQA.Selenium.Appium.Android;
77
using OpenQA.Selenium.Appium.iOS;
88
using System;
9+
using System.Collections.Generic;
910
using System.Linq;
1011

1112
namespace Aquality.Appium.Mobile.Applications
@@ -42,7 +43,7 @@ protected virtual AppiumDriver<AppiumWebElement> CreateSession(PlatformName plat
4243
return driver;
4344
}
4445

45-
protected class CustomActionRetrier : ElementActionRetrier
46+
protected class CustomActionRetrier : ActionRetrier
4647
{
4748
private static readonly string[] handledErrorMessages = new string[]
4849
{
@@ -55,13 +56,18 @@ protected class CustomActionRetrier : ElementActionRetrier
5556
};
5657

5758
public CustomActionRetrier()
58-
: base(AqualityServices.Get<IRetryConfiguration>(), new[] { typeof(WebDriverException) })
59+
: base(AqualityServices.Get<IRetryConfiguration>())
5960
{
6061
}
6162

62-
protected override bool IsExceptionHandled(Exception exception)
63+
protected override bool IsExceptionHandled(IEnumerable<Type> handledExceptions, Exception exception)
6364
{
64-
return base.IsExceptionHandled(exception) && handledErrorMessages.Any(message => exception.Message.ToLower().Contains(message));
65+
var exceptions = new List<Type>(handledExceptions ?? new List<Type>())
66+
{
67+
typeof(WebDriverException)
68+
};
69+
return base.IsExceptionHandled(exceptions, exception)
70+
&& handledErrorMessages.Any(message => exception.Message.ToLower().Contains(message));
6571
}
6672
}
6773

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Aquality.Appium.Mobile.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
@@ -46,7 +46,7 @@
4646

4747
<ItemGroup>
4848
<PackageReference Include="Appium.WebDriver" Version="4.1.1" />
49-
<PackageReference Include="Aquality.Selenium.Core" Version="0.3.10" />
49+
<PackageReference Include="Aquality.Selenium.Core" Version="1.1.1" />
5050
</ItemGroup>
5151

5252
</Project>

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Aquality.Appium.Mobile.xml

Lines changed: 57 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Configurations/DeviceSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public AppiumOptions AppiumOptions
3838
}
3939
}
4040

41-
private IDictionary<string, object> Capabilities => settingsFile.GetValueOrNew<Dictionary<string, object>>($"{deviceKey}.capabilities");
41+
private IReadOnlyDictionary<string, object> Capabilities => settingsFile.GetValueDictionaryOrEmpty<object>($"{deviceKey}.capabilities");
4242
}
4343
}

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Configurations/DriverSettings.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ public DriverSettings(ISettingsFile settingsFile, PlatformName platformName)
2727

2828
private string ApplicationPathJPath => $"{DriverSettingsPath}.{ApplicationPathKey}";
2929

30-
protected IDictionary<string, object> Capabilities => settingsFile.GetValueOrNew<Dictionary<string, object>>($"{DriverSettingsPath}.capabilities");
30+
protected virtual IReadOnlyDictionary<string, object> Capabilities => settingsFile.GetValueDictionaryOrEmpty<object>($"{DriverSettingsPath}.capabilities");
3131

3232
/// <summary>
3333
/// Defines does the current settings have the application path defined
3434
/// </summary>
35-
protected bool HasApplicationPath => settingsFile.IsValuePresent(ApplicationPathJPath);
35+
protected virtual bool HasApplicationPath => settingsFile.IsValuePresent(ApplicationPathJPath) || Capabilities.ContainsKey(AppCapabilityKey);
3636

37-
public AppiumOptions AppiumOptions
37+
public virtual AppiumOptions AppiumOptions
3838
{
3939
get
4040
{
4141
var options = new AppiumOptions();
4242
Capabilities.ToList().ForEach(capability => options.AddAdditionalCapability(capability.Key, capability.Value));
43-
if (HasApplicationPath)
43+
if (HasApplicationPath && ApplicationPath != null)
4444
{
4545
options.AddAdditionalCapability(AppCapabilityKey, ApplicationPath);
4646
}
@@ -49,7 +49,15 @@ public AppiumOptions AppiumOptions
4949
}
5050
}
5151

52-
public string ApplicationPath => Path.GetFullPath(settingsFile.GetValue<string>(ApplicationPathJPath));
52+
public virtual string ApplicationPath
53+
{
54+
get
55+
{
56+
var appValue = settingsFile.GetValueOrDefault(ApplicationPathJPath,
57+
defaultValue: (Capabilities.ContainsKey(AppCapabilityKey) ? Capabilities[AppCapabilityKey] : null)?.ToString());
58+
return appValue?.StartsWith(".") == true ? Path.GetFullPath(appValue) : appValue;
59+
}
60+
}
5361

5462
private AppiumOptions DeviceOptions
5563
{

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Resources/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"driverSettings": {
88
"android": {
99
"deviceKey": "<KEY_OF_ANDROID_DEVICE_FROM_DEVICES_JSON>",
10-
"applicationPath": "./Resources/Apps/ApiDemos-debug.apk",
1110
"capabilities": {
11+
"app": "./Resources/Apps/ApiDemos-debug.apk",
1212
"platformName": "Android",
1313
"automationName": "UiAutomator2"
1414
}
1515
},
1616
"ios": {
1717
"deviceKey": "<KEY_OF_IOS_DEVICE_FROM_DEVICES_JSON>",
18-
"applicationPath": "./Resources/Apps/TestApp.app.zip",
1918
"capabilities": {
19+
"app": "./Resources/Apps/TestApp.app.zip",
2020
"platformName": "iOS",
2121
"automationName": "XCUITest"
2222
}

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Screens/Screen.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,61 @@
33
using Aquality.Selenium.Core.Elements.Interfaces;
44
using OpenQA.Selenium;
55
using System.Drawing;
6+
using IElement = Aquality.Appium.Mobile.Elements.Interfaces.IElement;
67
using IElementFactory = Aquality.Appium.Mobile.Elements.Interfaces.IElementFactory;
78

89
namespace Aquality.Appium.Mobile.Screens
910
{
11+
/// <summary>
12+
/// Defines base class for any mobile screen.
13+
/// Use <see cref="ScreenFactory.ScreenTypeAttribute"/> on your screen class to identify platform.
14+
/// <seealso cref="ScreenFactory.ScreenFactory"/>
15+
/// </summary>
1016
public abstract class Screen : IScreen
1117
{
1218
private readonly ILabel screenLabel;
1319

20+
/// <summary>
21+
/// Constructor with parameters.
22+
/// </summary>
23+
/// <param name="locator">Unique locator of the screen.</param>
24+
/// <param name="name">Name of the screen.</param>
1425
protected Screen(By locator, string name)
1526
{
1627
Locator = locator;
1728
Name = name;
1829
screenLabel = ElementFactory.GetLabel(locator, name);
1930
}
2031

32+
/// <summary>
33+
/// Gets Screen element defined by its locator and name.
34+
/// Could be used to find child elements relative to screen element.
35+
/// </summary>
36+
protected IElement ScreenElement => screenLabel;
37+
38+
/// <summary>
39+
/// Element factory <see cref="IElementFactory"/>
40+
/// </summary>
41+
protected static IElementFactory ElementFactory => AqualityServices.ElementFactory;
42+
43+
/// <summary>
44+
/// Locator of the screen.
45+
/// </summary>
2146
public By Locator { get; }
2247

48+
/// <summary>
49+
/// Name of the screen.
50+
/// </summary>
2351
public string Name { get; }
2452

53+
/// <summary>
54+
/// Gets size of form element defined by its locator.
55+
/// </summary>
2556
public Size Size => screenLabel.GetElement().Size;
2657

58+
/// <summary>
59+
/// Provides ability to get screen's state (whether it is displayed, exists or not) and respective waiting functions.
60+
/// </summary>
2761
public IElementStateProvider State => screenLabel.State;
28-
29-
protected IElementFactory ElementFactory => AqualityServices.ElementFactory;
3062
}
3163
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Aquality.Appium.Mobile.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PrivateAssets>all</PrivateAssets>
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Resources/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"driverSettings": {
88
"android": {
99
"deviceKey": "Android_Emulator",
10-
"applicationPath": "./Resources/Apps/ApiDemos-debug.apk",
1110
"capabilities": {
11+
"app": "./Resources/Apps/ApiDemos-debug.apk",
1212
"platformName": "Android",
1313
"automationName": "UIAutomator2",
1414
"eventTimings": true,
@@ -17,8 +17,8 @@
1717
},
1818
"ios": {
1919
"deviceKey": "iOS_Simulator",
20-
"applicationPath": "./Resources/Apps/TestApp.app.zip",
2120
"capabilities": {
21+
"app": "./Resources/Apps/TestApp.app.zip",
2222
"platformName": "iOS",
2323
"automationName": "XCUITest"
2424
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/NativeApp/ApiDemos/Screens/AndroidScreen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ protected AndroidScreen(By locator, string name) : base(locator, name)
2121
protected void StartActivity(string appPackage, string appActivity, bool stopApp = true)
2222
{
2323
AqualityServices.LocalizedLogger.Info("loc.application.android.activity.start", appPackage, appActivity);
24-
var adnroidAppiumDriver = (AndroidDriver<AppiumWebElement>) AqualityServices.Application.Driver;
25-
adnroidAppiumDriver.StartActivity(appPackage, appActivity, stopApp: stopApp);
24+
var androidAppiumDriver = (AndroidDriver<AppiumWebElement>) AqualityServices.Application.Driver;
25+
androidAppiumDriver.StartActivity(appPackage, appActivity, stopApp: stopApp);
2626
}
2727
}
2828
}

0 commit comments

Comments
 (0)