Skip to content

Commit

Permalink
Feature/kamal/e2e setup (#245)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kamal0808 authored and pulkitsinghal committed Jul 31, 2017
1 parent f0a8a91 commit 5311aab
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions e2e/.env.example
Original file line number Diff line number Diff line change
@@ -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://<HOST>/#/

# each protractor run resembles one end-user
# by increasing scale, you can simulate multiple end-users
TEST_SCALE=1
6 changes: 6 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:6.10.3
COPY . /project
WORKDIR /project
RUN npm install -g protractor
RUN npm install
ENTRYPOINT [ "protractor" ]
22 changes: 22 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -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://<HOST>: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
17 changes: 17 additions & 0 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions e2e/modules/auth/pages/auth.po.js
Original file line number Diff line number Diff line change
@@ -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();
};

};
6 changes: 6 additions & 0 deletions e2e/modules/auth/testData/auth.td.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
manager: {
email: process.env.MANAGER_LOGIN_USERNAME,
password: process.env.MANAGER_LOGIN_PASSWORD
}
};
48 changes: 48 additions & 0 deletions e2e/modules/auth/tests/test1_login_manager.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

});
30 changes: 30 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 8 additions & 0 deletions e2e/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.config = {
framework: 'jasmine',
specs: ['./modules/auth/tests/*.js'],
jasmineNodeOpts: {
defaultTimeoutInterval: 1000 * 60 * 10
},
baseUrl: process.env.BASE_URL
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion warehouse-workers

0 comments on commit 5311aab

Please sign in to comment.