sitespeedio / sitespeed.io

sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your website’s speed using real browsers in various environments.
https://www.sitespeed.io/
MIT License
4.75k stars 602 forks source link

How to add ChromeOptions and DesiredCapabilities in sitespeed? #3704

Closed harinsai closed 10 months ago

harinsai commented 2 years ago

Your question

Hi,

We have a desktop application developed in electron app framework. The framework is designed to create desktop applications using web technologies which are rendered using a flavor of the Chromium browser engine, and a backend using the Node.js runtime environment. We are opening the application by executing an exe file and the window will open up.

We are able to invoke the application and perform the scenarios using WebDriver by adding ChromeOptions and DesiredCapabilities.

Code :

import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.*;

System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); ChromeOptions options1 = new ChromeOptions(); options1.setBinary("Complete path\sample.exe"); DesiredCapabilities cap = DesiredCapabilities.chrome(); WebDriver driver = new ChromeDriver(options1);

But when we tried to do the same in sitespeed its failing. We have tried to add the chromedriverPath and binaryPath in the config.json as well as in the console. But the application is not getting invoked and only the chrome browser is getting opened.

Config.json

{ "browsertime": { "chromedriverPath": "completepath\chromedriver.exe", "binaryPath":"completepath\sample.exe" }

}

Command line - node sitespeed.js --binaryPath:"completepath\sample.exe" -n 1 sample.js --multi

I am referring the https://beenanner.github.io/sitespeed.io/documentation/browsertime/configuration/ document.

How to add ChromeOptions and DesiredCapabilities in sitespeed.io? Do we have any document with examples how to use binaryPath and chromedriverPath parametes?

Thanks in advance.

Regards, Harin

soulgalore commented 2 years ago

Hi @harinsai they should just work, but they are in the chrome name space so if you add them to a config file it needs to look like this:

{
"browsertime":
  {
    "chrome": { 
      "chromedriverPath": "completepath\chromedriver.exe",
      "binaryPath":"completepath\sample.exe"
      }
   }
}

Or by command-line (using your example): node sitespeed.js --browsertime.chrome.binaryPath:"completepath\sample.exe" -n 1 sample.js --multi

Best Peter

harinsai commented 2 years ago

Hi @soulgalore Thanks for the response.

I have tried both your suggestion. In first method (config.json) the application got invoked for a second and closed immediately with an error : " ERROR: BrowserError: unknown error: unhandled inspector error: {"code":-32601,"message":"'Browser.getWindowForTarget' wasn't found"}" .

Second method also having the same above issue. There is a correction in the command 👍

node sitespeed.js --browsertime.chrome.binaryPath "completepath\sample.exe" -n 1 sample.js --multi

I am able to solve the issue with following code.

CODE

const webdriver = require('selenium-webdriver'); const driver = new webdriver.Builder() .withCapabilities({ 'goog:chromeOptions': { "binary": "complete path of the exe file" } }) .forBrowser('chrome') .build();

harinsai commented 2 years ago

Hi @soulgalore ,

We are facing some issue while measuring the metrics. The above mentioned code is working and all the navigations flows are performing. But when we tried to measure the metrics ( adding commands.measure.start() and stop() between the workflows) we are getting the following error.

[2022-08-03 09:58:15] ERROR: Missing most active frame. Number of threads 0, Number of TraceEvents 61 and Threads [] [2022-08-03 09:58:15] ERROR: TypeError: Cannot read properties of undefined (reading 'frame')

The problem is while using the above code it will open a chrome browser and electron app separately. We are not able to use any of the the default sitespeed.io commands like 'await commands.addText.byId, commands.measure.start' etc. Instead of that for the user action we are using 'driver.findElement(webdriver.By.xpath , driver.get(''); ' commands.

If we add 'await commands.navigate('https://www.sitespeed.io');' it is running in the chrome browser, not in the electron app.

Reference link - https://www.electronjs.org/docs/latest/tutorial/using-selenium-and-webdriver#start-chromedriver

Regards, Harin Sai

jorge-prieto commented 2 years ago

Hi @soulgalore,

I am facing this same issue from above. Instead, I am working in a flow with vanilla JS and an iFrame, after couple views it changes into Angular and when i start again the test, this is the output.

[2022-08-11 09:23:33] ERROR: Missing most active frame. Number of threads 0, Number of TraceEvents 44 and Threads [] [2022-08-11 09:23:33] ERROR: TypeError: Cannot read property 'frame' of undefined

soulgalore commented 10 months ago

If there's problem with an iframe, please create an different issue and a reproducible test case, thanks!