I was working on integrating Lighthouse into my CD pipeline.
Sadly we're running our build & test scripts on a VM with no displays/browsers, so for our tests like webdriverIO & WCT we use a selenium grid.
But as far as I can tell it's not possible with Lighthouse to use something else than the standard Chromedriver?
If it's possible to test with Selenium (ofcourse only chrome) do you have an example or else is it something that is technically possible or not feasible at all in the current situation?
Great to see you're working to include Lighthouse as part of your CD!
You're correct it's not really supported to use selenium as the driver for Lighthouse as we currently need a direct connection to Chrome (I'm not a selenium expert, but if it's possible to send raw commands or get hold of the websocket that selenium is using to communicate with the browser you might be able to get it to work with some modifications to LH). However, all is not lost!
You can still run lighthouse on a VM without a display, in fact, that's how we test Lighthouse on travis. If you have this level of control take a look at our travis config and the download chrome script to see if something similar would work for you.
I believe @gauntface has some setup with lighthouse/selenium working. He can advise on if it's worth it :)
Nah - I use some helpers to download chrome that I use with my selenium flow but thats it.
I think Selenium uses the Chrome debug protocol which Lighthouse needs to control Chrome - as a result it's one or the other.
@patrickhulce Thanks for the feedback, luckily we do have full control of the VM's, so we'll just setup a display for chrome for now (same as we do for our selenium grid).
just to confirm,
there's currently no way that selenium can hand over control to lighthouse, as chromedriver doesn't support proxying raw protocol commands, and we'd need that.
It's possible it'll have support for this in the future, but it'll be some time.
@Bubbit @gauntface can you please share you setup info in a blog ?
I also have requirement to use Lighthouse in CD pipeline. Thanks in advance.
@Bubbit
I am able to pass off browser control from Selenium Webdriver to Lighthouse by passing the port that Webdriver randomly chooses:
lighthouse(appUrl, {port: remoteDebuggingPort});
I get "remoteDebuggingPort" by parsing the content of "chrome://version/" using Webdriver to find the value of "--remote-debugging-port" flag (definitely a hacky solution but I can't find any other way to get this value). My workflow is that I authenticate into a web application using Selenium and then pass off the session to Lighthouse, and this setup seems to work well.
However, this only seems to work locally, I am not able to do the same thing using Selenium Grid. I wonder what sort of hacks would be needed to get this to work...
@kyoheiyazawa
When i launch chrome via selenium, the remote debugging port is 0 every time. when I pass --port 0 in lighthouse, it ignores this option and opens another chrome instance. Could you share more about your implementation?
@atariq6298 port=0 generally means, pick a randomly available port. You'll need to pass the port that selenium picked to LH
Am also stuck at the same place as @kyoheiyazawa ( Selenium Grid Part ), do we have any alternate solution for this ?
When using Selenium Grid the browser will not be on your localhost so you also need to pass the hostname to lighthouse, I'm not super familiar with how to get this information when using selenium grid, but once you know the IP/hostname
```
lighthouse(appUrl, {port: remoteDebuggingPort, hostname: remoteHostIp});
Thanks for the solution @patrickhulce ,
We have our Automation infra setup on GCP - K8s with IP of grid exposed, but it fails with error on using the IP : Error: getaddrinfo ENOTFOUND
@ankurgpt6719 are you including the protocol by accident? It should just be the hostname itself, see https://stackoverflow.com/a/28385129/1091925
@ankurgpt6719
I use selenium option's option "--remote-debugging port" to specify the debugging port:
const Chrome = require("selenium-webdriver/chrome");
driver = await new Builder().forBrowser("chrome").setChromeOptions(new Chrome.Options().addArguments("--remote-debugging-port=" + Port).addArguments("--disable-infobars")).build();
await driver.get(URL);
Then i run lighthouse audit on the same port:
//define url you want to audit and use debugging port "Port"
const results= await lighthouse(url, { port: Port,config }).then(results => {
return results;
});
@atariq6298
I was able to retrieve the URL with selenium, can you help how do i run the lighthouse test.
Most helpful comment
@Bubbit
I am able to pass off browser control from Selenium Webdriver to Lighthouse by passing the port that Webdriver randomly chooses:
lighthouse(appUrl, {port: remoteDebuggingPort});I get "remoteDebuggingPort" by parsing the content of "chrome://version/" using Webdriver to find the value of "--remote-debugging-port" flag (definitely a hacky solution but I can't find any other way to get this value). My workflow is that I authenticate into a web application using Selenium and then pass off the session to Lighthouse, and this setup seems to work well.
However, this only seems to work locally, I am not able to do the same thing using Selenium Grid. I wonder what sort of hacks would be needed to get this to work...