feat: add new route to allow logging of custom events
ADD
lib/basedriver/commands/event.js
+const commands = {};
+
+/**
+ * Log a user-defined event in the event log.
+ *
+ * @param {string} vendor - a vendor prefix for the user, to ensure namespace
+ * separation
+ * @param {string} event - the event name
+ */
+commands.logCustomEvent = function (vendor, event) {
+ this.logEvent(`${vendor}:${event}`);
+};
+
+export default commands;

MODIFY
lib/basedriver/commands/index.js
lib/basedriver/commands/index.js
@@ -5,6 +5,7 @@ import findCmds from './find';
import logCmds from './log';
import imagesCmds from './images';
import executeCmds from './execute';
+import eventCmds from './event';
let commands = {};
@@ -18,6 +19,7 @@ Object.assign(
logCmds,
imagesCmds,
executeCmds,
+ eventCmds,
// add other command types here
);

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/log_event': {
+ POST: {command: 'logCustomEvent', payloadParams: {required: ['vendor', 'event']}}
+ },
/*

ADD
test/basedriver/commands/event-specs.js
+import _ from 'lodash';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { BaseDriver } from '../../..';
+
+
+chai.use(chaiAsPromised);
+
+describe('logging custom events', function () {
+ it('should allow logging of events', async function () {
+ const d = new BaseDriver();
+ d._eventHistory.should.eql({commands: []});
+ await d.logCustomEvent('myorg', 'myevent');
+ _.keys(d._eventHistory).should.eql(['commands', '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('f46dc0b1');
+ hash.should.equal('3e494ba9');
});
});

feat: add new route to allow logging of custom events (#364)