Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
local.log
screenshots
.env
browserstack.err
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
# .github

This repository provides some base files for setting up a repository at
CDS.
# Browser - UI Automate

This is a tool to cross-test GC Form's webpages from the UI's point of view using selenium
and the Browser Stack API to ensure browsers compatibility.

## Requirements

A system with `docker` and `docker-compose` installed and available on the
path.

See the [Docker Homepage](https://www.docker.com/) for more details on
installation of docker.

### Environment Variables

Below is a list of the Environment variable requirements to run the UI automate.
Please considere add them to `.env` file.
- `BROWSERSTACK_USERNAME`: Your username in browserstack
- `BROWSERSTACK_ACCESSKEY`: Your access key in browserstack

To get the browser stack credentials see your [BrowserStack Account Settings](https://www.browserstack.com/accounts/settings)

### Setup
* Clone the repo
* Install dependencies `npm install`
* Update `*.conf.js` files inside the `conf/` directory with your BS Username and Access Key

### Running your tests
* To run a single test, run `npm run single`
* To run local tests, run `npm run local`
12 changes: 12 additions & 0 deletions conf/local.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exports.config = {
user: 'BROWSERSTACK_USERNAME',
key: 'BROWSERSTACK_ACCESS_KEY',
server: 'hub-cloud.browserstack.com',

capabilities: [{
browserName: 'chrome',
name: "local_test",
build: "GC Forms - Formulaires GC UI-Automate",
'browserstack.local': true
}]
}
11 changes: 11 additions & 0 deletions conf/single.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.config = {
user: 'BROWSERSTACK_USERNAME',
key: 'BROWSERSTACK_ACCESS_KEY',
server: 'hub-cloud.browserstack.com',

capabilities: [{
browserName: 'chrome',
name: "single_test",
build: "GC Forms - Formulaires GC UI-Automate"
}]
}
5 changes: 5 additions & 0 deletions features/local.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: BrowserStack Local Testing

Scenario: Can check tunnel working
When I open health check
Then I should see "Up and running"
8 changes: 8 additions & 0 deletions features/single.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: GC Forms landing page
As a user of GC Forms
I want to land on GC forms welcome page
So that I can fill out a form

Scenario: Rendering GC Forms landing page
When I navigate to GC forms
Then I should see title "GC Forms - Formulaires GC"
19 changes: 19 additions & 0 deletions features/step_definitions/gc-forms-landing-page-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const assert = require('cucumber-assert');
const webdriver = require('selenium-webdriver');

module.exports = function() {

this.When('I navigate to GC forms', function (next) {
this.driver.get('https://forms-staging.cdssandbox.xyz');
next();
});

this.Then(/^I should see title "([^"]*)"$/, function (titleMatch, next) {
this.driver.getTitle()
.then(function(title) {
assert.equal(title, titleMatch, next, 'Expected title to be ' + titleMatch);
});
});
};
19 changes: 19 additions & 0 deletions features/step_definitions/local-step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const assert = require('cucumber-assert');
const webdriver = require('selenium-webdriver');

module.exports = function() {

this.When(/^I open health check$/, function (next) {
this.driver.get('http://myip:40091/check');
next();
});

this.Then(/^I should see "([^"]*)"$/, function (sourceMatch, next) {
this.driver.getPageSource()
.then(function(source) {
assert.equal(source.indexOf(sourceMatch) > -1, true, next, 'Expected source to contain ' + sourceMatch);
});
});
};
5 changes: 5 additions & 0 deletions features/support/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var configure = function () {
this.setDefaultTimeout(60 * 1000);
};

module.exports = configure;
54 changes: 54 additions & 0 deletions features/support/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';
require('dotenv').config();
const webdriver = require('selenium-webdriver');
const browserstack = require('browserstack-local');

const config_file = '../../conf/' + (process.env.CONFIG_FILE || 'single') + '.conf.js';
const config = require(config_file).config;

const username = process.env.BROWSERSTACK_USERNAME || config.user;
const accessKey = process.env.BROWSERSTACK_ACCESS_KEY || config.key;
//Bs Session
const createBrowserStackSession = function(config, caps){
return new webdriver.Builder().
usingServer('http://'+config.server+'/wd/hub').
withCapabilities(caps).
build();
}

const myHooks = function () {
let bs_local = null;

this.Before(function (scenario, callback) {
const world = this;
const task_id = parseInt(process.env.TASK_ID || 0);
const caps = config.capabilities[task_id];
caps['browserstack.user'] = username;
caps['browserstack.key'] = accessKey;

if(caps["browserstack.local"]){
bs_local = new browserstack.Local();
bs_local.start({'key': accessKey }, function(error) {
if (error) return console.log(error.red);

world.driver = createBrowserStackSession(config, caps);
callback();
});
}
else {
world.driver = createBrowserStackSession(config, caps);
callback();
}
});
// stop and close sessions
this.After(function(scenario, callback){
this.driver.quit().then(function(){
if(bs_local){
bs_local.stop(callback);
}
else callback();
});
});
};

module.exports = myHooks;
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "ui-automate",
"version": "0.0.1",
"description": " GC Forms - Formulaires GC UI-Automate with Selenium webdriver",
"scripts": {
"test": "npm run single && npm run local && npm run parallel",
"single": "cross-env CONFIG_FILE=single ./node_modules/cucumber/bin/cucumber.js features/single.feature",
"local": "cross-env CONFIG_FILE=local ./node_modules/cucumber/bin/cucumber.js features/local.feature",
"parallel": "cross-env CONFIG_FILE=parallel ./scripts/runner.js features/single.feature"
},
"devDependencies": {
"cucumber": "1.3.3",
"cucumber-assert": "1.0.4",
"selenium-webdriver": "^3.6.0"
},
"dependencies": {
"browserstack-local": "^1.0.0",
"cross-env": "^5.2.0",
"dotenv": "^10.0.0"
}
}
18 changes: 18 additions & 0 deletions scripts/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
require('dotenv').config();
const os = require('os');

const child_process = require('child_process');
const config_file = '../conf/' + (process.env.CONFIG_FILE || 'single') + '.conf.js';
const config = require(config_file).config;
const command = '/usr/bin/env';

process.argv[0] = 'node';
process.argv[1] = './node_modules/cucumber/bin/cucumber.js';

for(var i in config.capabilities){
let env = Object.create( process.env );
env.TASK_ID = i.toString();
let p = child_process.spawn(command, process.argv, { env: env } );
p.stdout.pipe(process.stdout);
}
Loading