Skip to content

Commit

Permalink
BE-654 Add script to setup fabric for GUI e2e test
Browse files Browse the repository at this point in the history
Use first-network as underlying fabric network for GUI e2e test environment.
Add scripts for GUI e2e test to package.json
You can run e2e test for GUI manually with the following command:
  npm run e2e-gui-test

Change-Id: I3b2aaced5fa5039268f72975d9502d70e6d5119d
Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia committed Jun 17, 2019
1 parent f647b1d commit ecb62a1
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 18 deletions.
19 changes: 19 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ node ('hyp-x') { // trigger build on x86_64 node
}
}

// Run npm tests
stage("E2E Tests of GUI for Sanity-check") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}") {
sh '''
npm install
npm run e2e-gui-test:ci
'''
}
}
catch (err) {
failure_stage = "e2e tests for GUI"
currentBuild.result = 'FAILURE'
throw err
}
}
}

// Docs HTML Report
stage("Doc Output") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
Expand Down
91 changes: 91 additions & 0 deletions client/e2e-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

#
# SPDX-License-Identifier: Apache-2.0
#


ROOTDIR="$(cd "$(dirname "$0")"/.. && pwd)"
export CORE_PEER_NETWORKID=e2egui
export COMPOSE_PROJECT_NAME=$CORE_PEER_NETWORKID
export NETWORK_PROFILE=first-network

docker rm -f $(docker ps -aq)
docker volume rm -f $(docker volume ls -q)

TIMEOUT=600
DELAY=10

#
# Setup fabric-samples/first-network
#
pushd $ROOTDIR/app/platform/fabric/e2e-test/fabric-samples/first-network

rm -rf ../../configs/$CORE_PEER_NETWORKID
rm -rf channel-artifacts/* ordererOrganizations peerOrganizations

mkdir -p ../../configs/$CORE_PEER_NETWORKID
./byfn.sh generate -c mychannel

cp -a channel-artifacts ordererOrganizations peerOrganizations ../../configs/$CORE_PEER_NETWORKID

docker-compose -f docker-compose-cli.yaml down -v
docker-compose -f docker-compose-cli.yaml up -d

# continue to poll
# we either get a matched keyword, or reach TIMEOUT
rc=1
starttime=$(date +%s)
while
[[ "$(($(date +%s) - starttime))" -lt "$TIMEOUT" ]] && [[ $rc -ne 0 ]];
do
sleep $DELAY
set -x
docker logs cli | grep -q "All GOOD, BYFN execution completed"
rc=$?
set +x
done

popd

#
# Bring up Explorer
#
pushd $ROOTDIR/app/platform/fabric/e2e-test/docker-compose
docker-compose -f docker-compose-explorer.yaml down -v
docker-compose -f docker-compose-explorer.yaml up -d

rc=1
starttime=$(date +%s)
while
[[ "$(($(date +%s) - starttime))" -lt "$TIMEOUT" ]] && [[ $rc -ne 0 ]];
do
sleep $DELAY
set -x
docker logs explorer.mynetwork.com | grep -q "Please open web browser to access"
rc=$?
set +x
done

popd

#
# Start selenium standalone server
#
pushd $ROOTDIR/client/test
docker-compose down
docker-compose up -d

rc=1
starttime=$(date +%s)
while
[[ "$(($(date +%s) - starttime))" -lt "$TIMEOUT" ]] && [[ $rc -ne 0 ]];
do
sleep $DELAY
set -x
docker logs selenium-chrome | grep -q "The node is registered to the hub and ready to use"
rc=$?
set +x
done

popd
114 changes: 100 additions & 14 deletions client/test/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
*/

require('chai').should();
var expect = require('chai').expect;

