Skip to content

Commit

Permalink
enable protractor testing of create and login to BusNet (hyperledger-…
Browse files Browse the repository at this point in the history
  • Loading branch information
nklincoln authored Oct 2, 2017
1 parent f493ceb commit 9461b52
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 46 deletions.
5 changes: 4 additions & 1 deletion packages/composer-playground-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const LOG = Logger.getLog('PlaygroundAPI');
*/
function createServer (port, testMode) {
const method = 'createServer';
LOG.entry(method, port);
LOG.entry(method, port, testMode);

const app = Util.createApp();

Expand All @@ -59,6 +59,9 @@ function createServer (port, testMode) {

server.listen(port);
LOG.info(method, `Playground API started on port ${port}`);
if(testMode) {
LOG.info(method, 'Playground API started in test mode');
}

LOG.exit(method, app);
return app;
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-playground-api/routes/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ module.exports = (app, testMode) => {


if (testMode) {
let readStream = fs.createReadStream('basic-sample-network-0.1.9.tgz');
let readStream = fs.createReadStream(__dirname + '/../basic-sample-network-0.1.9.tgz');

return downloadSample(readStream, res);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/composer-playground/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const argv = require('yargs')
type: 'number',
describe: 'The port to start composer on'
})
.option('t', {
alias: 'test',
demand: false,
default: false
})
.argv;

const Logger = require('composer-common').Logger;
Expand Down Expand Up @@ -58,7 +63,7 @@ Logger.setFunctionalLogger({
}
});

const app = require('composer-playground-api')(argv.port);
const app = require('composer-playground-api')(argv.port, argv.test);
const cheerio = require('cheerio');
const express = require('express');
const fs = require('fs');
Expand Down
61 changes: 61 additions & 0 deletions packages/composer-playground/e2e/component/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { browser, element, by } from 'protractor';
import { ExpectedConditions } from 'protractor';

import { OperationsHelper } from '../utils/operations-helper';
import { dragDropFile } from '../utils/fileUtils';

let baseTiles = ['basic-sample-network', 'empty-business-network', 'drag-drop'];

export class Deploy {

// Wait for appear
static waitToAppear() {
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.choose-network'))), 5000);
}

static waitToLoadDeployBasisOptions() {
return browser.wait(OperationsHelper.elementsPresent(element(by.css('.sample-network-list-container')).all(by.css('.sample-network-list-item')), baseTiles.length), 10000);
}

// Wait for disappear
static waitToDisappear() {
return browser.wait(ExpectedConditions.invisibilityOf(element(by.css('.choose-network'))), 5000);
}

// Name the network
static nameBusinessNetwork(name: string) {
return element(by.id('import-businessNetworkName')).sendKeys(name);
}

// Deploy selected Tile option from Base tiles
static selectDeployBasisOption(importOption: string) {
// Wait for poplation of sample-network-list-item(s)
this.retrieveBaseTileOptions()
.then((options) => {
// Figure out which one we want
let index = baseTiles.findIndex((tile) => tile === importOption);
let optionElement = options[index].getWebElement();
// Scroll into view
browser.executeScript('arguments[0].scrollIntoView();', optionElement);

// Click
optionElement.click();

// Confirm
let confirmElement = element(by.id('import_confirm'));
browser.executeScript('arguments[0].scrollIntoView();', confirmElement);
return OperationsHelper.click(confirmElement);
});
}

static retrieveBaseTileOptions() {
this.waitToLoadDeployBasisOptions();
return element(by.css('.sample-network-list-container')).all(by.css('.sample-network-list-item'));
}

// Deploy
static clickDeploy() {
let deployElement = element(by.id('import_confirm'));
return OperationsHelper.click(deployElement);
}
}
5 changes: 5 additions & 0 deletions packages/composer-playground/e2e/component/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ let scrollMe = (target) => {

export class Editor {

// Wait to appear
static waitToAppear() {
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.main-view'))), 5000);
}

// Click AddFile button
static clickAddFile() {
return OperationsHelper.click(element(by.id('editor_addfile')));
Expand Down
28 changes: 0 additions & 28 deletions packages/composer-playground/e2e/component/identity.ts

This file was deleted.

59 changes: 59 additions & 0 deletions packages/composer-playground/e2e/component/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { browser, element, by, ElementFinder, WebElement } from 'protractor';
import { ExpectedConditions } from 'protractor';

import { OperationsHelper } from '../utils/operations-helper';

export class Login {

static deployNewToProfile(profile: string) {
// Wish to find named connection profile and then select/click the 'empty' deploy card
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.connection-profile'))), 10000)
.then(() => {
return element.all(by.css('.connection-profile')).filter((item) => {
return item.element(by.css('.connection-profile-title')).getText()
.then((text) => { if (text.includes(profile)) { return true; } });
})
.then((matchedItems: [ElementFinder]) => {
if(matchedItems.length >1) {
return Promise.reject('Multiple conection profile name match occured');
} else {
return matchedItems[0].element(by.css('.connection-profile-card'));
}
})
.then((deployCard: ElementFinder) => {
return OperationsHelper.click(deployCard);
});
});
}

// Connect to Playground via named ID Card under named connectino profile
static connectViaIdCard(profile: string, networkName: string) {
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.connection-profile'))), 10000)
.then(() => {
// Retrieve components under named connection-profile
return element.all(by.css('.connection-profile')).filter((item) => {
return item.element(by.css('.connection-profile-title')).getText()
.then((text) => { if (text.includes(profile)) { return true; } });
})
.then((matchedItems) => {
if(matchedItems.length >1) {
return Promise.reject('Multiple conection profile name match occured');
} else {
return matchedItems[0];
}
})
.then((matchedItem) => {
return matchedItem.all(by.css('.identity-card')).filter((item) => {
return item.element(by.css('.business-network-details')).getText()
.then((text) => { if (text.includes(networkName)) { return true; } });
})
})
.then((cards) => {
let connect = cards[0].getWebElement().findElement(by.css('.connect'));
browser.wait(() => { return browser.isElementPresent(connect); }, 5000);
connect.click();
})
});
}

}
3 changes: 1 addition & 2 deletions packages/composer-playground/e2e/specs/editor-define.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExpectedConditions } from 'protractor';
import { OperationsHelper } from '../utils/operations-helper';
import { Editor } from '../component/editor';
import { Import } from '../component/import';
import { Identity } from '../component/identity';
import { Login } from '../component/login';
import { Replace } from '../component/replace';
import { AddFile } from '../component/add-file';
import { EditorFile } from '../component/editor-file';
Expand All @@ -27,7 +27,6 @@ describe('Editor Define', (() => {
// Important angular configuration and intial step passage to reach editor
browser.waitForAngularEnabled(false);
OperationsHelper.navigatePastWelcome();
Identity.connectViaNamedCard('admin');
});

afterAll(() => {
Expand Down
68 changes: 68 additions & 0 deletions packages/composer-playground/e2e/specs/login-define.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { browser, element, by } from 'protractor';
import { ExpectedConditions } from 'protractor';
import { OperationsHelper } from '../utils/operations-helper';
import { Login } from '../component/login';
import { Deploy } from '../component/deploy';
import { Editor } from '../component/editor';

import * as chai from 'chai';
import * as fs from 'fs';
import * as JSZip from 'jszip';

let expect = chai.expect;

describe('Login Define', (() => {

// Navigate to Playground base page and move past welcome splash
beforeAll(() => {
// Important angular configuration and intial step passage to reach login
browser.waitForAngularEnabled(false);
OperationsHelper.navigatePastWelcome();
});

afterAll(() => {
browser.waitForAngularEnabled(true);
browser.executeScript('window.sessionStorage.clear();');
browser.executeScript('window.localStorage.clear();');
});

describe('Create BusinessNetwork', (() =>{
it('should enable default BNetwork deploy on named connection profile', (() => {

let networkName = 'test-network';
let profile = 'Web Browser';

// Click to deploy on desired profile
Login.deployNewToProfile(profile)

// Deploy item should appear
Deploy.waitToAppear();
Deploy.waitToLoadDeployBasisOptions();

// Name the network and base it on empty network
Deploy.nameBusinessNetwork(networkName);
Deploy.selectDeployBasisOption('empty-business-network');

// Deploy
Deploy.clickDeploy();

// Should disappear and return to login page
Deploy.waitToDisappear();

// Should now have an ID Card with the business network name defined above
Login.connectViaIdCard(profile, networkName);

// Should now be on main editor page for the business network
Editor.waitToAppear();

// Should have the correct named busnet once loaded
Editor.waitForProjectFilesToLoad();
Editor.retrieveDeployedPackageName()
.then((packageName) => {
expect(packageName).to.be.equal(networkName);
});

}));
}));

}));
8 changes: 2 additions & 6 deletions packages/composer-playground/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ const snowWhite = require('sleep');
// Note that this script is called via npm run e2e:main/nobuild and consequently all
// paths are relative to that calling location (~/composer-playground)

// Start the api server as a spawned child process
let childAPI = spawn('node', ['../composer-playground-api/cli.js -test']);

// Start the target test server as a spawned child process
let childServer = spawn('node', ['cli.js', '-p', '3001']);
// Start the target test server as a spawned child process in test mode (no npm connections)
let childServer = spawn('node', ['cli.js', '-p', '3001', '-test']);

// Execute protractor and attach to listeners
var childProtractor = exec('webdriver-manager update && protractor -- protractor.conf.js');
Expand All @@ -33,7 +30,6 @@ childProtractor.on('close', function(code) {
code = 1;
}
console.log('Exit return code: ', code);
childAPI.kill();
childServer.kill();
process.exit(code);
});
6 changes: 2 additions & 4 deletions packages/composer-playground/e2e/utils/operations-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ export class OperationsHelper {
static click(elm: ElementFinder) {
browser.wait(ExpectedConditions.presenceOf(elm), 10000);
browser.wait(ExpectedConditions.visibilityOf(elm), 10000);
browser.wait(ExpectedConditions.elementToBeClickable(elm), 10000);
// Scroll into view
browser.executeScript('arguments[0].scrollIntoView();', elm);
return browser.wait(() => {
return elm.click()
.then(() => true)
.catch(() => false);
});
}
});
}

// Retrieve text from an element
static retriveTextFromElement(elm: ElementFinder) {
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-playground/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports.config = {
directConnect: true,
baseUrl: 'http://127.0.0.1:3001',
specs: ['./e2e/specs/welcome.spec.ts',
/* './e2e/specs/editor-define.spec.ts' */],
'./e2e/specs/login-define.spec.ts'],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<section *ngIf="!showSubScreen" class="header">
<h1>My Wallet</h1>
<div *ngIf="!showSubScreen">
<button *ngIf="usingLocally" type="button" class="secondary" (click)="importIdentity()">
<button id="importIdCard" *ngIf="usingLocally" type="button" class="secondary" (click)="importIdentity()">
<span>Import ID card</span>
</button>
<button *ngIf="usingLocally" type="button" class="secondary" (click)="createIdCard()">
<button id="createIdCard" *ngIf="usingLocally" type="button" class="secondary" (click)="createIdCard()">
<span>Create ID card</span>
</button>
</div>
Expand Down

0 comments on commit 9461b52

Please sign in to comment.