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

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)

Related

Unable to open playwright HTML Report (using Docker)

I have pulled the image using below command into my root of the project
docker pull mcr.microsoft.com/playwright:v1.24.2-focal
and then run the image using below command:
docker run -it --rm --ipc=host mcr.microsoft.com/playwright:v1.24.2-focal /bin/bash
and it takes me to the container (please check screenshot below)
when I run the command npx playwright test my all test got passed but when I tried to open test report using command: npx playwright show-report then it shows me below result:
It says:
Failed to open browser on http://127.0.0.1:9323
What can I try to resolve this?
Max is right, you have to add for example in your playwright.config.ts the option open: 'never'. For example:
const config: PlaywrightTestConfig = {
// (...)
reporter: [ ['html', { open: 'never'}], ['list'] ],
// (...)
}
And to answer to your second question, about getting the reports on your host, you have to use a volume when executing docker run.
For example, let's say that on your host, in your current folder, you have your playwright.config.ts file, then run the following command to mount the whole directory on the container:
docker run -it --rm --ipc=host \
--workdir=/my_tests \
-v $PWD:/my_tests \
mcr.microsoft.com/playwright:v1.24.2-focal bash

docker run [9] System error: exec format error

I created Dockerfile to build my image called aii.
FROM docker.io/centos:latest
#Set parameters
ENV BinDir /usr/local/bin
ENV RunFile start-aii.sh
ADD ${RunFile} ${BinDir}
#Some other stuff
...
CMD ${RunFile}
When I run the image with the following command:
docker run -it -v <some-volume-mapping> aii
it's works great (default operation of running CMD command of start-aii.sh).
Now, if I try to override this default behavior and to run the image with the same script implicitly (and add another arg) I'm getting the following error:
docker run -it -v <some-volume-mapping> aii start-aii.sh kafka
exec format error
docker: Error response from daemon: Cannot start container b3f4f3bde04d862eb8bc619ea55b7061ce78ace8f1984a12f6ec681877d7d926: [9] System error: exec format error.
I also tried: only script (without argument)
docker run -it -v <some-volume-mapping> aii start-aii.sh
and full path to script
docker run -it -v <some-volume-mapping> aii /usr/local/bin/start-aii.sh
but the same error appear.
Another info:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2488a4dd7014 aii "start-aii.sh kafka" 3 seconds ago Created tiny_payne
Any suggestions?
Thanks
Had the same issue, fixed it by adding #!/bin/sh at the top of the file instead of having other comments.
Try to start bash before using your script, and use the --rm flag in order to destroy the instance once the job is ended, like that :
docker run -it --rm -v <some-volume-mapping> aii /bin/bash /usr/local/bin/start-aii.sh
If you created the file start-aii.sh in the Windows editor. After that, this file was added to the docker image. You should check this file in a Linux editor, e.g. nano. In my case there were non-printable characters at the beginning of the file. I removed them and my script ran successfully.

How to get docker exec stdout to be as verbose as running command in container?

If I run a command using docker's exec command, like so:
docker exec container gulp
It simply runs the command, but nothing is outputted to my terminal window.
However, if I actually go into the container and run the command manually:
docker exec -ti container bash
gulp
I see gulp's output:
[13:49:57] Using gulpfile ~/code/services/app/gulpfile.js[13:49:57]
Starting 'scripts'...[13:49:57] Starting 'styles'...[13:49:58]
Starting 'emailStyles'... ...
How can I run my first command and still have the output sent to my terminal window?
Side note: I see the same behavior with npm installs, forever restarts, etc. So, it is not just a gulp issue, but likely something with how docker is mapping the stdout.
How can I run my first command and still have the output sent to my terminal window?
You need to make sure docker run is launched with the -t option in order to allocate a pseudo tty.
Then a docker exec without -t would still work.
I discuss docker exec -it here, which references "Fixing the Docker TERM variable issue ")
docker#machine:/c/Users/vonc/prog$ d run --name test -dit busybox
2b06a0ebb573e936c9fa2be7e79f1a7729baee6bfffb4b2cbf36e818b1da7349
docker#machine:/c/Users/vonc/prog$ d exec test echo ok
ok

run docker commands from command prompt versus jenkins script

I have a test Ubuntu server with docker-machine installed. I have a number of docker containers running on the servers. Including a Jenkins container. I run jenkins with the following command
docker run -d --name jenkins -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker --restart=always -p 8080:8080 -v ~/jenkinsHome:/var/jenkins_home docker-jenkins
I am working on managing my images through Jenkins. I can start all but one of my containers via Jenkins shell script. The one container that fails appears to start in the script (I do a docker PS after the docker run in script). However, the container stops after the script completes. I am using the same docker run command that works on the command prompt, but it fails in Jenkins script:
sudo docker run -d --net=host -v ~/plex-config:/config -v ~/Media:/media -p 32400:32400 wernight/plex-media-server
I have double checked folder permissions and they are correct. Can anyone direct me to possible reasons the run command is failing in Jenkins, but not at the command prompt?
using docker ps -a I was able to get an ID for the stopped container. Then by using docker logs I was able to see the error was a folder permission issue. Then digging deeper, it was a user permission error mis-match between the user Jenkins runs as inside it's container not being able to pass the folder correctly. I have decided to circumvent the problem by using docker stop and start commands and not using the docker run command.

Docker Exec command does not work properly

I have a script run.sh that I run as I initialize the container through docker run command. The script runs successfully. I can also get a bash instance (through docker exec -i -t container-name bash) in the container and run the script successfully (note that by default I have su privileges when I get the bash).
However, when I run the script from the host through docker exec -i -t container-name /run.sh the script runs but does not provide the outcome that it provides through the alternative approaches. I know it runs as it produces some of the expected behavior but not all of them. So my main question is what are the difference between executing a script through commandline and running the same script through docker exec.

Resources