From 1ac40a94e73daa3271bac1f74b50f240cb24879c Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Mon, 19 Sep 2016 15:40:57 -0700 Subject: [PATCH] Add initial nightwatch smoke test, package commands --- .gitignore | 3 + nightwatch.json | 38 ++++++++ package.json | 9 +- spec/smoke/individual-account-lifecycle.js | 101 +++++++++++++++++++++ 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 nightwatch.json create mode 100644 spec/smoke/individual-account-lifecycle.js diff --git a/.gitignore b/.gitignore index c4a59d9bf..ffd92e394 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,6 @@ Dockerfile # coffeelint for editors (might be standardized eventually) coffeelint.json gitSpy/* + +# nightwatch reports +spec/smoke/reports/ diff --git a/nightwatch.json b/nightwatch.json new file mode 100644 index 000000000..c3ffa2766 --- /dev/null +++ b/nightwatch.json @@ -0,0 +1,38 @@ +{ + "src_folders": ["spec/smoke"], + "output_folder": "spec/smoke/reports", + "custom_commands_path": "", + "custom_assertions_path": "", + "page_objects_path": "", + "globals_path": "", + + "selenium": { + "start_process": true, + "start_session": true, + "server_path": "node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.53.1.jar", + "log_path": "", + "host": "127.0.0.1", + "port": 4444, + "cli_args": { + "webdriver.chrome.driver": "node_modules/chromedriver/lib/chromedriver/chromedriver" + } + }, + + "test_settings": { + "default": { + "launch_url": "http://localhost", + "selenium_port": 4444, + "selenium_host": "localhost", + "silent": true, + "screenshots": { + "enabled": false, + "path": "" + }, + "desiredCapabilities": { + "browserName": "chrome", + "javascriptEnabled": true, + "acceptSslCerts": true + } + } + } +} diff --git a/package.json b/package.json index 2a93d8c0a..6d9e41567 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,11 @@ "jasmine-node": "jasmine-node", "multicore": "coffee multicore.coffee", "jasmine": "jasmine", - "proxy": "COCO_PROXY='true' nodemon" + "proxy": "COCO_PROXY='true' nodemon", + "smoke-local": "COCO_SMOKE_DOMAIN='local' nightwatch", + "smoke-next": "COCO_SMOKE_DOMAIN='next' nightwatch", + "smoke-prod": "COCO_SMOKE_DOMAIN='prod' nightwatch", + "smoke-staging": "COCO_SMOKE_DOMAIN='staging' nightwatch" }, "main": "index.js", "keywords": [ @@ -98,6 +102,7 @@ "auto-reload-brunch": "^1.8.1", "bower": "~1.6.4", "brunch": "^1.8.5", + "chromedriver": "^2.24.1", "coffee-script-brunch": "^1.8.3", "coffeelint-brunch": "^1.7.1", "commonjs-require-definition": "0.2.0", @@ -120,11 +125,13 @@ "karma-requirejs": "~0.2.1", "karma-script-launcher": "~0.1.0", "marked": "0.2.x", + "nightwatch": "^0.9.8", "nock": "^2.17.0", "nodemon": "1.6.1", "parse-domain": "^0.2.1", "requirejs": "~2.1.10", "sass-brunch": "https://github.com/basicer/sass-brunch-bleeding/archive/1.9.1-bleeding.tar.gz", + "selenium-server-standalone-jar": "^2.53.1", "telepath-brunch": "https://github.com/nwinter/telepath-brunch/tarball/master", "uglify-js": "^2.5.0" }, diff --git a/spec/smoke/individual-account-lifecycle.js b/spec/smoke/individual-account-lifecycle.js new file mode 100644 index 000000000..e6ce06395 --- /dev/null +++ b/spec/smoke/individual-account-lifecycle.js @@ -0,0 +1,101 @@ +WAIT_TIMEOUT = 8000; + +// TODO: Refactor into shared file +switch (process.env.COCO_SMOKE_DOMAIN) { + case "local": + DOMAIN = 'http://localhost:3000'; + break; + case "next": + DOMAIN = 'http://next.codecombat.com'; + break; + case "staging": + DOMAIN = 'http://staging.codecombat.com'; + break; + case "prod": + DOMAIN = 'https://codecombat.com'; + break; + default: + DOMAIN = 'http://localhost:3000'; +} + +var timestamp = new Date().getTime(), + email = `email${timestamp}@${timestamp}.com`, + name = timestamp.toString(), + password = timestamp.toString(); + +module.exports = { + 'Sign up': function (browser) { + + browser + // Go to home page + .url(DOMAIN) + .resizeWindow(1250, 900) + + // Open login modal + .executeAsync(function(done) { window.currentView.supermodel.finishLoading.then(done); }) + .click('#create-account-link') + + // Sign up + .waitForElementVisible('.individual-path-button', WAIT_TIMEOUT) + .click('.individual-path-button') + .waitForElementVisible('#birthday-month-input', WAIT_TIMEOUT) + .setValue('#birthday-month-input', 'January') + .setValue('#birthday-day-input', '1') + .setValue('#birthday-year-input', '1999') + .click('.next-button') + .waitForElementVisible('input[name="email"]', WAIT_TIMEOUT) + .setValue('input[name="email"]', email) + .setValue('input[name="name"]', name) + .setValue('input[name="password"]', password) + .click('#subscribe-input') + .pause(100) // Sometimes create account button does not get clicked + .click('#create-account-btn') + .waitForElementVisible('#start-btn', WAIT_TIMEOUT) + .click('#start-btn') + + // Confirm we went to campaign view, navigate back to home + .waitForElementVisible('#logout-button', WAIT_TIMEOUT * 3) // takes particularly long + .assert.urlContains('/play') + }, + + 'Logout': function (browser) { + browser + .url(DOMAIN) + .executeAsync(function (done) { + window.currentView.supermodel.finishLoading.then(done); + }) + .click('.dropdown-toggle') + .waitForElementVisible('.dropdown #logout-button', WAIT_TIMEOUT) + .click('.dropdown #logout-button') + }, + + 'Log back in': function (browser) { + browser + // Log back in + .waitForElementVisible('#login-link', WAIT_TIMEOUT) + .click('#login-link') + .waitForElementVisible('#login-btn', WAIT_TIMEOUT) + .setValue('input#username-or-email-input', email) + .setValue('input#password-input', password) + .click('#login-btn') + .pause(100) + .waitForElementVisible('#main-nav', WAIT_TIMEOUT) + }, + + 'Delete account': function (browser) { + browser + // Delete account + .url(`${DOMAIN}/account/settings`) + .pause(100) + .executeAsync(function(done) { window.currentView.supermodel.finishLoading.then(done); }) + .waitForElementVisible('#delete-account-email-or-username', WAIT_TIMEOUT) + .setValue('#delete-account-email-or-username', email) + .setValue('#delete-account-password', password) + .click('#delete-account-btn') + .waitForElementVisible('#confirm-button', WAIT_TIMEOUT) + .click('#confirm-button') + .end(); + } +}; + +