Skip to content

Commit

Permalink
added app locally
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaelespazzoli committed Jul 15, 2018
1 parent 06dd286 commit ec704fa
Show file tree
Hide file tree
Showing 22 changed files with 1,237 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cucumber-selenium-grid/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pipeline {
steps {
// Turn off Git's SSL cert check, uncomment if needed
// sh 'git config --global http.sslVerify false'
git url: "${APPLICATION_SOURCE_REPO}"
git url: "${APPLICATION_SOURCE_REPO}", branch: "${APPLICATION_REF}"
}
}

Expand Down
4 changes: 4 additions & 0 deletions cucumber-selenium-grid/angularjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
/tmp/
/cucumber/
/npm-debug.log
8 changes: 8 additions & 0 deletions cucumber-selenium-grid/angularjs/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var express = require("express");

var app = express();
app.use('/', express.static(__dirname + '/'));

app.listen(8080, function(){
console.log('Running app on port 8080');
});
76 changes: 76 additions & 0 deletions cucumber-selenium-grid/angularjs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!doctype html>
<html lang="en" data-framework="angularjs">
<head>
<meta charset="utf-8">
<title>AngularJS • TodoMVC</title>
<link rel="stylesheet" href="node_modules/todomvc-common/base.css">
<link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
<style>[ng-cloak] { display: none; }</style>
</head>
<body ng-app="todomvc">
<ng-view></ng-view>

<script type="text/ng-template" id="todomvc-index.html">
<section class="todoapp">
<header class="header">
<h1>todos</h1>
<form class="todo-form" ng-submit="addTodo()">
<input class="new-todo" placeholder="What needs to be done?" ng-model="newTodo" ng-disabled="saving" autofocus>
</form>
</header>
<section class="main" ng-show="todos.length" ng-cloak>
<input id="toggle-all" class="toggle-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)">
<label for="toggle-all">Mark all as complete</label>
<ul class="todo-list">
<li ng-repeat="todo in todos | filter:statusFilter track by $index" ng-class="{completed: todo.completed, editing: todo == editedTodo}">
<div class="view">
<input class="toggle" type="checkbox" ng-model="todo.completed" ng-change="toggleCompleted(todo)">
<label ng-dblclick="editTodo(todo)">{{todo.title}}</label>
<button class="destroy" ng-click="removeTodo(todo)"></button>
</div>
<form ng-submit="saveEdits(todo, 'submit')">
<input class="edit" ng-trim="false" ng-model="todo.title" todo-escape="revertEdits(todo)" ng-blur="saveEdits(todo, 'blur')" todo-focus="todo == editedTodo">
</form>
</li>
</ul>
</section>
<footer class="footer" ng-show="todos.length" ng-cloak>
<span class="todo-count"><strong>{{remainingCount}}</strong>
<ng-pluralize count="remainingCount" when="{ one: 'item left', other: 'items left' }"></ng-pluralize>
</span>
<ul class="filters">
<li>
<a ng-class="{selected: status == ''} " href="#/">All</a>
</li>
<li>
<a ng-class="{selected: status == 'active'}" href="#/active">Active</a>
</li>
<li>
<a ng-class="{selected: status == 'completed'}" href="#/completed">Completed</a>
</li>
</ul>
<button class="clear-completed" ng-click="clearCompletedTodos()" ng-show="completedCount">Clear completed</button>
</footer>
</section>
<footer class="info">
<p>Double-click to edit a todo</p>
<p>Credits:
<a href="http://twitter.com/cburgdorf">Christoph Burgdorf</a>,
<a href="http://ericbidelman.com">Eric Bidelman</a>,
<a href="http://jacobmumm.com">Jacob Mumm</a> and
<a href="http://blog.igorminar.com">Igor Minar</a>
</p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
</script>
<script src="node_modules/todomvc-common/base.js"></script>
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-route/angular-route.js"></script>
<script src="node_modules/angular-resource/angular-resource.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/todoCtrl.js"></script>
<script src="js/services/todoStorage.js"></script>
<script src="js/directives/todoFocus.js"></script>
<script src="js/directives/todoEscape.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/**
* Step definitions.
*/
'use strict';

// Require and configure the assertion libraries.
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised'); // https://github.com/domenic/chai-as-promised/
chai.use(chaiAsPromised);

// Convenience.
var expect = chai.expect;
var _ = require('underscore');
const { setWorldConstructor } = require('cucumber')

var CustomWorld = function({attach, parameters}) {
this.attach = attach
this.parameters = parameters
};

CustomWorld.prototype.clearLocalStorage = function () {
browser.executeScript('localStorage.clear();');
};

CustomWorld.prototype.flattenTable = function (table) {
// Array of arrays e.g.
// [ [ 'First todo' ], [ 'Second todo' ] ]
table = table.raw();

// Flatten array
// [ 'First todo', 'Second todo' ]
return _.flatten(table);
};

setWorldConstructor(CustomWorld);

const { Given, When, Then, After, Before, Status } = require('cucumber');

//Require page objects.
var homePage = require('../../page-objects/home-page');

Before('@home', function () {
var world = this;

// Load the homepage.
homePage.get();
//browser.get('');

// Clear localStorage.
world.clearLocalStorage();

// Reload the page with empty localStorage.
homePage.get();
//browser.get('');

});

