Reputation: 173
I have a selenium script that to upload an attachment runs on maven and java and is working fine when run from Local.
When I run it on docker container using selenium standalone server receiving the following exception
org.openqa.selenium.InvalidArgumentException: invalid argument: File not found :
Not sure how to resolve it inside the container, I have verified the file is available
The docker compose file Iam using is as follows:
version : '3'
services :
maven:
container_name : Maven-Java
image : maven:3.5.3-jdk-8-alpine
volumes :
- .:/workspace
- ~/.m2:/root/.m2
depends_on :
- selenium
command : mvn -f /workspace test
selenium:
container_name : selenium
image : selenium/standalone-chrome:latest
volumes:
- /dev/shm:/dev/shm
ports :
- 4444:4444
Upvotes: 1
Views: 1272
Reputation: 776
Mounting the volume on the browser and then using File.separator
worked
Upvotes: 0
Reputation: 215
You need to add a path configuration. Create a file browsers.json add this script there
{
"chrome": {
"default": "85.0",
"versions": {
"85.0": {
"image": "selenoid/vnc:chrome_85.0",
"port": "4444",
"volumes": ["/home/ubuntu/your-project:/opt/docker"]
}
}
}
}
and run with this --browsers-json browsers.json
argument
this example is for selenoid, but if you don't use selenoid, just add "volumes": ["/home/ubuntu/your-project:/opt/docker"]
to your selenium grid config.
Upvotes: 0
Reputation: 173
thank you all for the answer's so the working solution I found are two one is as @Alexey mentioned I should also volume map my script folder to the selenium container as well as below:
selenium:
volumes :
- .:/workspace
Above is a docker oriented solution, the other one I found is with selenium grid where the grid can detect the files using a file detector, it can be done by adding the following snipet.
remoteDriver.setFileDetector(new LocalFileDetector());
Both the solutions are working and have solved my problem.
Upvotes: 1
Reputation: 8686
You mounted the volume to container where your test code is running. However you need to mount the volume to the container where the browser is running.
The thing is that when your code says to the web app "hey, this is the file that you need to upload", the test code sends not a file itself but a path that is passed to the browser. Then browser tries to look up that file and build appropriate request to the server.
So the file hast to be within the container where the browser is running.
Upvotes: 2