feat: add ability to retrieve log events as a new api route
MODIFY
lib/basedriver/commands/event.js
lib/basedriver/commands/event.js
@@ -11,4 +11,16 @@ commands.logCustomEvent = function (vendor, event) {
this.logEvent(`${vendor}:${event}`);
};
+/**
+ * Get the event log
+ *
+ * @param {string} type - currently unused but a placeholder for a future
+ * feature where filtering of log events is allowed
+ * @returns {object} - the event history log object
+ */
+commands.getLogEvents = function (/*type*/) {
+ // type is currently unused but may be implemented for filtering later on
+ return this._eventHistory;
+};
+
export default commands;

MODIFY
lib/protocol/routes.js
lib/protocol/routes.js
@@ -586,6 +586,9 @@ const METHOD_MAP = {
'/session/:sessionId/appium/execute_driver': {
POST: {command: 'executeDriverScript', payloadParams: {required: ['script'], optional: ['type', 'timeout']}}
},
+ '/session/:sessionId/appium/events': {
+ POST: {command: 'getLogEvents', payloadParams: {optional: ['type']}}
+ },
'/session/:sessionId/appium/log_event': {
POST: {command: 'logCustomEvent', payloadParams: {required: ['vendor', 'event']}}
},

MODIFY
test/basedriver/commands/event-specs.js
test/basedriver/commands/event-specs.js
@@ -13,4 +13,12 @@ describe('logging custom events', function () {
await d.logCustomEvent('myorg', 'myevent');
_.keys(d._eventHistory).should.eql(['commands', 'myorg:myevent']);
});
+ it('should get all events including custom ones', async function () {
+ const d = new BaseDriver();
+ d._eventHistory.should.eql({commands: []});
+ d.logEvent('appiumEvent');
+ await d.logCustomEvent('myorg', 'myevent');
+ const events = await d.getLogEvents();
+ _.keys(events).should.eql(['commands', 'appiumEvent', 'myorg:myevent']);
+ });
});

MODIFY
test/protocol/routes-specs.js
test/protocol/routes-specs.js
@@ -40,7 +40,7 @@ describe('Protocol', function () {
}
let hash = shasum.digest('hex').substring(0, 8);
// Modify the hash whenever the protocol has intentionally been modified.
- hash.should.equal('3e494ba9');
+ hash.should.equal('1a27532d');
});
});

feat: add ability to retrieve log events as a new api route (#365)