Skip to content

Commit

Permalink
Adding a test to verify the video file is generated (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Oct 3, 2020
1 parent 5d739a8 commit a09631c
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 60 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/test-video.yml
@@ -0,0 +1,60 @@
name: Test video files

on:
push:
branches:
- trunk
pull_request:
branches:
- trunk

jobs:
build-and-test:
# Skip job based on the commit message, only works in push to branches for now
if: contains(toJson(github.event.commits), '[skip ci]') == false
name: Test video recorded through Docker Selenium
runs-on: ubuntu-18.04
strategy:
matrix:
use-random-user: [false, true]
steps:
- uses: actions/checkout@v1
- name: Output Docker info
run: docker info
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Get branch name (only for push to branch)
if: github.event_name == 'push'
run: echo "::set-env name=BRANCH::$(echo ${PUSH_BRANCH##*/})"
env:
PUSH_BRANCH: ${{ github.ref }}
- name: Get target branch name (only for PRs)
if: github.event_name == 'pull_request'
run: echo "::set-env name=BRANCH::$(echo ${TARGET_BRANCH##*/})"
env:
TARGET_BRANCH: ${{ github.head_ref }}
- name: Output branch name
run: echo ${BRANCH}
- name: Sets build date
run: echo ::set-env name=BUILD_DATE::$(date '+%Y%m%d')
- name: Run Docker Compose to record video
run: USE_RANDOM_USER_ID=${USE_RANDOM_USER} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make test_video
env:
USE_RANDOM_USER: ${{ matrix.use-random-user }}
- name: Upload recorded Chrome video
uses: actions/upload-artifact@v2
with:
name: chrome_video
path: ./tests/videos/chrome_video.mp4
- name: Upload recorded Firefox video
uses: actions/upload-artifact@v2
with:
name: firefox_video
path: ./tests/videos/firefox_video.mp4
- name: Upload recorded Opera video
uses: actions/upload-artifact@v2
with:
name: opera_video
path: ./tests/videos/opera_video.mp4
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,6 +14,7 @@ StandaloneO*/selenium.conf
StandaloneC*/start-*.sh
StandaloneF*/start-*.sh
StandaloneO*/start-*.sh
videos

# Created by https://www.gitignore.io/api/virtualenv

Expand Down
29 changes: 29 additions & 0 deletions Makefile
Expand Up @@ -300,6 +300,35 @@ test_opera:
test_opera_standalone:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneOpera

# This should run on its own CI job. There is no need to combine it with the other tests.
# Its main purpose is to check that a video file was generated.
test_video: video hub chrome firefox opera
# Running a few tests with docker-compose to generate the videos
for node in NodeChrome NodeFirefox NodeOpera ; do \
cd ./tests || true ; \
echo VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) > .env ; \
echo TAG=$(TAG_VERSION) >> .env ; \
echo NODE=$$node >> .env ; \
if [ $$node = "NodeChrome" ] ; then \
echo BROWSER=chrome >> .env ; \
echo VIDEO_FILE_NAME=chrome_video.mp4 >> .env ; \
fi ; \
if [ $$node = "NodeFirefox" ] ; then \
echo BROWSER=firefox >> .env ; \
echo VIDEO_FILE_NAME=firefox_video.mp4 >> .env ; \
fi ; \
if [ $$node = "NodeOpera" ] ; then \
echo BROWSER=opera >> .env ; \
echo VIDEO_FILE_NAME=opera_video.mp4 >> .env ; \
fi ; \
docker-compose -f docker-compose-v3-test-video.yml up --abort-on-container-exit --build ; \
done
# Using ffmpeg to verify file integrity
# https://superuser.com/questions/100288/how-can-i-check-the-integrity-of-a-video-file-avi-mpeg-mp4
docker run -v $$(pwd):$$(pwd) -w $$(pwd) jrottenberg/ffmpeg:4.3.1-ubuntu1804 -v error -i ./tests/videos/chrome_video.mp4 -f null - 2>error.log
docker run -v $$(pwd):$$(pwd) -w $$(pwd) jrottenberg/ffmpeg:4.3.1-ubuntu1804 -v error -i ./tests/videos/firefox_video.mp4 -f null - 2>error.log
docker run -v $$(pwd):$$(pwd) -w $$(pwd) jrottenberg/ffmpeg:4.3.1-ubuntu1804 -v error -i ./tests/videos/opera_video.mp4 -f null - 2>error.log

