Skip to content

Commit

Permalink
Fix #5 Ability to start from a project sample
Browse files Browse the repository at this point in the history
  • Loading branch information
racodond committed Nov 22, 2018
1 parent 75f2d17 commit 255532e
Show file tree
Hide file tree
Showing 29 changed files with 557 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Note that it requires good development skills as well as good knowledge and unde
1. Create a new folder <AUTOMATED_TESTS> in your project to host your automated tests.
2. Create a new NPM project by executing `npm init`. More information about the different options [here](https://docs.npmjs.com/getting-started/using-a-package.json).
3. Install EAT package by running the following command from <AUTOMATED_TESTS>: `npm install --save etaf`. It creates a `node_modules` directory containing all the dependencies needed to run the project.
4. From <AUTOMATED_TESTS>, run `npx etaf install` to generate the skeleton of your test project.
4. From <AUTOMATED_TESTS>, run `npx etaf install` to generate the skeleton of your test project. If you want to generate the skeleton of your project with some working samples, run: `npx etaf install --sample=true` and then run `npm install --no-optional`

### Behind a Proxy
Set the configuration of your proxy by editing the `.npmrc` file in your home directory:
Expand Down
29 changes: 27 additions & 2 deletions bin/etaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const gulpDel = require('del');
const gulpMocha = require('gulp-mocha');
const webdriver = require('gulp-webdriver');
const yargs = require('yargs');
const replace = require('replace');
const wdioOptions = { cucumberOpts: {} };
let configFile;

Expand Down Expand Up @@ -76,7 +77,7 @@ const runProject = config => {
* Create project structure tree.
* @return {Promise}
*/
const installProject = async () => {
const installProject = async(config) => {
console.log('Creating test project structure...');

const allPromises = [
Expand Down Expand Up @@ -104,6 +105,24 @@ const installProject = async () => {
await fs.move('gitignore', '.gitignore');
await fs.move('npmrc', '.npmrc');
console.log('Test project structure successfully created.');

if (config.sample == 'true') {
console.log('Adding project sample...');
await fs.copy('node_modules/etaf/sample', '.');
replace({
regex: "baseUrl: 'http://localhost:8080'",
replacement: "baseUrl: 'https://racodond.github.io/test-automation-website/'",
paths: ['wdio.conf.js', 'wdio.local.conf.js'],
silent: true,
});
replace({
regex: 'dependencies": {',
replacement: 'dependencies": {\n "faker": "4.1.0",',
paths: ['package.json'],
silent: true,
});
console.log("Project sample successfully added.")
}
} catch (err) {
console.error(err);
process.exit(1);
Expand All @@ -119,7 +138,13 @@ yargs
.command({
command: 'install',
desc: 'Create project structure tree',
handler: () => installProject(),
handler: argv => installProject(argv),
builder: yargsObj => {
yargsObj.option('sample', {
describe: 'To populate the project structure with a sample project.',
default: 'false',
});
},
})
.command({
command: 'generate-local-conf',
Expand Down
1 change: 1 addition & 0 deletions lib/conf/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs-extra');
const path = require('path');
const replace = require('replace');

const getAllFilesIn = function (dir, filelist) {
let files = filelist || [];
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"merge": "1.2.1",
"mocha": "5.2.0",
"path": "0.12.7",
"replace": "1.0.0",
"sinon": "7.1.1",
"sinon-chai": "3.2.0",
"wdio-allure-reporter": "0.8.3",
Expand Down
22 changes: 22 additions & 0 deletions sample/conf/realm/all-docker-chrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const merge = require('merge');

let config = require('./part/all');
config = merge.recursive(true, require('./part/docker'), config);
config = merge.recursive(true, require('./part/chrome'), config);
config = merge.recursive(true,
{
reporterOptions: {
json: {
outputDir: 'output-json/all-docker-chrome/',
filename: 'report',
combined: 'true',
},
},
host: 'chrome',
},
config);
config = merge.recursive(true, require('../../wdio.conf').config, config);

exports.config = config;
23 changes: 23 additions & 0 deletions sample/conf/realm/all-docker-firefox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const merge = require('merge');

let config = require('./part/all');
config = merge.recursive(true, require('./part/docker'), config);
config = merge.recursive(true, require('./part/firefox'), config);
config = merge.recursive(
true,
{
reporterOptions: {
json: {
outputDir: 'output-json/all-docker-firefox/',
filename: 'report',
combined: 'true',
},
},
host: 'firefox',
},
config);
config = merge.recursive(true, require('../../wdio.conf').config, config);

exports.config = config;
7 changes: 7 additions & 0 deletions sample/conf/realm/part/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
specs: [
'./src/features/**/*.feature',
],
};
39 changes: 39 additions & 0 deletions sample/conf/realm/part/chrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

module.exports = {
capabilities: [
{
browserName: 'chrome',
chromeOptions: {
// args: ['--headless'],
prefs: {
profile: {
default_content_setting_values: { images: 2 }, // Do not load images for tests to run faster
password_manager_enabled: false, // Deactivate password manager
},
credentials_enable_service: false, // Deactivate password manager
},
},
},
],

// seleniumInstallArgs: {
// proxy: 'http://localhost:3128',
// drivers: {
// chrome: {
// version: '2.43',
// arch: process.arch,
// baseURL: 'https://chromedriver.storage.googleapis.com',
// },
// },
// },
// seleniumArgs: {
// drivers: {
// chrome: {
// version: '2.43',
// arch: process.arch,
// },
// },
// },

};
5 changes: 5 additions & 0 deletions sample/conf/realm/part/docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
services: [],
};
33 changes: 33 additions & 0 deletions sample/conf/realm/part/firefox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

module.exports = {
capabilities: [
{
browserName: 'firefox',
acceptInsecureCerts: true,
// "moz:firefoxOptions": {
// args: ['-headless'],
// }
},
],

// seleniumInstallArgs: {
// proxy: 'http://localhost:3128',
// drivers: {
// firefox: {
// version: '0.23.0',
// arch: process.arch,
// baseURL: 'https://github.com/mozilla/geckodriver/releases/download',
// },
// },
// },
// seleniumArgs: {
// drivers: {
// firefox: {
// version: '0.23.0',
// arch: process.arch,
// },
// },
// },

};
8 changes: 8 additions & 0 deletions sample/docker/docker-compose-sample-project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -euo pipefail

export RUN_AS_UID=$(id -u)

docker-compose up --build --exit-code-from sample-project
docker-compose down
23 changes: 23 additions & 0 deletions sample/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3'
services:
chrome:
image: selenium/standalone-chrome:3.14.0
container_name: chrome
environment:
- JAVA_OPTS=-Dselenium.LOGGER.level=WARNING
firefox:
image: selenium/standalone-firefox:3.14.0
container_name: firefox
environment:
- JAVA_OPTS=-Dselenium.LOGGER.level=WARNING
sample-project:
image: node:8
container_name: sample-project
command: /data/docker/run-sample-project-docker.sh
volumes:
- ../.:/data
environment:
- RUN_AS_UID=${RUN_AS_UID}
depends_on:
- firefox
- chrome
17 changes: 17 additions & 0 deletions sample/docker/run-sample-project-docker-ft.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -euo pipefail

cd /data

echo "Installing sample project dependencies..."
npm install
echo "Sample project dependencies installed."

echo "Running end-to-end tests on all-docker-chrome realm..."
npx etaf run --realm='all-docker-chrome'
echo "End-to-end tests run on all-docker-chrome realm."

echo "Running end-to-end tests on all-docker-firefox realm..."
npx etaf run --realm='all-docker-firefox'
echo "End-to-end tests run on all-docker-firefox realm."
13 changes: 13 additions & 0 deletions sample/docker/run-sample-project-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -euo pipefail

if id "testrunner" >/dev/null 2>&1; then
echo "User 'testrunner' already exists."
else
echo "Creating user 'testrunner'..."
useradd -u $RUN_AS_UID -o -m -p $(echo testrunner | openssl passwd -1 -stdin) testrunner
echo "User 'testrunner' created."
fi

su testrunner -c '/data/docker/run-sample-project-docker-ft.sh'
21 changes: 21 additions & 0 deletions sample/src/features/navigation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Navigate

Scenario Outline: Navigate directly to URL
When I go to the <page> page
Then I should be on the <page> page
Examples:
| page |
| home |
| search |
| results |
| contact |

@smoke
Scenario Outline: Navigate from the home page menu
When I am on the home page
When I go to the <page> page from the home page menu
Then I should be on the <page> page
Examples:
| page |
| search |
| contact |
27 changes: 27 additions & 0 deletions sample/src/features/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: Search engine

Background:
Given I am on the search page

@smoke
Scenario: Search for something and land on the results page
When I search for something
Then I should be on the results page

@smoke
Scenario: Search for something that exists and see some results
When I search for something that exists
Then I should be on the results page
And I should see some results

@smoke
Scenario: Search for something that does not exist and see no results
When I search for something that does not exist
Then I should be on the results page
And I should be told that no results have been found

@query-reminder
Scenario: Be reminded the search query on the results page
When I search for something
Then I should be on the results page
And I should be reminded what I searched for
25 changes: 25 additions & 0 deletions sample/src/step_definitions/navigate.step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const { defineSupportCode } = require('cucumber');

defineSupportCode(function ({ Given, When, Then }) {

Given(/^I am on the (.+) page$/, function (pageName) {
return browser
.goToPage(pageName)
.seePage(pageName);
});

When(/^I go to the (.+) page$/, function (pageName) {
return browser.goToPage(pageName);
});

When(/^I go to the (.+) page from the home page menu$/, function (pageName) {
return browser.goToPageFromHomePageMenu(pageName);
});

Then(/^I should be on the (.+) page$/, function (pageName) {
return browser.seePage(pageName);
});

});
39 changes: 39 additions & 0 deletions sample/src/step_definitions/search.step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

require('src/support/business-object/search.bo');

const { defineSupportCode } = require('cucumber');

defineSupportCode(function ({ Before, Given, When, Then }) {

let query = require('src/support/data/search/search-for-something.data');

Before({ tags: '@query-reminder' }, function() {
query = require('src/support/data/search/search-for-something-query-reminder.data');
});

When(/^I search for something$/, function () {
return browser.search(query);
});

When(/^I search for something that does not exist$/, function () {
return browser.searchForSomethingThatDoesNotExist();
});

When(/^I search for something that exists$/, function () {
return browser.searchForSomethingThatExists();
});

Then(/^I should see some results$/, function () {
return browser.seeResults();
});

Then(/^I should be told that no results have been found$/, function () {
return browser.seeNoResults();
});

Then(/^I should be reminded what I searched for$/, function () {
return browser.seeSearchQuery(query);
});

});
Loading

0 comments on commit 255532e

Please sign in to comment.