Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit a57ea86

Browse files
committed
feat: add ability to retrieve log events as a new api route
1 parent 52a1b03 commit a57ea86

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

lib/basedriver/commands/event.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,16 @@ commands.logCustomEvent = function (vendor, event) {
1111
this.logEvent(`${vendor}:${event}`);
1212
};
1313

14+
/**
15+
* Get the event log
16+
*
17+
* @param {string} type - currently unused but a placeholder for a future
18+
* feature where filtering of log events is allowed
19+
* @returns {object} - the event history log object
20+
*/
21+
commands.getLogEvents = function (/*type*/) {
22+
// type is currently unused but may be implemented for filtering later on
23+
return this._eventHistory;
24+
};
25+
1426
export default commands;

lib/protocol/routes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ const METHOD_MAP = {
586586
'/session/:sessionId/appium/execute_driver': {
587587
POST: {command: 'executeDriverScript', payloadParams: {required: ['script'], optional: ['type', 'timeout']}}
588588
},
589+
'/session/:sessionId/appium/events': {
590+
POST: {command: 'getLogEvents', payloadParams: {optional: ['type']}}
591+
},
589592
'/session/:sessionId/appium/log_event': {
590593
POST: {command: 'logCustomEvent', payloadParams: {required: ['vendor', 'event']}}
591594
},

test/basedriver/commands/event-specs.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ describe('logging custom events', function () {
1313
await d.logCustomEvent('myorg', 'myevent');
1414
_.keys(d._eventHistory).should.eql(['commands', 'myorg:myevent']);
1515
});
16+
it('should get all events including custom ones', async function () {
17+
const d = new BaseDriver();
18+
d._eventHistory.should.eql({commands: []});
19+
d.logEvent('appiumEvent');
20+
await d.logCustomEvent('myorg', 'myevent');
21+
const events = await d.getLogEvents();
22+
_.keys(events).should.eql(['commands', 'appiumEvent', 'myorg:myevent']);
23+
});
1624
});

test/protocol/routes-specs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('Protocol', function () {
4040
}
4141
let hash = shasum.digest('hex').substring(0, 8);
4242
// Modify the hash whenever the protocol has intentionally been modified.
43-
hash.should.equal('3e494ba9');
43+
hash.should.equal('1a27532d');
4444
});
4545
});
4646

0 commit comments

Comments
 (0)