Skip to content

Commit 7a7dff8

Browse files
authored
Merge pull request #13 from pictos/pj/update-code-to-match-21305
Update files to match .NET MAUI implementation
2 parents 6ef4fe9 + 44b3136 commit 7a7dff8

File tree

10 files changed

+859
-21
lines changed

10 files changed

+859
-21
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using OpenQA.Selenium.Appium;
2+
using Plugin.Maui.UITestHelpers.Core;
3+
4+
namespace Plugin.Maui.UITestHelpers.Appium
5+
{
6+
public class AppiumCatalystMouseActions : ICommandExecutionGroup
7+
{
8+
const string DoubleClickCommand = "doubleClick";
9+
10+
readonly List<string> _commands = new()
11+
{
12+
DoubleClickCommand,
13+
};
14+
readonly AppiumApp _appiumApp;
15+
16+
public AppiumCatalystMouseActions(AppiumApp appiumApp)
17+
{
18+
_appiumApp = appiumApp;
19+
}
20+
21+
public bool IsCommandSupported(string commandName)
22+
{
23+
return _commands.Contains(commandName, StringComparer.OrdinalIgnoreCase);
24+
}
25+
26+
public CommandResponse Execute(string commandName, IDictionary<string, object> parameters)
27+
{
28+
return commandName switch
29+
{
30+
DoubleClickCommand => DoubleClick(parameters),
31+
_ => CommandResponse.FailedEmptyResponse,
32+
};
33+
}
34+
35+
CommandResponse DoubleClick(IDictionary<string, object> parameters)
36+
{
37+
var element = GetAppiumElement(parameters["element"]);
38+
39+
if (element != null)
40+
{
41+
_appiumApp.Driver.ExecuteScript("macos: doubleClick", new Dictionary<string, object>
42+
{
43+
{ "elementId", element.Id },
44+
});
45+
}
46+
return CommandResponse.SuccessEmptyResponse;
47+
}
48+
49+
static AppiumElement? GetAppiumElement(object element)
50+
{
51+
if (element is AppiumElement appiumElement)
52+
{
53+
return appiumElement;
54+
}
55+
else if (element is AppiumDriverElement driverElement)
56+
{
57+
return driverElement.AppiumElement;
58+
}
59+
60+
return null;
61+
}
62+
}
63+
}

src/Plugin.Maui.UITestHelpers.Appium/Actions/AppiumCatalystPointerActions.cs renamed to src/Plugin.Maui.UITestHelpers.Appium/Actions/AppiumCatalystTouchActions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
namespace Plugin.Maui.UITestHelpers.Appium
55
{
6-
public class AppiumCatalystPointerActions : ICommandExecutionGroup
6+
public class AppiumCatalystTouchActions : ICommandExecutionGroup
77
{
8-
const string DoubleClickCommand = "doubleClick";
8+
const string DoubleTapCommand = "doubleTap";
99
const string DragAndDropCommand = "dragAndDrop";
1010

1111
readonly List<string> _commands = new()
1212
{
13-
DoubleClickCommand,
13+
DoubleTapCommand,
1414
DragAndDropCommand,
1515
};
1616
readonly AppiumApp _appiumApp;
1717

18-
public AppiumCatalystPointerActions(AppiumApp appiumApp)
18+
public AppiumCatalystTouchActions(AppiumApp appiumApp)
1919
{
2020
_appiumApp = appiumApp;
2121
}
@@ -29,13 +29,13 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
2929
{
3030
return commandName switch
3131
{
32-
DoubleClickCommand => DoubleClick(parameters),
32+
DoubleTapCommand => DoubleTap(parameters),
3333
DragAndDropCommand => DragAndDrop(parameters),
3434
_ => CommandResponse.FailedEmptyResponse,
3535
};
3636
}
3737

38-
CommandResponse DoubleClick(IDictionary<string, object> parameters)
38+
CommandResponse DoubleTap(IDictionary<string, object> parameters)
3939
{
4040
var element = GetAppiumElement(parameters["element"]);
4141

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using OpenQA.Selenium.Appium;
2+
using Plugin.Maui.UITestHelpers.Core;
3+
4+
5+
namespace Plugin.Maui.UITestHelpers.Appium
6+
{
7+
public class AppiumIOSMouseActions : ICommandExecutionGroup
8+
{
9+
const string DoubleClickCommand = "doubleClick";
10+
11+
readonly List<string> _commands = new()
12+
{
13+
DoubleClickCommand,
14+
};
15+
readonly AppiumApp _appiumApp;
16+
17+
public AppiumIOSMouseActions(AppiumApp appiumApp)
18+
{
19+
_appiumApp = appiumApp;
20+
}
21+
22+
public bool IsCommandSupported(string commandName)
23+
{
24+
return _commands.Contains(commandName, StringComparer.OrdinalIgnoreCase);
25+
}
26+
27+
public CommandResponse Execute(string commandName, IDictionary<string, object> parameters)
28+
{
29+
return commandName switch
30+
{
31+
DoubleClickCommand => DoubleClick(parameters),
32+
_ => CommandResponse.FailedEmptyResponse,
33+
};
34+
}
35+
36+
CommandResponse DoubleClick(IDictionary<string, object> parameters)
37+
{
38+
var element = GetAppiumElement(parameters["element"]);
39+
40+
if (element != null)
41+
{
42+
_appiumApp.Driver.ExecuteScript("mobile: doubleTap", new Dictionary<string, object>
43+
{
44+
{ "elementId", element.Id },
45+
});
46+
}
47+
48+
return CommandResponse.SuccessEmptyResponse;
49+
}
50+
51+
static AppiumElement? GetAppiumElement(object element)
52+
{
53+
if (element is AppiumElement appiumElement)
54+
{
55+
return appiumElement;
56+
}
57+
else if (element is AppiumDriverElement driverElement)
58+
{
59+
return driverElement.AppiumElement;
60+
}
61+
62+
return null;
63+
}
64+
}
65+
}

src/Plugin.Maui.UITestHelpers.Appium/Actions/AppiumIOSPointerActions.cs renamed to src/Plugin.Maui.UITestHelpers.Appium/Actions/AppiumIOSTouchActions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
namespace Plugin.Maui.UITestHelpers.Appium
55
{
6-
public class AppiumIOSPointerActions : ICommandExecutionGroup
6+
public class AppiumIOSTouchActions : ICommandExecutionGroup
77
{
8-
const string DoubleClickCommand = "doubleClick";
8+
const string DoubleTapCommand = "doubleTap";
99
const string DragAndDropCommand = "dragAndDrop";
1010

1111
readonly List<string> _commands = new()
1212
{
13-
DoubleClickCommand,
13+
DoubleTapCommand,
1414
DragAndDropCommand
1515
};
1616
readonly AppiumApp _appiumApp;
1717

18-
public AppiumIOSPointerActions(AppiumApp appiumApp)
18+
public AppiumIOSTouchActions(AppiumApp appiumApp)
1919
{
2020
_appiumApp = appiumApp;
2121
}
@@ -29,13 +29,13 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
2929
{
3030
return commandName switch
3131
{
32-
DoubleClickCommand => DoubleClick(parameters),
32+
DoubleTapCommand => DoubleTap(parameters),
3333
DragAndDropCommand => DragAndDrop(parameters),
3434
_ => CommandResponse.FailedEmptyResponse,
3535
};
3636
}
3737

38-
CommandResponse DoubleClick(IDictionary<string, object> parameters)
38+
CommandResponse DoubleTap(IDictionary<string, object> parameters)
3939
{
4040
var element = GetAppiumElement(parameters["element"]);
4141

0 commit comments

Comments
 (0)