.PHONY: \
all \
base \
Expand Down
3 changes: 3 additions & 0 deletions tests/.dockerignore
@@ -0,0 +1,3 @@
docker-selenium-tests
.env
videos
5 changes: 5 additions & 0 deletions tests/Dockerfile
@@ -0,0 +1,5 @@
FROM python:3.8.6-buster

WORKDIR /usr/src/app

COPY . .
10 changes: 7 additions & 3 deletions tests/SeleniumTests/__init__.py
@@ -1,12 +1,16 @@
import unittest
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')


class SeleniumGenericTests(unittest.TestCase):

def test_title(self):
self.driver.get('https://the-internet.herokuapp.com')
self.assertTrue(self.driver.title == 'The Internet')
Expand Down Expand Up @@ -64,15 +68,15 @@ class ChromeTests(SeleniumGenericTests):
def setUp(self):
self.driver = webdriver.Remote(
desired_capabilities=DesiredCapabilities.CHROME,
command_executor='http://localhost:4444'
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
)


class FirefoxTests(SeleniumGenericTests):
def setUp(self):
self.driver = webdriver.Remote(
desired_capabilities=DesiredCapabilities.FIREFOX,
command_executor='http://localhost:4444'
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
)

def test_title_and_maximize_window(self):
Expand All @@ -87,5 +91,5 @@ def setUp(self):
capabilities['browserName'] = 'operablink'
self.driver = webdriver.Remote(
desired_capabilities=capabilities,
command_executor='http://localhost:4444'
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
)
15 changes: 6 additions & 9 deletions tests/SmokeTests/__init__.py
@@ -1,3 +1,4 @@
import os
import unittest
import time
import json
Expand All @@ -7,6 +8,8 @@
except ImportError:
from urllib.request import urlopen

SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')


class SmokeTests(unittest.TestCase):
def smoke_test_container(self, port):
Expand All @@ -19,7 +22,7 @@ def smoke_test_container(self, port):
while current_attempts < max_attempts:
current_attempts = current_attempts + 1
try:
response = urlopen('http://localhost:%s/status' % port)
response = urlopen('http://%s:%s/status' % (SELENIUM_GRID_HOST, port))
status_json = json.loads(response.read())
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)
status_fetched = True
Expand All @@ -30,12 +33,6 @@ def smoke_test_container(self, port):
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)


class NodeTest(SmokeTests):
def test_hub_and_node_up(self):
self.smoke_test_container(4444)
self.smoke_test_container(5555)


class StandaloneTest(SmokeTests):
def test_standalone_up(self):
class GridTest(SmokeTests):
def test_grid_is_up(self):
self.smoke_test_container(4444)
9 changes: 4 additions & 5 deletions tests/bootstrap.sh
@@ -1,21 +1,20 @@
#!/usr/bin/env bash
cd tests
cd tests || true

if [ "${TRAVIS:-false}" = "false" ]; then
if [ "${CI:-false}" = "false" ]; then
pip install virtualenv | grep -v 'Requirement already satisfied'
virtualenv docker-selenium-tests
source docker-selenium-tests/bin/activate
fi


python -m pip install selenium===3.14.1 \
docker===4.2.0 \
| grep -v 'Requirement already satisfied'

python test.py $1 $2
python test.py $1
ret_code=$?

if [ "${TRAVIS:-false}" = "false" ]; then
if [ "${CI:-false}" = "false" ]; then
deactivate
fi

Expand Down
47 changes: 47 additions & 0 deletions tests/docker-compose-v3-test-video.yml
@@ -0,0 +1,47 @@
# How to run this?
# docker-compose -f docker-compose-v3-test-video.yml up --abort-on-container-exit --build
# To clean up, `docker-compose -f docker-compose-v3-test-video.yml down`
version: "3"
services:
browser:
image: selenium/node-${BROWSER}:${TAG:-test-video}
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
ports:
- "6900:5900"

browser_video:
image: selenium/video:${VIDEO_TAG:-test-video}
volumes:
- ./videos:/videos
depends_on:
- browser
environment:
- DISPLAY_CONTAINER_NAME=browser
- FILE_NAME=${VIDEO_FILE_NAME}

selenium-hub:
image: selenium/hub:${TAG:-test-video}
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"

tests:
image: docker-selenium-tests:latest
build:
context: ./
dockerfile: ./Dockerfile
depends_on:
- selenium-hub
environment:
- RUN_IN_DOCKER_COMPOSE=true
- SELENIUM_GRID_HOST=selenium-hub
command: ["./bootstrap.sh", "${NODE}"]

0 comments on commit a09631c

Please sign in to comment.