Unable to open playwright HTML Report (using Docker) - 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

Related

How to get playwrightUrl of Docker container for Playwright (needed to integrate Karate scripts)?

I am trying to execute the Karate script in mcr.microsoft.com/playwright:bionic Docker container.
I have exposed the port 5900 as shown below but not sure how to get the playwrightUrl for the container. Do I need to execute the node server.js inside it to get websocket endpoint?
docker run --name playwright -it --rm --ipc=host --cap-add=SYS_ADMIN -u root -p 5900:5900 -v $(pwd):/src -v /home/Automation/:/root/.m2 mcr.microsoft.com/playwright:bionic &
So, first of all, you need to actually provide a working example of what you're trying to achieve.
What I understand from your question, is that you're trying to give the url for the tests from docker command in the terminal.
Since Playwright v1.13.0, there is a baseURL option available. You can utilise that in this way probably
In your config.js file, you can have this
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
use: {
baseURL: process.env.URL,
},
};
export default config;
In your command for running docker, you can then pass as
docker run --name playwright -it --rm --ipc=host --cap-add=SYS_ADMIN -u root -p 5900:5900 -URL=whateverURLyouwant -v $(pwd):/src -v /home/Automation/:/root/.m2 mcr.microsoft.com/playwright:bionic &
Also, one point I would like to mention is that, you should not use root user for your executions. Using root as user in docker is not a recommended practice. Instead use the pwuser that is already created by the given image.

Error response from daemon: Mount denied - Error got while running docker application, which was working last night

Suddenly my docker run stopped working last night, which was working before. docker build is working fine, but I get the below error when trying to run the container.
Command
docker run -it --rm -p 9001:4200 -v ${pwd}/src:/app/src angularclient
Error message
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error
response from daemon: Mount denied: The source path
"E:/Karthik/angular/src" doesn't exist and is not known to Docker. See
'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
I tried running the following command in the power shell:
refreshenv
set MSYS_NO_PATHCONV=1
set COMPOSE_CONVERT_WINDOWS_PATHS=1
try this:
docker run -it --rm -p 9001:4200 -v E:/Karthik/angular/src:/app/src angularclient
It seems that you can't use ${pwd} and ./ on win cmd and Git Bash. You can only use absolute paths.
Add this on your ~/.bash_profile:
export MSYS_NO_PATHCONV=1
Add / to prefix of path as below.
docker run -it --rm -p 9001:4200 -v /${pwd}/src:/app/src angularclient
Ensure the drive is shared in Docker settings "Shared Drives".
Create the full path if it doesn't already exist.
Add trailing / to the path.

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)

docker run fails to start command specified as CMD option (path, library no found)

I can start a shell and the target program:
docker run -it mycontainer bash
myscript.py
However, when I start the program directly, it fails:
docker run -it mycontainer myscript.py
It does not find the path. When I provide the path (usr/bin/myscript.py), then the program, it does not find the library: (libpython3.4m.so.rh-python34-1.0: cannot open shared object file).
What can be the reason?

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.

Resources