Skip to content

Commit aaec938

Browse files
authored
feat: add events endpoint calls (#913)
* add initial new command names * add methods * add brief docs * fix spaces * fix spaces * revert tests * remove extra new line * add test * Update EventsTests.cs
1 parent d8bbbe7 commit aaec938

File tree

4 files changed

+136
-7
lines changed

4 files changed

+136
-7
lines changed

src/Appium.Net/Appium/AppiumCommand.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class AppiumCommand
147147
"/session/{sessionId}/appium/device/finger_print"),
148148

149149
#endregion Driver Commands
150-
150+
151151

152152
// Enable W3C Actions on AppiumWebDriver
153153

@@ -211,13 +211,24 @@ public class AppiumCommand
211211

212212
#endregion
213213

214+
#region Logs
215+
214216
new AppiumCommand(HttpCommandInfo.GetCommand, DriverCommand.GetAvailableLogTypes,
215217
"session/{sessionId}/log/types"),
216-
new AppiumCommand(HttpCommandInfo.PostCommand, DriverCommand.GetLog, "session/{sessionId}/log")
218+
new AppiumCommand(HttpCommandInfo.PostCommand, DriverCommand.GetLog, "session/{sessionId}/log"),
219+
220+
#endregion
221+
222+
#region Event logs
223+
224+
new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.GetEvents, "session/{sessionId}/appium/events"),
225+
new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.LogEvent, "session/{sessionId}/appium/log_event")
226+
227+
#endregion
217228
};
218229

219230
/// <summary>
220-
/// This method adds Appium-specific commands to the given
231+
/// This method adds Appium-specific commands to the given
221232
/// CommandInfoRepository
222233
/// </summary>
223234
/// <param name="repo">is a CommandInfoRepository instance which is used</param>
@@ -234,12 +245,12 @@ internal static ICommandExecutor Merge(ICommandExecutor repo)
234245
}
235246

236247
/// <summary>
237-
/// command type
248+
/// command type
238249
/// </summary>
239250
internal readonly string CommandType;
240251

241252
/// <summary>
242-
/// Command
253+
/// Command
243254
/// </summary>
244255
internal readonly string CommandName;
245256

src/Appium.Net/Appium/AppiumDriver.cs

+43-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void RemoveApp(string appId) =>
148148

149149
public void ActivateApp(string appId) =>
150150
Execute(AppiumDriverCommand.ActivateApp, AppiumCommandExecutionHelper.PrepareArgument("appId", appId));
151-
151+
152152
public void ActivateApp(string appId, TimeSpan timeout) =>
153153
Execute(AppiumDriverCommand.ActivateApp,
154154
AppiumCommandExecutionHelper.PrepareArguments(new string[] {"appId", "options"},
@@ -508,7 +508,7 @@ public FeaturesMatchingResult MatchImageFeatures(string base64Image1, string bas
508508
}
509509

510510
/// <summary>
511-
/// Performs images matching by template to find possible occurrence of
511+
/// Performs images matching by template to find possible occurrence of
512512
/// the partial image in the full image with default options. Read
513513
/// https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html
514514
/// for more details on this topic.
@@ -567,6 +567,47 @@ public SimilarityMatchingResult GetImagesSimilarity(string base64Image1, string
567567

568568
#endregion Compare Images
569569

570+
#region Event logs
571+
572+
/// <summary>
573+
/// Retrieves events information from the current session.
574+
/// See https://appium.io/docs/en/latest/guides/event-timing/ also.
575+
/// </summary>
576+
/// <param name="type">key name to filter with. It can be empty, string or an array of keys. </param>
577+
/// <returns>A dictionary of events timing information containing the following entries</returns>
578+
public Dictionary<string, object> GetEvents(string type)
579+
{
580+
return this.GetEvents([type]);
581+
}
582+
583+
public Dictionary<string, object> GetEvents(string[] type = null)
584+
{
585+
Dictionary<string, object> parameters = new Dictionary<string, object>();
586+
if (type != null)
587+
{
588+
parameters.Add("type", type);
589+
}
590+
return (Dictionary<string, object>)Execute(AppiumDriverCommand.GetEvents, parameters).Value;
591+
}
592+
593+
/// <summary>
594+
/// Log a custom event on the Appium server.
595+
/// See https://appium.io/docs/en/latest/guides/event-timing/ also.
596+
/// </summary>
597+
/// <param name="vendorName">The vendor to log. </param>
598+
/// <param name="eventName">The event to log. </param>
599+
public void LogEvent(string vendorName, string eventName)
600+
{
601+
Dictionary<string, object> parameters = new Dictionary<string, object>
602+
{
603+
{ "vendor", vendorName },
604+
{ "event", eventName }
605+
};
606+
Execute(AppiumDriverCommand.LogEvent, parameters);
607+
}
608+
609+
#endregion Event logs
610+
570611
#endregion Public Methods
571612

572613
#region Support methods

src/Appium.Net/Appium/AppiumDriverCommand.cs

+14
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,19 @@ public class AppiumDriverCommand
313313
public const string CompareImages = "compareImages";
314314

315315
#endregion
316+
317+
#region Event logs
318+
319+
/// <summary>
320+
/// Represents the GetEvents command
321+
/// </summary>
322+
public static readonly string GetEvents = "getEvents";
323+
324+
/// <summary>
325+
/// Represents the LogEvent command
326+
/// </summary>
327+
public static readonly string LogEvent = "logEvent";
328+
329+
#endregion
316330
}
317331
}
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Appium.Net.Integration.Tests.helpers;
2+
using NUnit.Framework;
3+
using OpenQA.Selenium.Appium.Android;
4+
using OpenQA.Selenium.Support.UI;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
9+
namespace Appium.Net.Integration.Tests.Android
10+
{
11+
public class EventTests
12+
{
13+
private AndroidDriver _driver;
14+
15+
private readonly string _appKey = "androidApiDemos";
16+
17+
[OneTimeSetUp]
18+
public void BeforeAll()
19+
{
20+
var capabilities = Env.ServerIsRemote()
21+
? Caps.GetAndroidUIAutomatorCaps(Apps.Get(_appKey))
22+
: Caps.GetAndroidUIAutomatorCaps(Apps.Get(_appKey));
23+
var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;
24+
_driver = new AndroidDriver(serverUri, capabilities, Env.InitTimeoutSec);
25+
}
26+
27+
[Test]
28+
public void GetEventsTestCase()
29+
{
30+
object value;
31+
_driver.GetEvents().TryGetValue("commands", out value);
32+
Assert.That(value, Is.Not.Null);
33+
}
34+
35+
[Test]
36+
public void LogEventTestCase()
37+
{
38+
object value;
39+
40+
_driver.GetEvents().TryGetValue("appium:hello", out value);
41+
Assert.That(value, Is.Null);
42+
43+
_driver.LogEvent("appium", "hello");
44+
45+
_driver.GetEvents().TryGetValue("appium:hello", out value);
46+
Assert.That(value, Is.Not.Null);
47+
}
48+
49+
[OneTimeTearDown]
50+
public void AfterAll()
51+
{
52+
if (_driver != null)
53+
{
54+
_ = _driver.TerminateApp(Apps.GetId(_appKey));
55+
_driver?.Quit();
56+
}
57+
if (!Env.ServerIsRemote())
58+
{
59+
AppiumServers.StopLocalService();
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)