From f81756a44ccc926183410b58e3e72365aa7410bb Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Tue, 14 Jun 2016 08:46:17 -0400 Subject: [PATCH 1/2] Initial browser testing --- .gitignore | 1 + .travis.yml | 12 +++++----- README.md | 14 ++++++++++++ nightwatch.json | 42 +++++++++++++++++++++++++++++++++++ package.json | 5 ++++- test-browser/new-file-test.js | 10 +++++++++ test-browser/smoke-test.js | 9 ++++++++ 7 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 nightwatch.json create mode 100644 test-browser/new-file-test.js create mode 100644 test-browser/smoke-test.js diff --git a/.gitignore b/.gitignore index 30f101fb65..ba6d2dcfe8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode build node_modules +reports diff --git a/.travis.yml b/.travis.yml index 56ba281685..6843bf7a55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,11 @@ language: node_js node_js: -- stable -script: npm run lint && npm run test && npm run build + - stable +before_script: + - npm run serve & +script: + - npm run lint && npm run test && npm run build && nightwatch --env chrome + - pkill node addons: sauce_connect: username: "chriseth" @@ -11,7 +15,7 @@ deploy: script: ci/deploy_from_travis.sh skip_cleanup: true on: - branch: master + branch: master env: global: - ENCRYPTION_LABEL="b5c2730599da" @@ -19,5 +23,3 @@ env: - COMMIT_AUTHOR="Travis CI" - PUSH_REPO="git@github.com:ethereum/browser-solidity.git" - FILES_TO_PACKAGE="assets background.js build icon.png index.html manifest.json README.md" - - diff --git a/README.md b/README.md index fd1403d0cb..a6a7f5d197 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,20 @@ Run: - In Debian based OSes such as Ubuntu you may need to run `apt-get install build-essential`. After installing `build-essential` run `npm install rebuild`. +## Testing + +To run the Selenium tests via nightwatch serve the app through a local web server: + + npm run serve # starts web server at localhost:8080 + +Then you will need to either: + + 1. Have a Selenium server running locally on port 4444 along with the chromedriver installed. + * Run: `./node_modules/nightwatch/bin/nightwatch --env local` + 1. Or, install SauceConnect and run it locally `sc -u -k ` (see .travis.yml for values) + * Run: `./node_modules/nightwatch/bin/nightwatch --env chrome` + + ## Usage as a Chrome Extension If you would like to use this as a Chrome extension, you must either build it first or pull from the `gh-pages` branch, both described above. diff --git a/nightwatch.json b/nightwatch.json new file mode 100644 index 0000000000..2c2b3fbf5a --- /dev/null +++ b/nightwatch.json @@ -0,0 +1,42 @@ +{ + "src_folders" : ["test-browser"], + "output_folder" : "reports", + "custom_commands_path" : "", + "custom_assertions_path" : "", + "page_objects_path" : "", + "globals_path" : "", + + "test_settings" : { + "default" : { + "launch_url": "http://ondemand.saucelabs.com:80", + "selenium_port": 80, + "selenium_host": "ondemand.saucelabs.com", + "silent": true, + "username": "chriseth", + "access_key": "b781828a-9e9c-43d8-89d4-2fbb879595ca", + "screenshots" : { + "enabled" : false + }, + "globals": { + "waitForConditionTimeout": 60000 + } + }, + "chrome" : { + "desiredCapabilities": { + "browserName": "chrome", + "javascriptEnabled": true, + "acceptSslCerts": true + } + }, + "local" : { + "launch_url": "http://localhost:8080", + "selenium_port": 4444, + "selenium_host": "localhost", + "desiredCapabilities": { + "browserName": "chrome", + "javascriptEnabled": true, + "acceptSslCerts": true + } + } + } +} diff --git a/package.json b/package.json index ee3d46f471..efe1cff05a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "test": "node test/index.js", "build": "mkdir -p build; browserify src/index.js -o build/app.js", - "lint": "semistandard" + "lint": "semistandard", + "serve": "http-server ." }, "devDependencies": { "brace": "^0.8.0", @@ -16,8 +17,10 @@ "ethereumjs-tx": "^1.1.1", "ethereumjs-util": "^4.4.0", "ethereumjs-vm": "^1.4.0", + "http-server": "0.9.0", "jquery": "^2.2.0", "js-base64": "^2.1.9", + "nightwatch": "^0.9.3", "semistandard": "^7.0.0", "tape": "^4.5.1", "web3": "^0.15.3", diff --git a/test-browser/new-file-test.js b/test-browser/new-file-test.js new file mode 100644 index 0000000000..aed8864643 --- /dev/null +++ b/test-browser/new-file-test.js @@ -0,0 +1,10 @@ +module.exports = { + 'New file test': function (browser) { + browser + .url('http://127.0.0.1:8080') + .waitForElementVisible('.newFile', 5000) + .click('.newFile') + .assert.containsText('.active', 'Untitled') + .end(); + } +}; diff --git a/test-browser/smoke-test.js b/test-browser/smoke-test.js new file mode 100644 index 0000000000..c9d70e7b71 --- /dev/null +++ b/test-browser/smoke-test.js @@ -0,0 +1,9 @@ +module.exports = { + 'Smoke test': function (browser) { + browser + .url('http://127.0.0.1:8080') + .waitForElementVisible('#righthand-panel', 5000) + .assert.containsText('#righthand-panel', 'Solidity version') + .end(); + } +}; From 795c429ddaa89ecd6fba5060c01717dcd9fcfe40 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Tue, 14 Jun 2016 08:59:41 -0400 Subject: [PATCH 2/2] Documenting browser vs unit testing --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a6a7f5d197..f2ffe635bc 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,13 @@ Run: - In Debian based OSes such as Ubuntu you may need to run `apt-get install build-essential`. After installing `build-essential` run `npm install rebuild`. - -## Testing +## Unit Testing + +Register new unit test files in `test/index.js`. The tests are written using [tape](https://www.npmjs.com/package/tape). Run the tests via: + + npm test + +## Browser Testing To run the Selenium tests via nightwatch serve the app through a local web server: