From b6a1a57bed396540f6dc231ef332075810672653 Mon Sep 17 00:00:00 2001 From: butomo1989 Date: Fri, 14 Jul 2017 20:40:14 +0200 Subject: [PATCH] Enable video recording --- .gitignore | 5 ++++- docker-compose.yml | 9 +++++++++ docker/Emulator_arm | 7 +++++++ docker/Emulator_x86 | 7 +++++++ docker/Real_device | 7 +++++++ src/record.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ supervisord.conf | 7 +++++++ 7 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/record.sh diff --git a/.gitignore b/.gitignore index a666536..e60e0b4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ .coverage coverage.xml xunit.xml -coverage/* \ No newline at end of file +coverage/* + +# Video +video* diff --git a/docker-compose.yml b/docker-compose.yml index 7c8c249..edae1cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,11 +21,14 @@ services: scale: 1 ports: - 6080 + volumes: + - ./video-nexus_7.1.1:/tmp/video environment: - DEVICE=Nexus 5 - CONNECT_TO_GRID=True - APPIUM=true - SELENIUM_HOST=selenium_hub + - AUTO_RECORD=True # Docker-Android for mobile website testing with chrome browser # Chrome browser exists only for version 7.0 and 7.1.1 @@ -36,12 +39,15 @@ services: scale: 1 ports: - 6080 + volumes: + - ./video-samsung_7.1.1:/tmp/video environment: - DEVICE=Samsung Galaxy S6 - CONNECT_TO_GRID=True - APPIUM=true - SELENIUM_HOST=selenium_hub - MOBILE_WEB_TEST=True + - AUTO_RECORD=True # Docker-Android for mobile website testing with default browser # Default browser exists only for version 5.0.1, 5.1.1 and 6.0 @@ -52,9 +58,12 @@ services: scale: 1 ports: - 6080 + volumes: + - ./video-samsung_5.1.1:/tmp/video environment: - DEVICE=Samsung Galaxy S6 - CONNECT_TO_GRID=True - APPIUM=true - SELENIUM_HOST=selenium_hub - MOBILE_WEB_TEST=True + - AUTO_RECORD=True diff --git a/docker/Emulator_arm b/docker/Emulator_arm index 07c8d35..e3fcead 100644 --- a/docker/Emulator_arm +++ b/docker/Emulator_arm @@ -29,6 +29,11 @@ WORKDIR /root # Numpy, For faster performance: https://github.com/novnc/websockify/issues/77 # net-tools # Netstat +#------------------ +# Video Recording +#------------------ +# ffmpeg +# Video recorder #================== RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \ xterm \ @@ -39,6 +44,7 @@ RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \ menu \ python-numpy \ net-tools \ + ffmpeg \ && rm -rf /var/lib/apt/lists/* #======= @@ -100,6 +106,7 @@ ENV DISPLAY=:0 \ LOCAL_PORT=5900 \ TARGET_PORT=6080 \ TIMEOUT=1 \ + VIDEO_PATH=/tmp/video \ LOG_PATH=/var/log/supervisor #=============== diff --git a/docker/Emulator_x86 b/docker/Emulator_x86 index 8892c57..2de1fee 100644 --- a/docker/Emulator_x86 +++ b/docker/Emulator_x86 @@ -30,6 +30,11 @@ WORKDIR /root # net-tools # Netstat #------------------ +# Video Recording +#------------------ +# ffmpeg +# Video recorder +#------------------ # KVM Package # for emulator x86 # https://help.ubuntu.com/community/KVM/Installation @@ -48,6 +53,7 @@ RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \ menu \ python-numpy \ net-tools \ + ffmpeg \ qemu-kvm \ libvirt-bin \ ubuntu-vm-builder \ @@ -113,6 +119,7 @@ ENV DISPLAY=:0 \ LOCAL_PORT=5900 \ TARGET_PORT=6080 \ TIMEOUT=1 \ + VIDEO_PATH=/tmp/video \ LOG_PATH=/var/log/supervisor #=============== diff --git a/docker/Real_device b/docker/Real_device index 26e4865..f208f71 100644 --- a/docker/Real_device +++ b/docker/Real_device @@ -29,6 +29,11 @@ WORKDIR /root # Numpy, For faster performance: https://github.com/novnc/websockify/issues/77 # net-tools # Netstat +#------------------ +# Video Recording +#------------------ +# ffmpeg +# Video recorder #================== RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \ xterm \ @@ -39,6 +44,7 @@ RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \ menu \ python-numpy \ net-tools \ + ffmpeg \ && rm -rf /var/lib/apt/lists/* #======= @@ -77,6 +83,7 @@ ENV DISPLAY=:0 \ LOCAL_PORT=5900 \ TARGET_PORT=6080 \ TIMEOUT=1 \ + VIDEO_PATH=/tmp/video \ LOG_PATH=/var/log/supervisor #========================= diff --git a/src/record.sh b/src/record.sh new file mode 100644 index 0000000..dc1a614 --- /dev/null +++ b/src/record.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +function start() { + mkdir -p $VIDEO_PATH + sw=$(($SCREEN_WIDTH - 1)) + sh=$(($SCREEN_HEIGHT - 1)) + name="$DEVICE-$BROWSER-$(date '+%d/%m/%Y-%H:%M:%S')" + echo "Start video recording" + ffmpeg -video_size $swx$sh -framerate 15 -f x11grab -i ${DISPLAY} $VIDEO_PATH/$name -y +} + +function stop() { + echo "Stop video recording" + kill $(ps -ef | grep ffmpeg) +} + +function auto_record() { + if [ ! -z $AUTO_RECORD ]; then + if [ ${AUTO_RECORD,,} = true ]; then + echo "Auto recording is enable. It will record the video automatically as soon as appium receive test scenario!" + + # Check if there is test running + no_test=true + while $no_test; do + task=$(curl -s localhost:4723/wd/hub/sessions | jq -r '.value') + if [ -n "$task" ]; then + sleep .5 + else + no_test=false + start + fi + done + + # Check if test is finished + while [ $no_test = false ]; do + task=$(curl -s localhost:4723/wd/hub/sessions | jq -r '.value') + if [ -n "$task" ]; then + stop + else + sleep .5 + fi + done + fi + fi +} \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf index 6a6a1bc..f865fd6 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -48,3 +48,10 @@ autorestart=false stdout_logfile=%(ENV_LOG_PATH)s/docker-android.stdout.log stderr_logfile=%(ENV_LOG_PATH)s/docker-android.stderr.log priority=4 + +[program:auto-recording] +command=./src/record.sh +autorestart=false +stdout_logfile=%(ENV_LOG_PATH)s/video-recording.stdout.log +stderr_logfile=%(ENV_LOG_PATH)s/video-recording.stderr.log +priority=4