4

I am testing a chrome extension using selenium webdriver.js and chromedriver. I've been able to successfully launch chrome, with my extension installed, but the extension id is randomly generated instead of matching the key property of my manifest.json. This makes it impossible to test extension pages like the options page.

manifest.json

// ...
"key": "pjnhffdkdckcagdmfmidafhppbomjdjg", // id from chrome web store
// ...

test.js

var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');

// load unpacked extension
var chromeOptions = new chrome.Options();
chromeOptions.addArguments('load-extension=/path/to/my/extension');

var service = new chrome.ServiceBuilder().build();
var driver = chrome.createDriver(chromeOptions, service)
// this page is not available T_T
driver.get('chrome-extension://pjnhffdkdckcagdmfmidafhppbomjdjg/html/options.html');

My assumption is that the extension id would match the key (and it does when installing from the web store), but this does not seem to be true for loading the extension via chromedriver. Is there a way to get the loaded extension to have a consistent ID? Or should I take another approach?

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
  • See https://stackoverflow.com/questions/23873623/obtaining-chrome-extension-id-for-development – Rob W Nov 13 '14 at 10:46
  • @RobW thanks for the comment! I didn't think I needed to go through the process of generating a PEM file if I just use the key from an extension installed through the chrome store. Is that assumption correct? – Nick Tomlin Nov 13 '14 at 18:16
  • Well, if you use the key of an arbitrary extension from the CWS in your unpacked extension, then you're effecively impersonating an extension. If you don't want to use the tools that I mentioned in that linked answer, then you can generate a crx file (and PEM file) using the "Pack extension" button at `chrome://extensions`. After creating the CRX file, you can use my CRX Viewer to view the `"key"` of the extension (as explained at http://stackoverflow.com/questions/21497781/how-to-change-chrome-packaged-app-id-or-why-do-we-need-key-field-in-the-manifest/21500707#21500707). – Rob W Nov 13 '14 at 22:12
  • @RobW in this case the extension is my extension from the CWS, so I believe I should be good (unless I misunderstood). You make an excellent point for others who are not developing off the CWS though. – Nick Tomlin Nov 14 '14 at 14:58

2 Answers2

4

The manifest key value is not the extension ID. You have to install the extension from the web store and look in the manifest.json file on your desk. Use they key value inside that file. The documentation describes how to find the install directory.

abraham
  • 46,583
  • 10
  • 100
  • 152
  • In my case I don't want to use the web store at all. But I need a contant ID to run my tests on my machine and on any other (buddys who help developing). At this point everypody who clones my projects needs to get his own ID for this extension which is kind of a pain. Check my question to this: http://stackoverflow.com/questions/36641833/receiving-the-chrome-api-chrome-runtime-within-selenium-test?noredirect=1#comment60883035_36641833 – xetra11 Apr 15 '16 at 11:08
1

I was having the same issue. Just load your extensions from a crx file and you will get a consistent id.