Skip to content

Commit

Permalink
nightwatch maintenance (qmk#196)
Browse files Browse the repository at this point in the history
* Add a couple of nightwatch targets to npm

 - `npm run init_nightwatch` to bootstrap the headless selenium stuff
 - `npm run nightwatch` to run the task

Only tested on OSX.

 - fix up version number in nightwatch.conf file
 - remove binary commits

* Fix up security warnings from github

 - everything but one thing is fixed up
 - the final thing is an HTML report writer we don't use it so I think
   it's ok for now. Hopefully someone will patch it.

* Remove unused vars

* Ignore temp files

* Update docs

* Fix warnings from shellcheck

* Simplify script

 - refactor variable assignments
 - assign variables for re-use to avoid building strings
 - avoid creating temporary artifacts while unpacking
 - remove a branch

* Remove a redundant rm

* Update README.md to use nvm

 - to avoid issues with outdated npm

* numbering

* markdown formatting

* Add instructions to install headless chrome
  • Loading branch information
yanfali authored and jackhumbert committed Oct 8, 2018
1 parent 829c2b3 commit c7482c7
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 375 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ vendor/*
*.sw[po]
node_modules
/functional_tests/bin/selenium-server-standalone-3.12.0.jar
/functional_tests/bin
/functional_tests/tmp
/selenium-debug.log
/functional_tests/reports/
/selenium-server.log
40 changes: 22 additions & 18 deletions functional_tests/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
# Functional Test using Nightwatch.js

[Nightwatch](http://nightwatchjs.org/) is an automated testing framework for web applications and websites. It is written using Node.js and the W3C WebDriver API.
[Nightwatch](http://nightwatchjs.org/) is an automated testing framework for web applications and websites. It is written using Node.js and the W3C WebDriver API.

## Structure

#### globals.js:
Contains the Setup and Teardown methods ran before each test as well as the variables for setting webdriver timeouts.
Contains the Setup and Teardown methods ran before each test as well as the variables for setting webdriver timeouts.
Also contains the launch URL for the application under testing.

#### nightwatch.conf.js:
The configuration file for Nightwatch.js that holds the paths to the required folders
as well as the settings for Selenium and the Webdrivers.

#### bin directory:
Folder containing the selenium jar and the webdriver executables. Currently the Linux webdrivers are included in the repo, the jar is not.
Ideally these should be downloaded by a script when executed on a CI environment to ensure they are up to date.

## Setup

1. Run the `selenium_setup.sh` script to install the following to `qmk_configurator/functional_tests/bin`
Selenium Standalone Server
Chrome Web Driver
Geckodriver

```
foo@bar:~/qmk_configurator/functional_tests$ ./selenium_setup.sh
```
At the time of this writing, `chromedriver` is at `2.40`, `geckodriver` is at `0.21.0` and Selenium Standalone Server is at `3.13.0`

2. Download and install the Java SDK.
3. Run `npm install` from the the main qmk_configurator directory
```console
foo@bar:~/qmk_configurator$ npm install
```
4. Update `qmk_configurator/nightwatch.conf.js` to have the correct version for the `Selenium Standalone Server`
1. Download and install the Java SDK.
1. Download and install a recent version of chrome with headless operation.
This [ariticle](https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/)
will help if you are on linux.
1. Download and install [nvm](https://github.com/creationix/nvm)
```console
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
```
1. Run `nvm install` if this is your first time using nvm, or `nvm use` if you already have nvm installed.
1. Run `npm install` from the the main qmk_configurator directory
```console
foo@bar:~/qmk_configurator$ npm install
```
1. Run `npm run init_nightwatch` to download nightwatch binary drivers for your OS
```console
foo@bar:~/qmk_configurator$ npm run init_nightwatch
```
1. Update `qmk_configurator/nightwatch.conf.js` to have the correct version for the `Selenium Standalone Server`

## Execution

To run all tests with the 'default' settings from nightwatch.js.conf:

```console
foo@bar:~/qmk_configurator$ node_modules/nightwatch/bin/nightwatch -e chromeHeadless
foo@bar:~/qmk_configurator$ npm run nightwatch
```

The chosen environment(s) will then be executed in their own child process
Expand Down
Binary file removed functional_tests/bin/chromedriver
Binary file not shown.
Binary file removed functional_tests/bin/geckodriver
Binary file not shown.
74 changes: 34 additions & 40 deletions functional_tests/selenium_setup.sh
Original file line number Diff line number Diff line change
@@ -1,88 +1,82 @@
#!/bin/bash
#!/bin/bash -e
set -x

# This script is intended to be run from the qmk_configurator/functional_tests directory
# Installs Chrome Web Driver
# Installs Selenium Standalone Server

if [ "$EUID" -ne 0 ]; then
exec sudo "$0" "$@";
fi

# Determine which OS
OS="$(uname -s)"

# Set Versions
SELENIUM_VERSION="3.13.0"
CHR_DRIVER_VER="2.40"
GKO_DRIVER_VER="0.21.0"
CHR_DRIVER_URL="https://chromedriver.storage.googleapis.com/${CHR_DRIVER_VER}"
GKO_DRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/v${GKO_DRIVER_VER}"

# Get Paths
PWD="$(pwd)" # should be qmk_configurator/functional_tests
ROOTPWD=$(pwd) # should be qmk_configurator/functional_tests

rm -fr ./bin ./tmp
mkdir -p ./bin ./tmp

# Determine which Chrome Web Driver to download based on system
if [ "${OS}" == "Darwin" ]; then
CHR_DRIVER="https://chromedriver.storage.googleapis.com/${CHR_DRIVER_VER}/chromedriver_mac64.zip"
GKO_DRIVER="https://github.com/mozilla/geckodriver/releases/download/v${GKO_DRIVER_VER}/geckodriver-v${GKO_DRIVER_VER}-macos.tar.gz"
DRIVER="mac64"
DRIVER="macos"
GKO_ARCHIVE="geckodriver-v${GKO_DRIVER_VER}-${DRIVER}.tar.gz"
CHR_ARCHIVE="chromedriver_mac64.zip"
else
VERSION="$(uname -m)"
if [ "${VERSION}" == "x86_64:" ]; then
CHR_DRIVER="https://chromedriver.storage.googleapis.com/${CHR_DRIVER_VER}/chromedriver_linux32.zip"
GKO_DRIVER="https://github.com/mozilla/geckodriver/releases/download/v${GKO_DRIVER_VER}/geckodriver-v${GKO_DRIVER_VER}-linux32.tar.gz"
DRIVER="linux32"
DRIVER="linux32"
else
CHR_DRIVER="https://chromedriver.storage.googleapis.com/${CHR_DRIVER_VER}/chromedriver_linux64.zip"
GKO_DRIVER="https://github.com/mozilla/geckodriver/releases/download/v${GKO_DRIVER_VER}/geckodriver-v${GKO_DRIVER_VER}-linux64.tar.gz"
DRIVER="linux64"
DRIVER="linux64"
fi
GKO_ARCHIVE="geckodriver-v${GKO_DRIVER_VER}-${DRIVER}.tar.gz"
CHR_ARCHIVE="chromedriver_${DRIVER}.zip"
fi
CHR_DRIVER="${CHR_DRIVER_URL}/${CHR_ARCHIVE}"
GKO_DRIVER="${GKO_DRIVER_URL}/${GKO_ARCHIVE}"

# Download Chrome Web Driver .zip file to temporary location
TEMP_PATH=${PWD}"/tmp/chromedriver"
mkdir "$TEMP_PATH" && pushd "$TEMP_PATH"
TEMP_PATH="${ROOTPWD}/tmp/chromedriver"
mkdir -p "$TEMP_PATH" && cd "$TEMP_PATH"
wget $CHR_DRIVER -P "$TEMP_PATH"
printf "Chrome Driver zip file downloaded to %s.\\n" "${TEMP_PATH}"

# Unzip Chrome Driver zip file to qmk_configurator/functional_tests/bin directory
DEST_PATH=${PWD}"/bin"
unzip "${TEMP_PATH}"/chromedriver_$DRIVER.zip
sudo mv -f ./chromedriver "$DEST_PATH"
sudo chown root:root "$DEST_PATH"
sudo chmod 0755 "$DEST_PATH"
DEST_PATH=${ROOTPWD}"/bin"
unzip "${TEMP_PATH}/${CHR_ARCHIVE}"
mv -f ./chromedriver "$DEST_PATH"
chmod 0755 "$DEST_PATH"

printf "Installed Chrome Web Driver for %s to %s.\\n" "${DRIVER}" "${DEST_PATH}"

# Download geckodriver to temporary location
TEMP_PATH=${PWD}"/tmp/geckodriver"
mkdir "$TEMP_PATH" && pushd "$TEMP_PATH"
TEMP_PATH=${ROOTPWD}"/tmp/geckodriver"
mkdir -p "$TEMP_PATH" && cd "$TEMP_PATH"
wget $GKO_DRIVER -P "$TEMP_PATH"
printf "geckodriver downloaded to %s.\\n" "${TEMP_PATH}"

# gunzip/tar geckodriver to qmk_configurator/functional_tests/bin directory
DEST_PATH=${PWD}"/bin"
if [ "${OS}" == "Darwin" ]; then
DRIVER="macos"
fi

gunzip "${TEMP_PATH}"/geckodriver-v$GKO_DRIVER_VER-$DRIVER.tar.gz
tar xvf "${TEMP_PATH}"/geckodriver-v$GKO_DRIVER_VER-$DRIVER.tar
DEST_PATH=${ROOTPWD}"/bin"
gunzip < "${TEMP_PATH}/${GKO_ARCHIVE}" | tar xvf -

sudo mv -f ./geckodriver "$DEST_PATH"
sudo chown root:root "$DEST_PATH"
sudo chmod 0755 "$DEST_PATH"
mv -f ./geckodriver "$DEST_PATH"
chmod 0755 "${DEST_PATH}"

printf "Installed geckodriver for %s to %s.\\n" "${DRIVER}" "${DEST_PATH}"

#Download and install Standalone Selenium Server
SELENIUM_JAR_FILE=selenium-server-standalone-$SELENIUM_VERSION.jar
wget http://selenium-release.storage.googleapis.com/$(echo "$SELENIUM_VERSION" | cut -d'.' -f-2)/$SELENIUM_JAR_FILE -P "$TEMP_PATH"
mv -f "$TEMP_PATH/$SELENIUM_JAR_FILE" "$DEST_PATH"
chown root:root "$DEST_PATH$SELENIUM_JAR_FILE"
chmod 755 "$DEST_PATH$SELENIUM_JAR_FILE"
wget "http://selenium-release.storage.googleapis.com/$(echo "$SELENIUM_VERSION" | cut -d'.' -f-2)/$SELENIUM_JAR_FILE" -P "$TEMP_PATH"
mv -f "${TEMP_PATH}/${SELENIUM_JAR_FILE}" "${DEST_PATH}"
chmod 755 "${DEST_PATH}/${SELENIUM_JAR_FILE}"

printf "Installed Selenium Standalone Server %s. \\n" "${SELENIUM_VERSION}"

printf "Deleting directory qmk_configurator/functional_tests/tmp \\n"
sudo rm -rf tmp/
rm -rf ./tmp/

printf "Installation is successful. \\n"
printf "Installation is successful. \\n"
2 changes: 1 addition & 1 deletion nightwatch.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nightwatch_config = {
selenium: {
start_process: true,
port: 4444,
server_path:'./functional_tests/bin/selenium-server-standalone-3.12.0.jar', //Set this to the version you are using
server_path:'./functional_tests/bin/selenium-server-standalone-3.13.0.jar', //Set this to the version you are using
cli_args:{
'webdriver.gecko.driver': './functional_tests/bin/geckodriver',
'webdriver.chrome.driver': './functional_tests/bin/chromedriver'
Expand Down
Loading

0 comments on commit c7482c7

Please sign in to comment.