javascript - How can I write integration tests for chrome extension? -
i have written chrome extension loads in developer window. communicates loaded webpage , stores desired data in database.
i want write automated unit test extension in node using selenium, phantomjs/chromedriver, mocha , chai. have written simple test using selenium, chromedriver, mocha , chai. failing right now. have attached error below.
this how looks: client.js
exports.client = require('/usr/local/lib/node_modules/webdriverjs').remote({ // settings // use webdriverjs create selenium client desiredcapabilities: { browsername: 'chrome', chromeoptions: { binary: '/applications/google chrome.app/contents/macos/google chrome', args: [], extensions: ['/users/divyanshu/downloads/stm_updated_20160308051700.crx'] } }, loglevel: 'silent' });
test.js
var client = require('./client').client; var expect = require('chai').expect; describe('test stackoverflow.com', function(){ before(function(done) { client.init().url('chrome-extension://bfedbpidmfabedhnemcibiciahnjdnid/index.html', done); }); describe('check homepage', function(){ it('should see correct title', function(done) { client.gettitle(function(err, title){ expect(title).to.have.string( 'stm' ); done(); }); }); it('should see body', function(done) { client.gettext('#header', function(err, span){ expect(span).to.have.string( 'browser' ); done(); }) }); }); after(function(done) { client.end(); done(); }); });
this how running selenium server: java -jar ~/downloads/selenium-server-standalone-2.53.0.jar -dwebdriver.chrome.driver=node_modules/chromedriver/bin/chromedriver
and how running test: mocha test.js -t 10000
but not able load extension , getting these error: error output of test run:
test stackoverflow.com [13:08:00]: command post {"protocol":"http:","slashes":true,"auth":null,"host":"127.0.0.1:4444","port":"4444","hostname":"127.0.0.1","hash":null,"search":null,"query":null,"pathname":"/wd/hub/session","path":"/wd/hub/session","href":"http://127.0.0.1:4444/wd/hub/session"} [13:08:00]: data {"desiredcapabilities":{"browsername":"chrome","version":"","javascriptenabled":true,"platform":"any","chromeoptions":{"binary":"/applications/google chrome.app/contents/macos/google chrome","args":[],"extensions":["/users/divyanshu/downloads/stm_updated_20160308051700.crx"]}}} [13:08:00]: error unknownerror unknown server-side error occurred while processing command. unknown error: cannot process extension #1 unknown error: cannot base64 decode (driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=mac os x 10.11.4 x86_64) (warning: server did not provide stacktrace information) [13:08:00]: error couldn't session id - undefined 1) "before all" hook [13:08:00]: command delete {"protocol":"http:","slashes":true,"auth":null,"host":"127.0.0.1:4444","port":"4444","hostname":"127.0.0.1","hash":null,"search":null,"query":null,"pathname":"/wd/hub/session/","path":"/wd/hub/session/","href":"http://127.0.0.1:4444/wd/hub/session/"} [13:08:00]: data {} 0 passing (730ms) 1 failing 1) test stackoverflow.com "before all" hook: uncaught error: [init()] <= unknown server-side error occurred while processing command. @ makeerror (/usr/local/lib/node_modules/webdriverjs/lib/utils/makeerror.js:9:17) @ requesthandler.<anonymous> (/usr/local/lib/node_modules/webdriverjs/lib/utils/requesthandler.js:170:25) @ request.self.callback (/usr/local/lib/node_modules/webdriverjs/node_modules/request/request.js:122:22) @ request.<anonymous> (/usr/local/lib/node_modules/webdriverjs/node_modules/request/request.js:1019:14) @ incomingmessage.<anonymous> (/usr/local/lib/node_modules/webdriverjs/node_modules/request/request.js:970:12) @ endreadablent (_stream_readable.js:913:12)
error output in selenium server: exception: unknown error: cannot process extension #1
i used fs.readfilesync('/users/divyanshu/downloads/stm_updated_20160308051700.crx', 'base64')
encode crx file overcome error , got error:
exception: unknown error: cannot parse capability: chromeoptions
i tried load extension without crx file. added in 'args' in 'chromeoptions':
args: ['load-extension=/users/divyanshu/downloads/stm_updated_20160308051700']
this helped me in resolving error: cannot process extension #1
but have stumbled upon new error. not able load html file (index.html). saying "your file not found. may have been moved or deleted. err_file_not_found. reload". how can on come error?
this how manifest.json file looks:
{ "name": "extension", "description": "tool.", "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" }, "version": "1.1.2", "manifest_version": 2, "permissions": [ "webrequest", "<all_urls>", "history", "background", "storage", "cookies", "clipboardwrite", "tabs" ], "options_page": "options.html", "background": { "scripts": [ "background-script.js", "panes/js/jquery.js" ] }, "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", "devtools_page": "devtools.html", "web_accessible_resources": [ "panes/*" ] }
and devtools.js file load html file have specified location of devtools.html:
var panelwindow, injectedpanel = false, injectedpage = false, panelvisible = false, savedstack = []; chrome.devtools.panels.create("extension", "panes/img/logo.jpg", "panes/index.html", function(panel) {});
so, extension has multiple html files. , want write unit tests those, moving past each file 1 one, like, first have log extension (this login.html), select client (this selectclient.html) etc etc.
index.html loads first can see devtools.js, processing starts , loads other html files 1 one.
Comments
Post a Comment