简体   繁体   中英

How to use .dockerVolumes of WebDriverManager?

I run my tests in docker by using webdrivermanager. I need to upload some files into the running docker. So, I will be able to use those files in my tests.

I initalised my tests with the code block below:

WebDriverManager wdm = WebDriverManager.chromedriver().browserInDocker()
                .enableVnc().enableRecording();

I get 3 docker image:

CONTAINER ID   IMAGE                         COMMAND                  CREATED         STATUS         PORTS                                              NAMES
202ddc0ff02b   selenoid/video-recorder:7.1   "/entrypoint.sh"         2 minutes ago   Up 2 minutes                                                      serene_lumiere
756cd8a49770   bonigarcia/novnc:1.1.0        "bash -c '/root/noVN…"   2 minutes ago   Up 2 minutes   0.0.0.0:65228->6080/tcp                            stoic_bhaskara
7e7a956fb2c2   selenoid/vnc:chrome_108.0     "/entrypoint.sh"         2 minutes ago   Up 2 minutes   0.0.0.0:65217->4444/tcp, 0.0.0.0:65218->5900/tcp   hopeful_brahmagupta

After that I use dockerVolumes() for being able to copy the file from my local to docker.

However, it seems I keep using it wrong.

wdm.dockerVolumes("/home/GitHub/e2e-test/doc.pdf:/home");

/home/GitHub/e2e-test/doc.pdf is directory on local.

/home is directory in the docker image where I need to have the file at.

When I noticed dockerVolumes() method, I like it. Because, otherwise, I need to implement more steps to make this action like running command line in the tests, read the containers id and copy the file...

However, it didn't work. How can I use it? How copy a file from my local to docker image by using webdrivermanager?

To use Docker volumes with WebDriverManager, you can specify the.dockerVolumes option in the.setup() method. For example:

from webdriver_manager.chrome import ChromeDriverManager

driver = ChromeDriverManager(path="./chromedriver",
                             version="latest",
                             .dockerVolumes={
                                 '/app/chromedriver': '/usr/local/bin/chromedriver'
                             }).install()

This will create a Docker volume that maps the /app/chromedriver directory on the host machine to the /usr/local/bin/chromedriver directory in the container. The ChromeDriver binary will be stored in the /app/chromedriver directory on the host machine, and will be available to the container at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM