From 5918f9197d5809256b8751d777d4dc32cfee345d Mon Sep 17 00:00:00 2001 From: "Isaac A. Murchie" Date: Tue, 12 Nov 2019 16:55:32 -0500 Subject: [PATCH] fix: enable console logging on page after navigating --- lib/remote-debugger.js | 11 +++++++++- lib/rpc-client.js | 2 +- ...sage-handler.js => rpc-message-handler.js} | 0 test/functional/safari-e2e-specs.js | 22 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) rename lib/{remote-debugger-message-handler.js => rpc-message-handler.js} (100%) diff --git a/lib/remote-debugger.js b/lib/remote-debugger.js index 843d5681..f3feb551 100644 --- a/lib/remote-debugger.js +++ b/lib/remote-debugger.js @@ -172,7 +172,9 @@ class RemoteDebugger extends events.EventEmitter { } async disconnect () { - await this.rpcClient.disconnect(); + if (this.rpcClient) { + await this.rpcClient.disconnect(); + } this.emit(RemoteDebugger.EVENT_DISCONNECT, true); this.teardown(); } @@ -574,6 +576,13 @@ class RemoteDebugger extends events.EventEmitter { await this.waitForFrameNavigated(); await this.waitForDom(Date.now(), pageLoadVerifyHook); + + // enable console logging, so we get the events (otherwise we only + // get notified when navigating to a local page + await this.rpcClient.send('enableConsole', { + appIdKey: this.appIdKey, + pageIdKey: this.pageIdKey, + }); } finally { this._navigatingToPage = false; } diff --git a/lib/rpc-client.js b/lib/rpc-client.js index b032b98d..5973d0cb 100644 --- a/lib/rpc-client.js +++ b/lib/rpc-client.js @@ -4,7 +4,7 @@ import log from './logger'; import _ from 'lodash'; import B from 'bluebird'; import UUID from 'uuid-js'; -import RpcMessageHandler from './remote-debugger-message-handler'; +import RpcMessageHandler from './rpc-message-handler'; import { getElapsedTime } from './helpers'; import { util } from 'appium-support'; diff --git a/lib/remote-debugger-message-handler.js b/lib/rpc-message-handler.js similarity index 100% rename from lib/remote-debugger-message-handler.js rename to lib/rpc-message-handler.js diff --git a/test/functional/safari-e2e-specs.js b/test/functional/safari-e2e-specs.js index ce864ec7..9040cb65 100644 --- a/test/functional/safari-e2e-specs.js +++ b/test/functional/safari-e2e-specs.js @@ -177,4 +177,26 @@ describe('Safari remote debugger', function () { await rd.selectApp(address); }); + + it('should be able to get console logs from a remote page', async function () { + await connect(rd); + const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE); + const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10)); + await rd.selectPage(appIdKey, pageIdKey); + + let lines = []; + rd.startConsole(function (line) { + lines.push(line); + }); + + await rd.navToUrl('https://google.com'); + + await rd.executeAtom('execute_script', [`console.log('hi from appium')`, []], []); + + // wait for the asynchronous console event to come in + await retryInterval(50, 100, function () { + lines.length.should.be.at.least(1); + lines.filter((line) => line.text === 'hi from appium').length.should.eql(1); + }); + }); });