Capybara tests being run against Zalenium can't find images - capybara

I have been working on using Zalenium for running our capybara tests against.
The tests run, but I am unable to upload images for testing image uploads.
I have mounted the folder with the images in the Zalenium containers and I have checked that the images are there, but I get a file not found error when using the file path to the images within the containers.
Zalenium config:
docker run --rm -ti --name zalenium -p 4444:4444 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/videos:/home/seluser/videos \
-v desktop/testdata/:/tmp/node/home/seluser/data \
--privileged dosel/zalenium start \
--desiredContainers 4 \
--maxDockerSeleniumContainers 8
Browser config:
when :chromeGrid
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :remote, url: "http://localhost:4444/wd/hub", desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome)
end

What is the path you are using in your tests?
I assume the images for the test are placed on the host machine in desktop/testdata/. But the test should look for them in /home/seluser/data, since it is the folder available in the container.

When using Capybara with a Selenium remote driver, the easiest way to handle this is to keep the images on the machine running the tests, set a file_detector in selenium and allow it to automatically send the images to the machine running the remote browser - https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb#L37 - https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/remote/oss/bridge.rb#L365

Related

Mount a file from D: Windows OS for file uploading to Zalenium docker image

I'm running my Selenium tests through Zalenium docker image. I have a test that requires a .pdf document uploading to the application.
The directory I will be using to store all my .pdfs is:
D:\Automation\KITS Automation\exports-endtoend-tests\Defra.Exports.EndToEnd.Tests\bin\Debug\netcoreapp2.1
I have added this path to my docker CMD window as below:
docker run --rm -ti --name zalenium -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/videos:/home/seluser/videos -v /d:/automation/kits automation/exports-endtoend-tests/defra.exports.endtoend.tests/bin/debug/netcoreapp2.1 --privileged dosel/zalenium start
Once added docker requests to share this file with a confirmation popup box however when I run the test I still see the error below
OpenQA.Selenium.WebDriverException : invalid argument: File not found : D:\Automation\KITS Automation\exports-endtoend-tests\Defra.Exports.EndToEnd.Tests\bin\Debug\netcoreapp2.1\test-ehc.pdf
c# Code that executes uploading the file:
string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(folder, "test-ehc.pdf");
driver.FindElement(By.Id("file")).SendKeys(filePath)
This is not related to Zalenium at all. The test code, C# seems to be the case here, needs access to the file to be uploaded. Normally this is done via
driver.setFileDetector(new LocalFileDetector());
If you'd like to run the C# code inside a Docker container, please look at docker images that can be used for that. In the end, the file to be uploaded does not need to be shared with Zalenium, it needs to be shared with the container where the test code will be executed.
This is related to Zalenium when starting Zalenium you use the command below:
docker run --rm -ti --name zalenium -p 4444:4444 -v
/var/run/docker.sock:/var/run/docker.sock -v /D/source/repos/Defra.Git/ehco-endtoend-
tests/src/main/resources/upload:/tmp/node/home/seluser/Downloads --privileged
dosel/zalenium start --desiredContainers 2

How do I transfer a volume's data to another volume on my local host in docker?

I did
docker run -v /jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
on Windows (with docker installed as a linux container).
However, after configuring jenkins on that container, I now wanted to transfer the data in that /jenkins_home volume into a C:\jenkins_home folder on my local windows host machine\another machine.
Any way I can get the data from the /jenkins_home to c:/jenkins_home?
I know I should have made it
docker run -v c:/jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
at the start but mistakes were made and I was wondering how do I fix that as the above suggestion?
Tried running
docker run -it -p 8080:8080 -p 50000:50000 --volumes-from jenkins_old -v c:/jenkins_home:/var/jenkins_home --name jenkins_new jenkins/jenkins:alpine
but it doesn't transfer the data over using the new c:\jenkins_home folder
docker run -v /jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
Can't get the data to transfer over from the /jenkins_home folder to c:\jenkins_home folder.
I don't know where the /jenkins_home would map to on windows, but you could try this:
docker run -it --rm -v /jenkins_home:/from -v c:\jenkins_home:/to alpine cp -r /from /to

prometheus run using docker

