From 5311aab0c92dfb1708df1f356ef08f6b042ab958 Mon Sep 17 00:00:00 2001 From: kamal0808 Date: Tue, 1 Aug 2017 02:01:58 +0530 Subject: [PATCH] Feature/kamal/e2e setup (#245) * fix the mapping again, its strange * Set up docker services for protractor tests * Editor configuration * Steps to run e2e tests in Readme * Run tests through 'npm test' and set up env file for tests * Store Manager login tests (+ve and -ve) * Circle CI to run protractor tests * move test runner into the e2e directory * Circle CI won't be running tests anymore Probably will set up a pre commit git hook that'll run before every commit. --- .editorconfig | 13 +++++ circle.yml | 2 +- e2e/.env.example | 9 ++++ e2e/Dockerfile | 6 +++ e2e/README.md | 22 +++++++++ e2e/docker-compose.yml | 17 +++++++ e2e/modules/auth/pages/auth.po.js | 31 ++++++++++++ e2e/modules/auth/testData/auth.td.js | 6 +++ e2e/modules/auth/tests/test1_login_manager.js | 48 +++++++++++++++++++ e2e/package.json | 30 ++++++++++++ e2e/protractor.conf.js | 8 ++++ package.json | 3 +- warehouse-workers | 2 +- 13 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 .editorconfig create mode 100644 e2e/.env.example create mode 100644 e2e/Dockerfile create mode 100644 e2e/README.md create mode 100644 e2e/docker-compose.yml create mode 100644 e2e/modules/auth/pages/auth.po.js create mode 100644 e2e/modules/auth/testData/auth.td.js create mode 100644 e2e/modules/auth/tests/test1_login_manager.js create mode 100644 e2e/package.json create mode 100644 e2e/protractor.conf.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..3ee22e5d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/circle.yml b/circle.yml index 20c2511b..3e676170 100644 --- a/circle.yml +++ b/circle.yml @@ -15,7 +15,7 @@ dependencies: override: # Extract the version number - npm install -g bower - - bower --allow-root install + - bower --allow-root install - ./scripts/build/image $(grep version package.json | head -1 | tr -s ' ' | awk '{ print $2 }' | sed 's/[",]//g') - docker run --name mongo-local -d mongo diff --git a/e2e/.env.example b/e2e/.env.example new file mode 100644 index 00000000..68fb5e5a --- /dev/null +++ b/e2e/.env.example @@ -0,0 +1,9 @@ +MANAGER_LOGIN_USERNAME= +MANAGER_LOGIN_PASSWORD= + +# the HOST in this URL should be the same as the value configured for VM_EXTERNAL_IP +BASE_URL=http:///#/ + +# each protractor run resembles one end-user +# by increasing scale, you can simulate multiple end-users +TEST_SCALE=1 \ No newline at end of file diff --git a/e2e/Dockerfile b/e2e/Dockerfile new file mode 100644 index 00000000..8a02393c --- /dev/null +++ b/e2e/Dockerfile @@ -0,0 +1,6 @@ +FROM node:6.10.3 +COPY . /project +WORKDIR /project +RUN npm install -g protractor +RUN npm install +ENTRYPOINT [ "protractor" ] \ No newline at end of file diff --git a/e2e/README.md b/e2e/README.md new file mode 100644 index 00000000..2f389b94 --- /dev/null +++ b/e2e/README.md @@ -0,0 +1,22 @@ +# Warehouse - e2e Testing Document + +## Prerequisites + +#### Docker Compose +Compose is a tool for defining and running multi-container Docker applications + +#### Setup `.env` file +1. Copy `.env.example` to `.env` file +2. Configure `.env` file with valid values for testing + +## How To Run Test Cases +- In the app root directory, run `docker-compose up e2e-selenium-and-chrome-debug`. This will create a container with image `selenium/standalone-chrome-debug`, details of which can be found here: https://github.com/SeleniumHQ/docker-selenium. +- In your mac spotlight, type `vnc://:5900`. + - the HOST in this URL should be the same as the value configured for VM_EXTERNAL_IP + - This will open a remote desktop access software which will allow you to view the tests running inside the docker container. +- After the container is up, use `npm run test`. This will run the tests specified in `protractor.conf.js`. + - the underlying command that runs is: `docker-compose up e2e-protractor-test-runner-debug` + - if you want to treat it as a test harness, use [scaling](https://docs.docker.com/compose/reference/up/) and run this command directly: + - `SCALE=5 npm run stressTest` + - each protractor run resembles one end-user + - by increasing scale, you can simulate multiple end-users diff --git a/e2e/docker-compose.yml b/e2e/docker-compose.yml new file mode 100644 index 00000000..fab1a7ff --- /dev/null +++ b/e2e/docker-compose.yml @@ -0,0 +1,17 @@ +version: "2" +services: + e2e-selenium-and-chrome-debug: + ports: + - "4444" + - "5900:5900" + image: selenium/standalone-chrome-debug + volumes: + - /dev/shm:/dev/shm + e2e-protractor-test-runner-debug: + build: . + env_file: .env + command: protractor.conf.js --seleniumAddress=http://e2e-selenium-and-chrome-debug:4444/wd/hub + volumes: + - ./modules:/project/modules + - ./package.json:/project/package.json + - ./protractor.conf.js:/project/protractor.conf.js diff --git a/e2e/modules/auth/pages/auth.po.js b/e2e/modules/auth/pages/auth.po.js new file mode 100644 index 00000000..bbe7b096 --- /dev/null +++ b/e2e/modules/auth/pages/auth.po.js @@ -0,0 +1,31 @@ +module.exports = function () { + + var self = this; + + /** + * @description Login using email and password + * @param email + * @param password + */ + self.login = function (email, password) { + console.log('Entering Login page'); + var baseUrl = browser.baseUrl; + var testUrl = browser.baseUrl + 'login'; + browser.get(testUrl); + console.log('Entering username and password', email, password); + element(by.model('userName')).sendKeys(email); + element(by.model('password')).sendKeys(password); + console.log('Clicking login button'); + return element(by.css('button[ng-click="login(userName,password)"]')).click(); + }; + + /** + * @description Click on the logout button + */ + self.logout = function () { + var logoutButton = element(by.css('a[href="#/logout"]')); + console.log('Clicking logout button'); + return logoutButton.click(); + }; + +}; diff --git a/e2e/modules/auth/testData/auth.td.js b/e2e/modules/auth/testData/auth.td.js new file mode 100644 index 00000000..746ee88b --- /dev/null +++ b/e2e/modules/auth/testData/auth.td.js @@ -0,0 +1,6 @@ +module.exports = { + manager: { + email: process.env.MANAGER_LOGIN_USERNAME, + password: process.env.MANAGER_LOGIN_PASSWORD + } +}; diff --git a/e2e/modules/auth/tests/test1_login_manager.js b/e2e/modules/auth/tests/test1_login_manager.js new file mode 100644 index 00000000..bc97e575 --- /dev/null +++ b/e2e/modules/auth/tests/test1_login_manager.js @@ -0,0 +1,48 @@ +var AuthFunctions = require('./../pages/auth.po.js'); +describe('Login', function () { + + var authFunctions = new AuthFunctions(); + var authParams = require('./../testData/auth.td.js'); + var manager = authParams.manager; + + /** + * Login to the warehouse as a store manager with correct credentials, + * and redirect to store-landing page. + */ + it('Store manager login', function () { + + authFunctions.login(manager.email, manager.password) + .then(function () { + expect(browser.getCurrentUrl()).toContain('/store-landing'); + console.log('Entered store landing page'); + }); + + }); + + /** + * Logout of the warehouse successfully, and redirect back to login page + */ + it('Store manager logout', function () { + authFunctions.logout() + .then(function () { + expect(browser.getCurrentUrl()).toContain('/login'); + console.log('Logged out successfully'); + }); + }); + + + /** + * Login to the warehouse using invalid username and password, and expect + * to get an error without any redirection + */ + it('Store manager login wrong username and password', function () { + authFunctions.login(manager.email + 'blah', manager.password + 'blah') + .then(function () { + var userNameError = element(by.binding('errors.username')).getText(); + expect(browser.getCurrentUrl()).toContain('/login'); + expect(userNameError).toBe('login failed'); + console.log('Login failure checked successfully'); + }); + }); + +}); diff --git a/e2e/package.json b/e2e/package.json new file mode 100644 index 00000000..8075e99a --- /dev/null +++ b/e2e/package.json @@ -0,0 +1,30 @@ +{ + "name": "warehouse-e2e", + "version": "1.0.0", + "description": "Warehouse e2e protractor tests", + "repository": { + "type": "git", + "url": "git+https://github.com/ShoppinPal/warehouse.git" + }, + "keywords": [ + "warehouse", + "protractor", + "e2e" + ], + "scripts": { + "protractor": "protractor", + "webdriver-manager": "webdriver-manager", + "test": "docker-compose up e2e-protractor-test-runner-debug", + "stressTest": "docker-compose up --scale e2e-protractor-test-runner-debug=${SCALE} e2e-protractor-test-runner-debug" + }, + "devDependencies": { + "protractor-jasmine2-screenshot-reporter": "0.4.0", + "protractor": "5.1.2" + }, + "author": "Kamal Khatwani", + "license": "ISC", + "bugs": { + "url": "https://github.com/ShoppinPal/warehouse/issues" + }, + "homepage": "https://github.com/ShoppinPal/warehouse#readme" +} diff --git a/e2e/protractor.conf.js b/e2e/protractor.conf.js new file mode 100644 index 00000000..5cb75e00 --- /dev/null +++ b/e2e/protractor.conf.js @@ -0,0 +1,8 @@ +exports.config = { + framework: 'jasmine', + specs: ['./modules/auth/tests/*.js'], + jasmineNodeOpts: { + defaultTimeoutInterval: 1000 * 60 * 10 + }, + baseUrl: process.env.BASE_URL +}; diff --git a/package.json b/package.json index e6b587e9..19df8a70 100644 --- a/package.json +++ b/package.json @@ -78,8 +78,7 @@ "node": "0.10.x" }, "scripts": { - "postinstall": "echo -n $NODE_ENV | grep -v 'production' && ./node_modules/protractor/bin/webdriver-manager update || echo 'will NOT run webdriver install or update'", - "test": "grunt test" + "postinstall": "echo -n $NODE_ENV | grep -v 'production' && ./node_modules/protractor/bin/webdriver-manager update || echo 'will NOT run webdriver install or update'" }, "main": "server/server.js" } diff --git a/warehouse-workers b/warehouse-workers index 7c06cca1..5ee656b5 160000 --- a/warehouse-workers +++ b/warehouse-workers @@ -1 +1 @@ -Subproject commit 7c06cca138386a13057bf6005694ae5dadb99b64 +Subproject commit 5ee656b5383baa1f06528c04f8796d3992ede4f6