Skylar

A intelligent software assistant written in Java

logo

Project HTML Manual PDF Manual

     

Selenium

Dependencies - selenium

Picture

Usage - selenium

See REST API section Selenium on how to remote control Skylars Firefox. To get a visual just open a VNC viewer.

# Open your favorite VNC viewer
# https://www.realvnc.com/en/connect/download/viewer/
#     host: 127.0.0.1
#     port: 61622
#     password: skylar
xdg-open 'vnc://:skylar@127.0.0.1:61622'
# Now you should see a black screen with a Ubuntu logo
# more info https://github.com/SeleniumHQ/docker-selenium

Restrictions of Docker container - selenium

Sooner or later you will find yourself in the situation that you want to play sound or use the microphone in Skylars Firefox. The best way is to run the Selenium Server in your desktop environment and outside of Docker. Another way is to enable the missing features in your Linux/Mac/Windows/ARM Docker Deamon. But each OS will require a different approach and will have different downsides…

Configure for external Selenium Server - selenium

PROJECT="$HOME/git/skylar"

# stop application
cd $PROJECT
./container_destroy.sh

# change selenium server to 172.23.42.1:4444
cd $PROJECT/docker/_volumes/registry
sed -i -e 's|selenium:4444/wd/hub|172.23.42.1:4444/wd/hub|' core.yml

# start application
cd $PROJECT
./container_start.sh

Start external Selenium Server - selenium

# Start selenium server
PROJECT="$HOME/git/skylar"
cd $PROJECT/tools/selenium
./startServer.sh

For more information read my article on Selenium beyond Unit testing

Sound

Method 1: Capture sound card - selenium

# edit docker-compose.yml
PROJECT="$HOME/git/skylar"
atom $PROJECT/docker/docker-compose.yml

uncomment lines

selenium:
    volumes:
    #            - "$DEVICE_SHM"
    #            - "$VOLUME_PULSEAUDIO_DBUS"
    #            - "$VOLUME_PULSEAUDIO_MACHINE_ID"

    #        devices:
    #            - "$DEVICE_SOUND"

Restart pulseaudio - selenium

Docker will capture the sound device and you will not be able to play sound from your desktop environment until you restart PulseAudio.

# stop docker
PROJECT="$HOME/git/skylar"
cd $PROJECT/docker
docker-compose down

# make sure all containers are down
docker ps -a | grep skylar

# restart pulseaudio
pulseaudio -k && sudo alsa force-reload

Method 2: Stream PulseAudio via TCP - selenium

E.g. inexpensive Raspberry Pi running Ubuntu

Setup TCP Server

sudo -i
# install pulseaudio
apt-get -y install \
                alsa-utils \
                libasound2 \
                libasound2-plugins \
                pulseaudio \
                pulseaudio-module-zeroconf \
                pulseaudio-utils \
                --no-install-recommends

# backup configuration
cp /etc/pulse/default.pa /etc/pulse/default.pa.org

# add TCP configuration --- replace network 192.168.0.0/16
echo '
# tcp server
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/16 auth-anonymous=1
load-module module-zeroconf-publish
' >> /etc/pulse/default.pa

# restart linux box
reboot

Test TCP Server

# make shure you are NOT ROOT and are in AUDIO GROUP
id | grep -v root | grep audio

# Add your user to the audio group if needed then restart shell
# sudo usermod -aG audio,pulse,pulse-access USER
# exit

# test audio
# locate wav | grep wav$
aplay /usr/share/sounds/alsa/Noise.wav

# check tcp module loaded
pactl list | grep module-native-protocol-tcp

# start server in debug mode
pulseaudio -v

# use SECOND TERMINAL to test --- replace IP 192.168.0.10
PULSE_SERVER=192.168.0.10:4713 pavucontrol

# play tcp sound --- replace IP 192.168.0.10
PULSE_SERVER=192.168.0.10:4713 vlc

# more info
xdg-open https://wiki.ubuntuusers.de/PulseAudio/#Soundausgabe-im-Netzwerk-umleiten

Run PulseAudio as systemd service

sudo -i

# create service script
echo '[Unit]
Description=System PulseAudio sound server

[Service]
Type=notify
ExecStart=/usr/bin/pulseaudio --verbose --system --daemonize=no --high-priority --log-target=syslog --disallow-exit --disallow-module-loading=1

[Install]
WantedBy=multi-user.target' > /etc/systemd/system/pulseaudio.service

# enable and start daemon
systemctl enable pulseaudio
systemctl start pulseaudio

Setup Docker

Change the .env value ENV_PULSE_AUDIO_TCP in file $PROJECT/docker/.env

ENV_PULSE_AUDIO_TCP=PULSE_SERVER=192.168.0.10:4713
# edit .env file
PROJECT="$HOME/git/skylar"
# atom $PROJECT/docker/.env

sed -i -e 's|ENV_PULSE_AUDIO_TCP=.*|ENV_PULSE_AUDIO_TCP=PULSE_SERVER=192.168.0.10:4713|' $PROJECT/docker/.env
cat $PROJECT/docker/.env | grep ENV_PULSE_AUDIO_TCP