diff options
author | Yuchen Pei <hi@ypei.me> | 2021-12-08 12:06:35 +1100 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2021-12-08 12:06:35 +1100 |
commit | 17a7b73d5446ad7e0f1eab4caba3b4b93c447275 (patch) | |
tree | d5fbc4ce9dac6b6b9f1db0011178faadb50c323d | |
parent | e37a21e4c0bc26f0c7ae9e17cd9ca1abd8b56534 (diff) |
Adding headless test.
-rw-r--r-- | README | 20 | ||||
-rw-r--r-- | test.js | 27 |
2 files changed, 47 insertions, 0 deletions
@@ -29,6 +29,7 @@ To debug this add-on on IceCat and other Firefox derivatives, browse to the spec LibreJS should work with other WebExtensions-compliant browsers; but currently, none of them meet the freedom standards of GNU, so no help will be provided for their usage. + TEST: An automated test suite runs automatically in its own tab whenever the extension @@ -36,6 +37,25 @@ is loaded as a "temporary add-on" from about:debugging. Otherwise (if included in the xpi, see BUILD above) it can be launched from the UI by clicking the [Automated self test...] button. +To launch the test in command line, ensure the extension has been +built with automated test suite. Then install selenium-webdriver and +geckodriver, and ensure the latter is in $PATH: + + $ npm install selenium-webdriver + $ npm install geckodriver + $ export PATH=$PATH:./node_modules/.bin + +Now you can invoke the test with + + $ node ./test.js + +which will print out a summary of test results. + +Optionally you can also test with a chosen seed + + $ node ./test.js 12345 + + CONTACT: Development mailing list: bug-librejs@gnu.org @@ -0,0 +1,27 @@ +/* A node script that runs tests in a headless browser. */ + +(function libreJSTest() { + const webdriver = require('selenium-webdriver'); + const firefox = require('selenium-webdriver/firefox'); + new webdriver.Builder().forBrowser('firefox') + .setFirefoxOptions(new firefox.Options() + // Uncomment this line to test using icecat +// .setBinary("/usr/bin/icecat") + .headless()).build() + .then(driver => + driver.installAddon("./librejs.xpi", /*isTemporary=*/true) + .then(driver.get("about:debugging#/runtime/this-firefox")) + .then(_ => driver.findElements(webdriver.By.css('.fieldpair dd'))) + .then(es => es[2].getText()) + .then(uuid => + driver.get('moz-extension://' + + uuid + '/test/SpecRunner.html' + + (process.argv[2] ? '?seed=' + process.argv[2] : '') )) + .then(_ => driver.wait(_ => + driver.findElement(webdriver.By.css('.jasmine-alert')) + .then(e => e.getText()), 10000)) + .then(_ => driver.findElement(webdriver.By.css('.jasmine-alert'))) + .then(e => e.getText()) + .then(console.log) + .then(_ => driver.quit())); +})(); |