describe('Explorer dashboard', () => {
it('shoud have a correct title', () => {
browser.setTimeout({
timeouts: 100000
});
browser.url('/');
before(function() {
// runs before all tests in this block
browser.url('http://explorer.mynetwork.com:8080');
// Login
var userInput = browser.$('#user');
var passInput = browser.$('#password');
Expand All @@ -19,15 +18,102 @@ describe('Explorer dashboard', () => {

signinBtn.click();
browser.pause(1000);
});

describe('statistics', () => {
it('shoud have a metrics', () => {
browser.setTimeout({
timeouts: 100000
});

// Num. of blocks
var nodeNum = browser
.$(
'#root > div > div > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div:nth-child(2) > h1'
)
.getText();
nodeNum.should.be.equal('5');

// Num. of TX
var txNum = browser
.$(
'#root > div > div > div > div > div:nth-child(1) > div > div > div:nth-child(2) > div > div:nth-child(2) > h1'
)
.getText();
txNum.should.be.equal('5');

// Num. of Nodes
var nodeNum = browser
.$(
'#root > div > div > div > div > div:nth-child(1) > div > div > div:nth-child(3) > div > div:nth-child(2) > h1'
)
.getText();
nodeNum.should.be.equal('4');

// Num. of CC
var ccNum = browser
.$(
'#root > div > div > div > div > div:nth-child(1) > div > div > div:nth-child(4) > div > div:nth-child(2) > h1'
)
.getText();
ccNum.should.be.equal('1');
});
});

describe('peers', () => {
it('should have 4 peers', () => {
var peerList = browser.$(
'#root > div > div > div > div > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div > div > div.rt-table > div.rt-tbody'
);
var elmNum = peerList.getProperty('childElementCount');
elmNum.should.be.equal(4);
});

// Dashboard
var title = browser.getTitle();
title.should.be.equal('Hyperledger Explorer');
var nodeNum = browser
.$(
'#root > div > div > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div:nth-child(2) > h1'
)
.getText();
nodeNum.should.be.equal('5');
it('should have the correct URL for each peer', () => {
var peerUrlList = browser.$$(
'#root > div > div > div > div > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div > div > div.rt-table > div.rt-tbody > div > div > div'
);
let peerUrlStrList = peerUrlList.map((elm, idx, array) => {
return elm.getText();
});
expect(peerUrlStrList).to.include('peer0.org1.example.com');
expect(peerUrlStrList).to.include('peer1.org1.example.com');
expect(peerUrlStrList).to.include('peer0.org2.example.com');
expect(peerUrlStrList).to.include('peer1.org2.example.com');
});
});

describe('blocks', () => {
it('should have 3 block entries', () => {
var blkList = browser.$$(
'#root > div > div > div > div > div:nth-child(2) > div:nth-child(1) > div:nth-child(2) > div > div > div > section > div > div > div:nth-child(2) > div:nth-child(1)'
);
blkList[0].getText().should.be.equal('Block 4');
blkList[1].getText().should.be.equal('Block 3');
blkList[2].getText().should.be.equal('Block 2');
});
});

describe('MSP pie chart', () => {
it('should response to click', () => {
var tooltip = browser.$(
'#root > div > div > div > div > div:nth-child(2) > div:nth-child(2) > div > div > div > div.recharts-tooltip-wrapper.recharts-tooltip-wrapper-right.recharts-tooltip-wrapper-bottom > div > ul > li > span.recharts-tooltip-item-name'
);
var displayTooltip = tooltip.isExisting();
expect(displayTooltip).to.be.false;

var path = browser.$(
'#root > div > div > div > div > div:nth-child(2) > div:nth-child(2) > div > div > div > svg > g > g:nth-child(1)'
);
path.click();

var tooltip = browser.$(
'#root > div > div > div > div > div:nth-child(2) > div:nth-child(2) > div > div > div > div.recharts-tooltip-wrapper.recharts-tooltip-wrapper-right.recharts-tooltip-wrapper-bottom > div > ul > li > span.recharts-tooltip-item-name'
);

var displayTooltip = tooltip.isExisting();
expect(displayTooltip).to.be.true;
console.log(tooltip.getText());
});
});
});
28 changes: 28 additions & 0 deletions client/test/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: Apache-2.0
version: '2.1'

networks:
e2egui-net:
external:
name: e2egui_behave

services:
chrome:
image: selenium/node-chrome:3.141.59-palladium
container_name: selenium-chrome
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
networks:
- e2egui-net

hub:
image: selenium/hub:3.141.59-palladium
container_name: selenium-hub
ports:
- "4444:4444"
networks:
- e2egui-net
10 changes: 8 additions & 2 deletions client/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ exports.config = {
'goog:chromeOptions': {
// to run chrome headless the following flags are required
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
args: ['--headless', '--disable-gpu']
args: [
'--headless',
'--disable-gpu',
'--whitelisted-ips',
'--no-sandbox',
'--disable-extensions'
]
}
// If outputDir is provided WebdriverIO can capture driver session logs
// it is possible to configure which logTypes to include/exclude.
Expand Down Expand Up @@ -112,7 +118,7 @@ exports.config = {
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
services: ['selenium-standalone'],
// services: ['selenium-standalone'],
//
// Framework you want to run your specs with.
// The following are supported: Mocha, Jasmine, and Cucumber
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@
"precommit": "lint-staged && ./scripts/verify-license.sh",
"e2e-test-check-tool": "/bin/bash -c 'if [[ -z $(which configtxgen) ]]; then echo \"### Need to install tools ###\n\"; exit -1; fi'",
"e2e-test-check-img": "/bin/bash -c 'if [[ -z $(docker images -q hyperledger/fabric-peer:latest) ]]; then echo \"### Need to pull fabric images ###\n\"; exit -1; fi'",
"e2e-test-setup-tool:ci": "/bin/bash -c 'mkdir fabric-samples; pushd fabric-samples; curl -sSL https://raw.githubusercontent.com/hyperledger/fabric-samples/release-1.4/scripts/bootstrap.sh | bash -s; popd'",
"e2e-test-setup-tool:ci": "/bin/bash -c 'curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s -- 1.4.0 1.4.0 0.4.14 -s'",
"e2e-test-setup-env": "cd app/platform/fabric/e2e-test; if [ ! -e e2e-test ]; then virtualenv e2e-test; fi && . ./e2e-test/bin/activate && pip install -r requirement.txt",
"e2e-test-setup-img": "./build_docker_image.sh",
"e2e-test-run": "cd app/platform/fabric/e2e-test; . ./e2e-test/bin/activate && behave explorer.feature",
"e2e-test-run-sanitycheck": "cd app/platform/fabric/e2e-test; . ./e2e-test/bin/activate && behave --tags=@sanitycheck --stop --no-skipped explorer.feature",
"e2e-test": "run-s e2e-test-check-tool e2e-test-check-img e2e-test-setup-env e2e-test-setup-img e2e-test-run",
"e2e-test-sanitycheck:ci": "cross-env PATH=$PATH:$PWD/fabric-samples/bin run-s e2e-test-setup-tool:ci e2e-test-check-tool e2e-test-check-img e2e-test-setup-env e2e-test-setup-img e2e-test-run-sanitycheck"
"e2e-test-sanitycheck:ci": "cross-env PATH=$PATH:$PWD/bin run-s e2e-test-setup-tool:ci e2e-test-check-tool e2e-test-check-img e2e-test-setup-env e2e-test-setup-img e2e-test-run-sanitycheck",
"e2e-gui-test-setup-env": "cd client; npm install",
"e2e-gui-test-setup": "./client/e2e-setup.sh",
"e2e-gui-test-run": "cd client; npx wdio",
"e2e-gui-test": "run-s e2e-gui-test-setup e2e-gui-test-run",
"e2e-gui-test:ci": "cross-env PATH=$PATH:$PWD/bin run-s e2e-test-check-tool e2e-test-setup-img e2e-gui-test-setup-env e2e-gui-test-setup e2e-gui-test-run"
}
}

0 comments on commit ecb62a1

Please sign in to comment.