3

I am using Selenium for testing. I noticed a different behavior starting Chrome manually and starting it with selenium. After a lot of investigation I broke the problem down to JavaScript's window.chrome.runtime which is undefined if started with selenium.

After some research on Google I have found people facing similar issues, but none of their solutions worked for me.

I have tried so far to remove the test-type switch:

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));

Are there any other ways I can make it work?

Carle B. Navy
  • 1,156
  • 10
  • 28
  • You haven't described the issue or behaviors you are seeing, what the different behavior is for Chrome manually vs Chrome with Selenium, and what does "make it work" look like? – JeffC Sep 07 '18 at 15:20
  • Javascript checks whether a specific chrome plugin is installed or not and therefor uses `runtime.sendMessage()`. For both cases a different dialog pops up. But when started with selenium `runtime` is `undefined` and nothing pops up. This does not happen when starting chrome manually. In some forums I found out that this goes back to some seleniumdriver parameters. Those posts were very old though and the solution did not work for me. "Make it work" would mean to get the same result as if I started chrome manually (so `runtime` is defined and `sendMessage()` works) – Carle B. Navy Sep 08 '18 at 14:05

2 Answers2

1

Answer which did the job for me was at https://groups.google.com/forum/#!topic/chromedriver-users/7wF9EHF2jxQ

Code snippet:

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
jpeg
  • 2,372
  • 4
  • 18
  • 31
0

Selenium does not start browser with an existing browser profile, it create a temporary one, every single time. So it does not need to send js to check any installed plugins. To avoid the undefined runtime, use an existing browser profile.

ChromeOptions options = new ChromeOptions();
// edit this path
options.addArguments("user-data-dir=C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data");   
driver = new ChromeDriver(options);
pburgr
  • 1,722
  • 1
  • 11
  • 26