From 2a0b3a007d0daada3438897c76898a86d9f485b8 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Wed, 20 Apr 2016 18:58:02 +0200 Subject: [PATCH] Added testing and auto-testing with selenium --- .gitignore | 1 + TestSelenium.js | 30 ++++++++++++++++++++++++++++++ package.json | 3 ++- readme.md | 9 ++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 TestSelenium.js diff --git a/.gitignore b/.gitignore index e4c4f537c..2d0cd09d9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ customization *.db /customize/ messages.log +.DS_Store diff --git a/TestSelenium.js b/TestSelenium.js new file mode 100644 index 000000000..55fb2a438 --- /dev/null +++ b/TestSelenium.js @@ -0,0 +1,30 @@ +'use strict'; +const WebDriver = require("selenium-webdriver"); + +let driver; +if (process.env.SAUCE_USERNAME != undefined) { + driver = new WebDriver.Builder().usingServer( + 'http://'+ process.env.SAUCE_USERNAME+':'+process.env.SAUCE_ACCESS_KEY+'@ondemand.saucelabs.com:80/wd/hub' + ).withCapabilities({ + "tunnel-identifier": process.env.TRAVIS_JOB_NUMBER, + "build": process.env.TRAVIS_BUILD_NUMBER, + "username": process.env.SAUCE_USERNAME, + "accessKey": process.env.SAUCE_ACCESS_KEY, + "browserName": "chrome" + }).build(); +} else { + driver = new WebDriver.Builder().withCapabilities({ browserName: "chrome" }).build(); +} + +driver.get('http://localhost:3000/assert/'); +const report = driver.wait(WebDriver.until.elementLocated(WebDriver.By.className("report")), 5000); +report.getAttribute("class").then(function (cls) { + driver.quit(); + if (!cls) { + throw new Error("cls is null"); + } else if (cls.indexOf("failure") !== -1) { + throw new Error("cls contains the word failure"); + } else if (cls.indexOf("success") === -1) { + throw new Error("cls does not contain the word success"); + } +}); diff --git a/package.json b/package.json index 387a5df98..bed5b49ba 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "selenium-webdriver": "^2.53.1" }, "scripts": { - "lint": "jshint --config .jshintrc --exclude-path .jshintignore ." + "lint": "jshint --config .jshintrc --exclude-path .jshintignore .", + "test": "node TestSelenium.js" } } diff --git a/readme.md b/readme.md index af024b64d..d3a2868fa 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,7 @@ To install: npm install -g bower ## if necessary bower install - ## copy config.js.dist to config.js + ## copy config.js.dist to config.js cp config.js.dist config.js ## modify configuration to use your own mongodb instance @@ -67,6 +67,13 @@ rm -rf ./cryptpad.db If you are using the mongodb adaptor, [drop the relevant collection](https://docs.mongodb.org/manual/reference/method/db.collection.drop/#db.collection.drop). +## Testing + +To test CryptPad, go to http://your.server:3000/assert/ + +You can use WebDriver to run this test automatically by running TestSelenium.js but you will need chromedriver installed. +If you use Mac, you can `brew install chromedriver`. + ## Security CryptPad is *private*, not *anonymous*. Privacy protects your data, anonymity protects you.