From 76d0bd78e4b51f30462e85baade6558120fed9f7 Mon Sep 17 00:00:00 2001 From: Jozz Hart Date: Thu, 5 Apr 2018 16:17:31 +0100 Subject: [PATCH 1/3] Update docker-compose setup Add containerised app and run containerised protractor tests against it. --- protractor-docker/README.md | 68 +++++++-------- protractor-docker/app/index.html | 87 +++++++++++++++++++ protractor-docker/app/index.js | 12 +++ protractor-docker/app/package.json | 8 ++ protractor-docker/docker-compose.yml | 56 ++++++------ .../docker-selenium-grid-conf.js | 27 +++--- protractor-docker/package.json | 4 +- protractor-docker/specs/app.spec.js | 16 ++++ .../specs/protractor.e2e.spec.js | 2 +- 9 files changed, 202 insertions(+), 78 deletions(-) create mode 100644 protractor-docker/app/index.html create mode 100644 protractor-docker/app/index.js create mode 100644 protractor-docker/app/package.json create mode 100644 protractor-docker/specs/app.spec.js diff --git a/protractor-docker/README.md b/protractor-docker/README.md index 01deaec..0575967 100644 --- a/protractor-docker/README.md +++ b/protractor-docker/README.md @@ -111,24 +111,37 @@ We would do the above the steps , by specifying a .yml file and see the results. Create a docker-compose.yml ``` yaml -seleniumhub: - image: selenium/hub:2.53.0 - ports: - - 4444:4444 - -# firefoxnode: -# image: selenium/node-firefox -# expose: -# - 5900 -# links: -# - seleniumhub:hub - -chromenode: - image: selenium/node-chrome:2.53.0 - ports: - - 5900 - links: - - seleniumhub:hub +version: '3' +services: + chrome: + image: selenium/node-chrome-debug:3.11.0-californium + volumes: + - /dev/shm:/dev/shm + environment: + HUB_HOST: hub + ports: + - "5900:5900" + networks: + - protractortest + hub: + image: selenium/hub:3.11.0-californium + ports: + - "4444:4444" + networks: + - protractortest + angular: + image: node:6-alpine + ports: + - 8000:8000 + volumes: + - ./app:/var/www + working_dir: /var/www + command: ["npm", "start"] + networks: + - protractortest +networks: + protractortest: + name: protractortest ``` Then in the terminal, enter the command @@ -136,26 +149,11 @@ Then in the terminal, enter the command ``` shell docker-compose up -d ``` -In order to scale the number of chrome nodes , one can do : - -``` shell -docker-compose scale chromenode=5 -``` - -The number of nodes that one can connect to a selenium hub is by default 5.Hence `chromenode=5`. -If one wants to increase the number of nodes, one has to change the settings on Hub to support the additional nodes first. - -The best way to do would be to wrap all of the above in a shell script file . -Ensure the shell script file has execute permissions. ``` shell -docker -v -docker-compose -v - -docker-compose up -d --remove-orphans -docker-compose scale chromenode=5 +docker run -it --rm --network=protractortest -v /dev/shm:/dev/shm -v $(pwd):/protractor jozzhart/node-6-protractor ./docker-selenium-grid-conf.js ``` -and then reference it in the package.json +or use the shortcut ``` shell npm test diff --git a/protractor-docker/app/index.html b/protractor-docker/app/index.html new file mode 100644 index 0000000..f5e2109 --- /dev/null +++ b/protractor-docker/app/index.html @@ -0,0 +1,87 @@ + + + + + + + + + + + +
+
+
+
+
+
+
+

Todo

+
+ {{todoList.remaining()}} of {{todoList.todos.length}} remaining + [ + archive ] +
    +
  • + +
  • +
+
+ + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/protractor-docker/app/index.js b/protractor-docker/app/index.js new file mode 100644 index 0000000..e00d94c --- /dev/null +++ b/protractor-docker/app/index.js @@ -0,0 +1,12 @@ +var http = require('http'); +var fs = require('fs'); + +http.createServer(function (req, res) { + + res.writeHead(200, { + 'Content-Type': 'text/html' + }); + + fs.createReadStream('./index.html').pipe(res); + +}).listen(8000); \ No newline at end of file diff --git a/protractor-docker/app/package.json b/protractor-docker/app/package.json new file mode 100644 index 0000000..2807c7b --- /dev/null +++ b/protractor-docker/app/package.json @@ -0,0 +1,8 @@ +{ + "name": "protractor-docker-test-app", + "dependencies": { + }, + "scripts": { + "start": "node ./" + } +} diff --git a/protractor-docker/docker-compose.yml b/protractor-docker/docker-compose.yml index e1b6409..10626e7 100644 --- a/protractor-docker/docker-compose.yml +++ b/protractor-docker/docker-compose.yml @@ -1,25 +1,31 @@ -seleniumhub: - image: selenium/hub:2.53.0 - ports: - - 4444:4444 - -# chromednode: -# image: selenium/node-chrome-debug:2.53.0 -# expose: -# - 5900 -# links: -# - seleniumhub:hub - -# firefoxnode: -# image: selenium/node-firefox -# expose: -# - 5900 -# links: -# - seleniumhub:hub - -chromenode: - image: selenium/node-chrome:2.53.0 - ports: - - 5900 - links: - - seleniumhub:hub \ No newline at end of file +version: '3.5' +services: + chrome: + image: selenium/node-chrome-debug:3.11.0-californium + volumes: + - /dev/shm:/dev/shm + environment: + HUB_HOST: hub + ports: + - "5900:5900" + networks: + - protractortest + hub: + image: selenium/hub:3.11.0-californium + ports: + - "4444:4444" + networks: + - protractortest + angular: + image: node:6-alpine + ports: + - 8000:8000 + volumes: + - ./app:/var/www + working_dir: /var/www + command: ["npm", "start"] + networks: + - protractortest +networks: + protractortest: + name: protractortest \ No newline at end of file diff --git a/protractor-docker/docker-selenium-grid-conf.js b/protractor-docker/docker-selenium-grid-conf.js index 0dd38bf..79470ca 100644 --- a/protractor-docker/docker-selenium-grid-conf.js +++ b/protractor-docker/docker-selenium-grid-conf.js @@ -1,19 +1,16 @@ exports.config = { - framework: 'jasmine2' - , specs: ['specs/*.spec.js'] - , seleniumAddress: 'http://localhost:4444/wd/hub' - , capabilities: { - browserName: 'chrome' - , shardTestFiles: true - , maxInstances: 5 - } - , getPageTimeout: 180000 - , allScriptsTimeout: 180000 - , onPrepare: function () { - browser.manage().window().maximize(); - browser.manage().timeouts().implicitlyWait(5000); - } - , jasmineNodeOpts: { + framework: 'jasmine2', + specs: ['specs/*.spec.js'], + seleniumAddress: 'http://hub:4444/wd/hub', + capabilities: { + browserName: 'chrome', + chromeOptions: { + args: ["headless", "disable-gpu", "window-size=800,600"] + } + }, + getPageTimeout: 180000, + allScriptsTimeout: 180000, + jasmineNodeOpts: { defaultTimeoutInterval: 300000 } }; \ No newline at end of file diff --git a/protractor-docker/package.json b/protractor-docker/package.json index 06cea1c..6a486da 100644 --- a/protractor-docker/package.json +++ b/protractor-docker/package.json @@ -4,7 +4,7 @@ "protractor": "4.0.9" }, "scripts": { - "pretest": "npm install && ./docker-setup.sh", - "test": "protractor docker-selenium-grid-conf.js" + "test": "docker run -it --rm --network=protractortest -v /dev/shm:/dev/shm -v $(pwd):/protractor jozzhart/node-6-protractor ./docker-selenium-grid-conf.js", + "start": "node ./app" } } diff --git a/protractor-docker/specs/app.spec.js b/protractor-docker/specs/app.spec.js new file mode 100644 index 0000000..5730921 --- /dev/null +++ b/protractor-docker/specs/app.spec.js @@ -0,0 +1,16 @@ +describe('On app page', function () { + + beforeAll(function () { + browser.get('http://angular:8000') + }) + + it('should have the expected the title', function () { + expect(element(by.css('h1')).getText()).toBe('Todo'); + }); + + it('should update list when I add a todo item', function () { + element(by.css('input[type="text"]')).sendKeys('Add protractor test'); + element(by.css('.btn-primary')).click(); + expect(element(by.css('ul li:last-child')).getText()).toBe('Add protractor test'); + }); +}); \ No newline at end of file diff --git a/protractor-docker/specs/protractor.e2e.spec.js b/protractor-docker/specs/protractor.e2e.spec.js index fac5ccb..b5e73f2 100644 --- a/protractor-docker/specs/protractor.e2e.spec.js +++ b/protractor-docker/specs/protractor.e2e.spec.js @@ -5,6 +5,6 @@ describe('On Protractor page', function () { }); it('should have the expected the title', function () { - expect(browser.getTitle()).toBe('Protractor - end to end testing for AngularJS'); + expect(browser.getTitle()).toBe('Protractor - end-to-end testing for AngularJS'); }); }); From 745d719fe01aaf51cf371ff43c550a7f2a81fc77 Mon Sep 17 00:00:00 2001 From: Jozz Date: Thu, 5 Apr 2018 20:08:44 +0100 Subject: [PATCH 2/3] Update README.md --- protractor-docker/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protractor-docker/README.md b/protractor-docker/README.md index 0575967..48ce73c 100644 --- a/protractor-docker/README.md +++ b/protractor-docker/README.md @@ -111,7 +111,7 @@ We would do the above the steps , by specifying a .yml file and see the results. Create a docker-compose.yml ``` yaml -version: '3' +version: '3.5' services: chrome: image: selenium/node-chrome-debug:3.11.0-californium @@ -161,4 +161,4 @@ npm test Where to go next ---------------- -This should get you started with writing tests using Docker and Protractor . To learn more, see the documentation for [Docker](https://docs.docker.com) and [Protractor](http://www.protractortest.org/#/). \ No newline at end of file +This should get you started with writing tests using Docker and Protractor . To learn more, see the documentation for [Docker](https://docs.docker.com) and [Protractor](http://www.protractortest.org/#/). From eefbb7e2b96fa8e0093111337a9494df458e8cd6 Mon Sep 17 00:00:00 2001 From: Jozz Hart Date: Fri, 6 Apr 2018 10:21:11 +0100 Subject: [PATCH 3/3] Update protractor config --- protractor-docker/docker-selenium-grid-conf.js | 4 ++-- protractor-docker/specs/app.spec.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/protractor-docker/docker-selenium-grid-conf.js b/protractor-docker/docker-selenium-grid-conf.js index 79470ca..643b8eb 100644 --- a/protractor-docker/docker-selenium-grid-conf.js +++ b/protractor-docker/docker-selenium-grid-conf.js @@ -4,8 +4,8 @@ exports.config = { seleniumAddress: 'http://hub:4444/wd/hub', capabilities: { browserName: 'chrome', - chromeOptions: { - args: ["headless", "disable-gpu", "window-size=800,600"] + 'goog:chromeOptions': { + args: ["--headless", "--disable-gpu", "--window-size=800,600"] } }, getPageTimeout: 180000, diff --git a/protractor-docker/specs/app.spec.js b/protractor-docker/specs/app.spec.js index 5730921..6831393 100644 --- a/protractor-docker/specs/app.spec.js +++ b/protractor-docker/specs/app.spec.js @@ -1,7 +1,7 @@ describe('On app page', function () { beforeAll(function () { - browser.get('http://angular:8000') + browser.get('http://angular:8000'); }) it('should have the expected the title', function () {