Functional test suite starter
Contains test runner Docker file and a sample smoke test. Smoke test build PolyGerrit app, serves it locally and expects page title to be updated to the default value. Change-Id: I8ab2ca8a97830eefa1c697c2e51be82cbc1657c7
This commit is contained in:
54
polygerrit-ui/app/test/functional/README.md
Normal file
54
polygerrit-ui/app/test/functional/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Functional test suite
|
||||
|
||||
## Installing Docker (OSX)
|
||||
|
||||
Simplest way to install all of those is to use Homebrew:
|
||||
|
||||
```
|
||||
brew cask install docker
|
||||
```
|
||||
|
||||
This will install a Docker in Applications. To run if from the command-line:
|
||||
|
||||
```
|
||||
open /Applications/Docker.app
|
||||
```
|
||||
|
||||
It'll require privileged access and will require user password to be entered.
|
||||
|
||||
To validate Docker is installed correctly, run hello-world image:
|
||||
|
||||
```
|
||||
docker run hello-world
|
||||
```
|
||||
|
||||
## Building a Docker image
|
||||
|
||||
Should be done once only for development purposes, run from the Gerrit checkout
|
||||
path:
|
||||
|
||||
```
|
||||
docker build -t gerrit/polygerrit-functional:v1 \
|
||||
polygerrit-ui/app/test/functional/infra
|
||||
```
|
||||
|
||||
## Running a smoke test
|
||||
|
||||
Running a smoke test from Gerrit checkout path:
|
||||
|
||||
```
|
||||
./polygerrit-ui/app/test/functional/run_functional.sh
|
||||
```
|
||||
|
||||
The successful output should be something similar to this:
|
||||
|
||||
```
|
||||
Starting local server..
|
||||
Starting Webdriver..
|
||||
Started
|
||||
.
|
||||
|
||||
|
||||
1 spec, 0 failures
|
||||
Finished in 2.565 seconds
|
||||
```
|
38
polygerrit-ui/app/test/functional/infra/Dockerfile
Normal file
38
polygerrit-ui/app/test/functional/infra/Dockerfile
Normal file
@@ -0,0 +1,38 @@
|
||||
FROM selenium/standalone-chrome-debug
|
||||
|
||||
USER root
|
||||
|
||||
# nvm environment variables
|
||||
ENV NVM_DIR /usr/local/nvm
|
||||
ENV NODE_VERSION 9.4.0
|
||||
|
||||
# install nvm
|
||||
# https://github.com/creationix/nvm#install-script
|
||||
RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
||||
|
||||
# install node and npm
|
||||
RUN [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
|
||||
&& nvm install $NODE_VERSION \
|
||||
&& nvm alias default $NODE_VERSION \
|
||||
&& nvm use default
|
||||
|
||||
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
|
||||
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
|
||||
|
||||
RUN npm install -g jasmine
|
||||
RUN npm install -g http-server
|
||||
|
||||
USER seluser
|
||||
|
||||
RUN mkdir -p /tmp/app
|
||||
WORKDIR /tmp/app
|
||||
|
||||
RUN npm init -y
|
||||
RUN npm install --save selenium-webdriver
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
COPY test-infra.js /tmp/app/node_modules
|
||||
COPY run.sh /tmp/app/
|
||||
|
||||
ENTRYPOINT [ "/tmp/app/run.sh" ]
|
14
polygerrit-ui/app/test/functional/infra/run.sh
Executable file
14
polygerrit-ui/app/test/functional/infra/run.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
echo Starting local server..
|
||||
cp /app/polygerrit_ui.zip .
|
||||
unzip -q polygerrit_ui.zip
|
||||
nohup http-server polygerrit_ui > /tmp/http-server.log 2>&1 &
|
||||
|
||||
echo Starting Webdriver..
|
||||
nohup /opt/bin/entry_point.sh > /tmp/webdriver.log 2>&1 &
|
||||
|
||||
# Wait for servers to start
|
||||
sleep 5
|
||||
|
||||
cp $@ .
|
||||
jasmine $(basename $@)
|
24
polygerrit-ui/app/test/functional/infra/test-infra.js
Normal file
24
polygerrit-ui/app/test/functional/infra/test-infra.js
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const {Builder} = require('selenium-webdriver');
|
||||
|
||||
let driver;
|
||||
|
||||
function setup() {
|
||||
return new Builder()
|
||||
.forBrowser('chrome')
|
||||
.usingServer('http://localhost:4444/wd/hub')
|
||||
.build()
|
||||
.then(d => {
|
||||
driver = d;
|
||||
return driver.get('http://localhost:8080');
|
||||
})
|
||||
.then(() => driver);
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
return driver.quit();
|
||||
}
|
||||
|
||||
exports.setup = setup;
|
||||
exports.cleanup = cleanup;
|
10
polygerrit-ui/app/test/functional/run_functional.sh
Executable file
10
polygerrit-ui/app/test/functional/run_functional.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
bazel build //polygerrit-ui/app:polygerrit_ui
|
||||
|
||||
docker run --rm \
|
||||
-p 5900:5900 \
|
||||
-v `pwd`/polygerrit-ui/app/test/functional:/tests \
|
||||
-v `pwd`/bazel-genfiles/polygerrit-ui/app:/app \
|
||||
-it gerrit/polygerrit-functional:v1 \
|
||||
/tests/test.js
|
25
polygerrit-ui/app/test/functional/test.js
Normal file
25
polygerrit-ui/app/test/functional/test.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @fileoverview Minimal viable frontend functional test.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const {until} = require('selenium-webdriver');
|
||||
const {setup, cleanup} = require('test-infra');
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
|
||||
|
||||
describe('example ', () => {
|
||||
let driver;
|
||||
|
||||
beforeAll(() => {
|
||||
return setup().then(d => driver = d);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
return cleanup();
|
||||
});
|
||||
|
||||
it('should update title', () => {
|
||||
return driver.wait(until.titleIs('status:open · Gerrit Code Review'), 5000);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user