After(function (testCase) {
var world = this;
if (testCase.result.status === Status.FAILED) {
return browser.takeScreenshot().then(function(screenShot) {
// screenShot is a base-64 encoded PNG
world.attach(screenShot, 'image/png');
});
}
});

Given(/^I am on the app home page\.?$/, function (done) {
var expectedTitle = 'AngularJS • TodoMVC';

// The page loading is async so we need an async expectation
// and an async 'done'.

expect(homePage.getPageTitle())
.to.eventually.equal(expectedTitle)
.notify(done);
});


When(/^I add a todo called "([^"]*)"\.?$/, addTodoText);


When(/^I add the todos\.?$/, addTodoText);


// Use a data table. API here
// https://github.com/cucumber/cucumber-js/blob/master/lib/cucumber/ast/data_table.js
When(/^I add multiple todos:$/, function (table, done) {
var world = this;

table = world.flattenTable(table);

table.forEach(function (todoText) {
homePage.createTodo(todoText);
});

world.expectedNumberOfTodos = table.length;

done();
});


// Deliberately pending step.
// When(/^Something is done\.$/, function (done) {
// Write code here that turns the phrase above into concrete actions
// done.pending();
// });


Then(/^I should see it added to the todo list\.?$/, function (done) {
checkFirstTodoText(this.expectedTodoText, done);
});


Then(/^I should see a todo called "([^"]*)"\.?$/, function (expectedTodoText, done) {
checkFirstTodoText(expectedTodoText, done);
});



Then(/^I should see them added to the todo list\.$/, function (done) {
var world = this;

// Split the expected text string on new line to
// allow comparison to the array of todos taken
// from the UI.
var expectedTodoTextArray = world.expectedTodoText.split(/\r?\n/);

// Use Chai deep equal to compare arrays.
homePage.getAllTodoText()
.then(function(todoTextArray) {
expect(todoTextArray).to.deep.equal(expectedTodoTextArray);
done();
});
});


Then(/^there should be that number of todos in the list\.?$/, function (done) {
var world = this;
checkNumberOfTodos(world.expectedNumberOfTodos, done);
});


Then(/^it should (.*) in the list\.$/, function (appearOrNot, done) {
var expectedNumberOfTodos = (appearOrNot === 'appear') ? 1 : 0;
checkNumberOfTodos(expectedNumberOfTodos, done);
});


// Then(/^there should be a measurable result\.$/, function (done) {
// Write code here that turns the phrase above into concrete actions
// done.pending();
//});




/* Helper functions */


function checkFirstTodoText(expectedTodoText, done) {
// The underlying getText method and and all Protractor DOM
// action methods (i.e. actions on 'elelement' objects) are
// asynchronous, because they wait for the Angular digest
// loop to settle down, and return promises.
// Here the promise is handled explicitly in the check.
homePage.getFirstTodoText()
.then(function(todoText) {
try {
expect(todoText).to.equal(expectedTodoText);
done();
}
catch(err){
done(err);
}

});
}

function checkNumberOfTodos(expectedNumberOfTodos, done) {
// If using Chai-as-promised then promises for values can also
// be checked against using the 'eventually' property. Note
// the call to 'notify' with the Cucumber callback as an
// argument in order to signal step completion.
expect(homePage.getNumberOfTodos())
.to.eventually
.equal(expectedNumberOfTodos)
.notify(done);
}

function addTodoText(todoText, done) {
// Share state on the world object. Could also have done this with a closure.
/*jshint validthis:true */
var world = this;
world.expectedTodoText = todoText;

homePage.createTodo(todoText);
done();
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Example feature, the description is using feature injection syntax.
Feature: Todo list
As a user of the todo list
I want to be able to add and read todos
So that I can remember what I am supposed to do later


@home @smoke
Scenario: Adding a todo
Given I am on the app home page.
When I add a todo called "hello world".
Then I should see it added to the todo list.


# NB if you are comparing blocks of text beware of the file encoding
# UTF-8 and Unix line-endings are recommended.
@home @block-string
Scenario: Adding multiple todos in a block string
Given I am on the app home page.
When I add the todos
"""
First todo
Second todo
Third todo
"""
Then I should see them added to the todo list.


# Data table.
# Data tables: https://www.relishapp.com/cucumber/cucumber-js/docs/cucumber-tck/data-tables
@home @regression @data-table
Scenario: Adding multiple todos in a data table
Given I am on the app home page.
When I add multiple todos:
| First todo |
| Second todo |
Then there should be that number of todos in the list.



# Scenario outline.
# Scenario outlines: supported https://github.com/cucumber/cucumber-js/commit/c2a9916810a224d77c6b7e94260c39bb867aee5b
@home @outline
Scenario Outline: Edge case todos
Given I am on the app home page.
When I add a todo called "<todo text>".
Then it should <appear or not> in the list.

Examples:
| todo text | appear or not |
| howdy | appear |
| | not appear |


# Senario with a pending step.
@home @somePendingTest
Scenario: Anther great scenario
Given I am on the app home page.
When Something is done.
Then there should be a measurable result.

# Senario with a failing step.
@home @someFailingTest
Scenario: Yet anther great scenario
Given I am on the app home page.
When I add a todo called "expected to fail".
Then I should see a todo called "something totally different".
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Note: this directory is not in the features directory in order to avoid it being parsed by Cucumber as it looks for step definitions and hooks etc.
Loading

0 comments on commit ec704fa

Please sign in to comment.