Skip to content

Commit 55eaf7c

Browse files
author
Pavel Anihimovsky
committed
Merge branch 'master' of github.com:aquality-automation/aquality-appium-mobile-dotnet
2 parents 03df1a9 + c4fefa3 commit 55eaf7c

File tree

14 files changed

+68
-111
lines changed

14 files changed

+68
-111
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class AqualityServices : AqualityServices<IMobileApplication>
5858
/// <summary>
5959
/// Gets factory to create screens.
6060
/// </summary>
61-
public static IScreenFactory ScreenFactory => Get<IScreenFactoryProvider>().ScreenFactory;
61+
public static IScreenFactory ScreenFactory => Get<IScreenFactory>();
6262

6363
/// <summary>
6464
/// Resolves required service from <see cref="ServiceProvider"/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override IServiceCollection ConfigureServices(IServiceCollection services
2727
services.AddTransient<CoreElementFactory, ElementFactory>();
2828
services.AddSingleton<IApplicationProfile, ApplicationProfile>();
2929
services.AddSingleton<ILocalServiceSettings, LocalServiceSettings>();
30-
services.AddSingleton<IScreenFactoryProvider, ScreenFactoryProvider>();
30+
services.AddSingleton<IScreenFactory, ScreenFactory>();
3131
services.AddSingleton<ILocalizationManager>(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService<ILoggerConfiguration>(), serviceProvider.GetRequiredService<Logger>(), Assembly.GetExecutingAssembly()));
3232
services.AddTransient(serviceProvider => AqualityServices.ApplicationFactory);
3333
services.AddScoped(serviceProvider => applicationProvider(serviceProvider) as IMobileApplication);

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
using Aquality.Appium.Mobile.Elements.Interfaces;
33
using Aquality.Selenium.Core.Elements.Interfaces;
44
using OpenQA.Selenium;
5-
using OpenQA.Selenium.Appium;
6-
using System;
75
using System.Drawing;
86
using IElementFactory = Aquality.Appium.Mobile.Elements.Interfaces.IElementFactory;
97

108
namespace Aquality.Appium.Mobile.Screens
119
{
12-
public abstract class Screen<T> : IScreen
13-
where T : AppiumDriver<AppiumWebElement>
10+
public abstract class Screen : IScreen
1411
{
1512
private readonly ILabel screenLabel;
1613

@@ -21,23 +18,6 @@ protected Screen(By locator, string name)
2118
screenLabel = ElementFactory.GetLabel(locator, name);
2219
}
2320

24-
protected T Driver
25-
{
26-
get
27-
{
28-
var currentPlatform = AqualityServices.Application.PlatformName;
29-
if (PlatformName != currentPlatform)
30-
{
31-
throw new InvalidOperationException("Cannot perform this operation. " +
32-
$"Current platform {currentPlatform} don't match to target {PlatformName}");
33-
}
34-
35-
return (T) AqualityServices.Application.Driver;
36-
}
37-
}
38-
39-
protected abstract PlatformName PlatformName { get; }
40-
4121
public By Locator { get; }
4222

4323
public string Name { get; }

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Screens/ScreenFactory/AndroidScreenFactory.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Screens/ScreenFactory/IOSScreenFactory.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Screens/ScreenFactory/IScreenFactoryProvider.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Aquality.Appium.Mobile.Applications;
2+
using Aquality.Appium.Mobile.Configurations;
23
using System;
34
using System.IO;
45
using System.Linq;
@@ -7,12 +8,17 @@
78
namespace Aquality.Appium.Mobile.Screens.ScreenFactory
89
{
910
/// <summary>
10-
/// Abstract screen factory.
11+
/// Screen factory.
1112
/// </summary>
12-
/// <typeparam name="TPlatformScreen">Desired platform screen <see cref="IOSScreen"/> or <see cref="AndroidScreen"/></typeparam>
13-
public abstract class ScreenFactory<TPlatformScreen> : IScreenFactory
14-
where TPlatformScreen : class
13+
public class ScreenFactory : IScreenFactory
1514
{
15+
private readonly IApplicationProfile applicationProfile;
16+
17+
public ScreenFactory(IApplicationProfile applicationProfile)
18+
{
19+
this.applicationProfile = applicationProfile;
20+
}
21+
1622
/// <summary>
1723
/// Returns an implementation of a particular app screen.
1824
/// </summary>
@@ -25,8 +31,14 @@ public TAppScreen GetScreen<TAppScreen>()
2531
{
2632
screenType = Assembly.Load(AqualityServices.ApplicationProfile.ScreensLocation)
2733
.GetTypes()
28-
.Where(t => t.GetInterfaces().Contains(typeof(TAppScreen)))
29-
.SingleOrDefault(t => t.IsSubclassOf(typeof(TPlatformScreen)));
34+
.Where(t => t.IsSubclassOf(typeof(TAppScreen)))
35+
.Where(t => t.IsDefined(typeof(ScreenTypeAttribute), false))
36+
.SingleOrDefault(t =>
37+
{
38+
var attribute = (ScreenTypeAttribute) Attribute.GetCustomAttribute(t, typeof(ScreenTypeAttribute));
39+
return attribute.Platform == applicationProfile.PlatformName;
40+
});
41+
3042
}
3143
catch (FileNotFoundException ex)
3244
{

Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Screens/ScreenFactory/ScreenFactoryProvider.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Aquality.Appium.Mobile.Applications;
2+
using System;
3+
4+
namespace Aquality.Appium.Mobile.Screens.ScreenFactory
5+
{
6+
/// <summary>
7+
/// Attribute that identifies platform of screen.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Class)]
10+
public class ScreenTypeAttribute : Attribute
11+
{
12+
public ScreenTypeAttribute(PlatformName platformName)
13+
{
14+
Platform = platformName;
15+
}
16+
17+
/// <summary>
18+
/// Name of platform that screen relates to.
19+
/// </summary>
20+
public PlatformName Platform { get; }
21+
}
22+
}

0 commit comments

Comments
 (0)