Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable console logging on page after navigating #176

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/remote-debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ class RemoteDebugger extends events.EventEmitter {
}

async disconnect () {
await this.rpcClient.disconnect();
if (this.rpcClient) {
await this.rpcClient.disconnect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also set this.rpcClient to null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That happens in the teardown function, called later in this function.

}
this.emit(RemoteDebugger.EVENT_DISCONNECT, true);
this.teardown();
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rpc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions test/functional/safari-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});