This is the first time I am using docker to run a release file.
I installed docker using
npm install -g docker
I am trying to use Prometheus.
https://github.com/prometheus/prometheus
I followed following steps
Download Prometheus [https://hub.docker.com/r/prom/prometheus/]
docker pull prom/prometheus
C:\xampp\htdocs\prometheus>docker pull prom/prometheus
Saved file tree to doc-filelist.js
Copied JS to doc-script.js
Compiled CSS to doc-style.css
Run docker [https://github.com/prometheus/prometheus]
docker run --name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus
C:\xampp\htdocs\prometheus>docker run --name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus
Saved file tree to doc-filelist.js
Copied JS to doc-script.js
Compiled CSS to doc-style.css
I am not sure what is wrong. Please advice
I think what you are installing is this docker which is a documentation generator rather than this docker , which is a container technology.
So , refer to this to install the correct Docker first .Then execute the following commands:
# docker pull prom/prometheus
# docker run --name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus
Then open the browser and visit http://127.0.0.1:9090 and you should see the Prometheus UI.
If you are using docker to run Prometheus, make sure
Docker engine is installed.
Keep a configuration file (promethues.yml) file.
run the container using the command.
docker run -d -p 9090:9090 -v /path_where_config_file_present/:/etc/prometheus -v /path_where_data_file_to_be_dumped/:/prometheus prom/prometheus:v2.4.0 --config.file=/etc/prometheus/prometheus.yml

Getting docker containers output from another docker container

I have an application that runs dockerized commands via docker run --rm .... Is it possible to dockerize this application?
E.g. I want the app RUNNER to run app RUNNABLE and read the stdout result.
(I need multiple instances of RUNNABLE in async calling fashion but that's RUNNER application business)
I know it is possible to just export root access to docker socket to the RUNNER application but this doesn't feel right. Especially with no-root-running rule for *nix applications.
Is there any other method to communicate containers rather than exporting socket to the container? Am I doing the system design wrong?
Basically it's possible to let the container communicate over host based files. Take a look at the following example.
# create a test dir
mkdir -p docker_test/bin
cd docker_test
# an endless running script that writes output in a file
vim bin/printDate.sh
chmod 700 bin/*.sh
# start docker container from debian image
# the container got a local host mount of /tmp to container /opt/output
# printDate.sh writes its output to container /opt/output/printDate.txt
docker run --name cont-1 \
-v /tmp:/opt/output -it -v `pwd`/bin:/opt/test \
debian /opt/test/printDate.sh
# start a second container in another terminal and mount /tmp again
docker run --name cont-2 -v /tmp:/opt/output -it \
debian tail -f /opt/output/printDate.txt
# the second container prints the output of program in cont-1
The endless script for container 1 output
#!/bin/bash
while true; do
sleep 1
date >> /opt/output/printDate.txt
done

How to run protractor end to end tests in docker container?

I am beginner to docker container.I just started to run protractor end to end test in docker container. My application is in angular 2 typescript. I tried to figure out how to configure docker and found out image from the docker hub https://hub.docker.com/r/caltha/protractor/ and downloaded this image in my virtual machine. I used this command and gave my test location folder.The container terminated automatically. I dont see any output directory generated or neither end tests are executed.
docker pull caltha/protractor
docker run --rm -v /home/ubuntu/git/Test/dashboard/test:/project
caltha/protractor
//protractor.conf.js
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test/e2e/menu.js'],
capabilities: {
'browserName': 'firefox',
},
baseUrl: 'http://localhost:8080/dashboard/#/',
jasmineNodeOpts: {
showColors: true,
},
}
Did you try to search for the output file as the website says?
The output of supervisord visible on the console is not interesting in most circumstances. You should check target/supervsor.out file to see the output of Protractor. Dispalying the file in an Unix terminal using cat is recommended over opening it using an editor because the file contains ANSI escape sequences.
Also you can leave the docker open for your testing instead opening and closing when executed the command. This way you could see the actual errors in console.
Try:
CONTAINER=$(docker run -d -v /home/ubuntu/git/Test/dashboard/test:/project --env MANUAL=yes caltha/protractor)
docker exec -ti $CONTAINER sudo -i -u node bash
From: Caltha/protractor website
EDIT:
Using the following command you it should open in terminal the docker container with your project:
docker run -it --rm -v /home/ubuntu/git/Test/dashboard/test:/project --privileged caltha/protractor bash
Then you just need to run the protractor as you do locally
protractor protractor.conf.js
(if protractor has been exposed to the path this should work.. if not write a comment)

Resources