Skip to content
This repository was archived by the owner on Jul 30, 2022. It is now read-only.

Alternative (simpler?) docker setup that does not use selemium #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions protractor-docker-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Running Protractor Tests on Docker (without Selenium)
========================================

This is a simple tutorial that shows how to use docker to run Protractor tests.
This example is an alternative to using Selenium Grid and as such provides a simpler setup

Prerequisites
-------------
Docker needs to be installed on your machine. One can download it from [Docker's website](https://www.docker.com) and follow the [documentation](https://docs.docker.com/) accordingly.
It is assumed that , one knows the basics of Docker for this tutorial.

Setup
-----------
To ensure Docker is installed sucessfully , type :
``` shell
docker -v
```
and one would see a similar output , depending on the version of docker installed :
``` shell
Docker version 18.05.0-ce, build f150324
```

Using Docker Compose
---------------------------------------------------------------------------

Create a docker-compose.yml

``` yaml
version: '2.4'

services:

app:
image: node:6.14-slim
working_dir: /src
command: node index.js
volumes:
- "../testapp:/src"

e2e:
image: webnicer/protractor-headless
command: ./conf.js
shm_size: 2g
volumes:
- "./:/protractor"
- "tests-output:/test-output"
depends_on:
- app

volumes:
tests-output:
```

Then in the terminal, enter the command

``` shell
npm test
```

The above command performs the following:
* installs node_modules for the testapp and any test jasmine reporters useful for end-to-end testing
* starts the testapp inside of a container ('app')
* runs protractor tests in another container ('e2e') against the testapp in the same private docker network
* outputs the results of the tests to a named volume thus making them available outside of the test container
27 changes: 27 additions & 0 deletions protractor-docker-simple/conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Tests for the calculator.
exports.config = {
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: [ "no-sandbox" ]
}
},
directConnect: true,
specs: [
'specs/*spec.js'
],
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
var junitReporter = new jasmineReporters.JUnitXmlReporter({

// setup the output path for the junit reports
// note: The report will be created inside of the container.
// We use a named volume in the compose file to make it available
// outside of the container
savePath: '/test-output/',
consolidateAll: true

});
jasmine.getEnv().addReporter(junitReporter);
}
};
11 changes: 11 additions & 0 deletions protractor-docker-simple/docker-compose.windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '2.4'

# you are on windows and are using LCOW

services:

app:
platform: linux

e2e:
platform: linux
26 changes: 26 additions & 0 deletions protractor-docker-simple/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '2.4'

services:

# to manually verify the site:
# 1. docker-compose run -d -p 8080:8080 app
# 2. browse to http://localhost:8080/ng1/calculator
app:
image: node:6.14-slim
working_dir: /src
command: node index.js
volumes:
- "../testapp:/src"

e2e:
image: webnicer/protractor-headless
command: ./conf.js
shm_size: 2g
volumes:
- "./:/protractor"
- "tests-output:/test-output"
depends_on:
- app

volumes:
tests-output:
34 changes: 34 additions & 0 deletions protractor-docker-simple/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions protractor-docker-simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "protractor-docker-setup",
"scripts": {
"prestart": "npm i && cd ../testapp && npm i",
"start": "docker-compose run -d -p 8080:8080 app",
"prestart:windows": "npm i && cd ../testapp && npm i",
"start:windows": "docker-compose -f docker-compose.yml -f docker-compose.windows.yml run -d -p 8080:8080 app",
"stop": "docker-compose down",
"pretest": "npm i && cd ../testapp && npm i",
"test": "docker-compose up --abort-on-container-exit --exit-code-from e2e",
"pretest:windows": "npm i && cd ../testapp && npm i",
"test:windows": "docker-compose -f docker-compose.yml -f docker-compose.windows.yml up --abort-on-container-exit --exit-code-from e2e"
},
"dependencies": {
"jasmine-reporters": "^2.3.1"
}
}
52 changes: 52 additions & 0 deletions protractor-docker-simple/specs/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var env = {
// 'app' === name of service started in ../docker-compose.yml
url: 'http://app:8080'
}

describe('slow calculator', () => {
beforeEach(() => {
browser.get(env.url + '/ng1/calculator');
});

it('should add numbers', () => {
element(by.model('first')).sendKeys(4);
element(by.model('second')).sendKeys(5);
element(by.id('gobutton')).click();

expect(element(by.binding('latest')).getText()).toEqual('9');
});

describe('memory', () => {
var first, second, goButton;
beforeEach(function() {
first = element(by.model('first'));
second = element(by.model('second'));
goButton = element(by.id('gobutton'));
});

it('should start out with an empty memory', () => {
var memory =
element.all(by.repeater('result in memory'));

expect(memory.count()).toEqual(0);
});

it('should fill the memory with past results', () => {
first.sendKeys(1);
second.sendKeys(1);
goButton.click();

first.sendKeys(10);
second.sendKeys(20);
goButton.click();

var memory = element.all(by.repeater('result in memory').
column('result.value'));
memory.then((arr) => {
expect(arr.length).toEqual(2);
expect(arr[0].getText()).toEqual('30'); // 10 + 20 = 30
expect(arr[1].getText()).toEqual('2'); // 1 + 1 = 2
});
});
});
});
Loading