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

Pass remote debugging port for chrome #39

Merged
merged 4 commits into from
Jul 3, 2018

Conversation

anil-alt
Copy link
Contributor

@anil-alt anil-alt commented Jun 25, 2018

Set '--remote-debugging-port' in testium config, which would be consumed by lighthouse to talk with testium.

Line of Thought:

Step 1: [Indidvidual apps] Add flag --remote-debugging-port to .testiumrc in the App's repo

Step 2: [testium-core] Use this flag to pass to chromedriver/chrome by either directly using the port number or by finding next available port. Also update the testium property, if new port number was used

Step 3: [testium-driver-wd] Add getPort method as wd chain methods to fetch the testium property

  wd.addPromiseChainMethod('getPort', function getPort() {
    let debugPort = testium.config.get('chrome.--remote-debugging-port');
    debug('Remote dubugging port set as', debugPort);
    return debugPort;
  });

Step 4: [Individual apps or itier-accessibility] Port fetch from browser.getPort would be used to pass it to lighthouse

 browser.getPort()
    .then(port => lighthouse(url, Object.assign({}, opts, { port }), config))
    .then(results => new Promise(res => res(results.audits)));

lib/processes.js Outdated
if (debugPort) {
findOpenPort().then(function (port) {
args.push('--remote-debugging-port=' + port);
config.set('chrome.--remote-debugging-port', port);
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a weird name for an option. Why not remoteDebuggingPort?

lib/processes.js Outdated
@@ -97,6 +97,15 @@ function launchAllProcesses(config) {
args.push('--headless');
}
if (process.getuid() === 0) args.push('--no-sandbox');

var debugPort = config.get('chrome.--remote-debugging-port');
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why this isn't the default? It feels weird that people have to opt-in to enable this feature..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you mean to always pass the port and set in the config? If yes, this was my initial thought -
In most cases, port number won't be used in the tests. Also, I was not very sure that, if we should always set the port even if it would be assigned by chromedriver.

But it makes sense now, if we are exposing API like getPort from testium. We should make it return in consistent way

Copy link
Member

Choose a reason for hiding this comment

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

IIRC there was some chat to just always read it from the port file written by Chrome. Didn't that work out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jkrems Unfortunately, that didn't work. Not sure if that was due to system issue (some process errors out writing to hidden directory/files). Looking at chromelauncher code, this option didn't seem bad to me :)

Copy link
Member

Choose a reason for hiding this comment

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

So setting this option is compatible with chromedriver after all? If so - SGTM. Is there any way we can verify that Chrome has in fact been started with that option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Captured this SS from activity Monitor for the chrome instance. Port number generated programmatically was- 59196. Not sure, if anything is obvious here :(

screen shot 2018-07-02 at 6 14 09 pm

@jkrems
Copy link
Member

jkrems commented Jul 2, 2018

Some thoughts:

  1. I think browser.getChromeDevtoolsPort() should just work when using chrome. Having to remember to set a global option seems like it would lead to confusion in the future.
  2. Implied in 1: I think .getPort is a little too generic for what that method does.
  3. I think testium.getChromeDevtoolsPort() should exist and throw a helpful error message when trying to use it outside of Chrome. Accessing the config directly from -wd makes it harder to tell where things are going wrong.

In the future I would hope that we could even get a driver instance exposed from testium so that we can reuse more logic. AFAICT it should be possible to create a reusable connection (e.g. that could be used to implement better/more reliable APIs) outside of lighthouse and pass that in. So hopefully a future API would be testium.getChromeDevtoolsConnection() rather than ...Port().

@anil-alt
Copy link
Contributor Author

anil-alt commented Jul 2, 2018

@jkrems What is the best place to add getChromeDevtoolsPort method? So far, I was thinking to add in testium-driver-wd

@jkrems
Copy link
Member

jkrems commented Jul 3, 2018

I think the "real" implementation should definitely live in -core. We can expose it from -wd but I wouldn't want it to have deep knowledge about how it's implemented. So I'd prefer the -wd implementation to be not much more than return testium.getChromeDevtoolsPort();. That way we have all the pieces in one place and can iterate here without having to keep changes in sync.

@anil-alt
Copy link
Contributor Author

anil-alt commented Jul 3, 2018

@jkrems addressed the comments in last commit, except throwing error in the case port is not set. Should we just log the message for the failure case?

lib/processes.js Outdated
@@ -97,6 +103,17 @@ function launchAllProcesses(config) {
args.push('--headless');
}
if (process.getuid() === 0) args.push('--no-sandbox');

var debugPort = config.get('chrome.remoteDebuggingPort', null);
Copy link
Member

Choose a reason for hiding this comment

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

Since this already runs only when we're using chrome - any reason not to default this to true instead of 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.

@jkrems This assumes that if the port has been set (with actual value) in .testiumrc, it would address that. Otherwise would discover the new port and update the config.

Are you suggesting that to remove the check and find new port anyway?

Copy link
Member

Choose a reason for hiding this comment

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

Is there value in making the port configurable? That seems to encourage hard-coding values which might lead to problems when running multiple test suites etc..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes. I didn't think about that. I'll remove the checks

Copy link
Member

@jkrems jkrems left a comment

Choose a reason for hiding this comment

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

One question, otherwise LGTM

lib/init.js Outdated
testium = {
close: close,
config: config,
getInitialUrl: getInitialUrl,
getNewPageUrl: _.partial(getNewPageUrl, config.get('proxy.targetUrl'))
getNewPageUrl: _.partial(getNewPageUrl, config.get('proxy.targetUrl')),
getChromeDevtoolsPort: getChromeDevtoolsPort
Copy link
Member

Choose a reason for hiding this comment

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

nit: it looks like those were sorted alphabetically before.

Copy link
Member

@jkrems jkrems left a comment

Choose a reason for hiding this comment

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

🎉

@jkrems jkrems changed the title feat: Pass remote debugging port for chrome Pass remote debugging port for chrome Jul 3, 2018
@jkrems
Copy link
Member

jkrems commented Jul 3, 2018

Thanks for digging into this & sorry for the long back-and-forth! :)

@jkrems jkrems merged commit decfd60 into testiumjs:master Jul 3, 2018
@anil-alt anil-alt deleted the pass-debug-port branch July 3, 2018 21:22
@anil-alt
Copy link
Contributor Author

anil-alt commented Jul 3, 2018

@jkrems Thanks for the review :)

How do I release new version now? I believe one with 'write access' can do

@jkrems
Copy link
Member

jkrems commented Jul 3, 2018

These libraries are under nlm, so the new version got released once this got merged!

jkrems pushed a commit that referenced this pull request Jul 5, 2018
jkrems added a commit that referenced this pull request Jul 5, 2018
Revert "Merge pull request #39 from anil-groupon/pass-debug-port"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants