Using docker with selenium to download multiple files






















In this article, Lets see how we could handle file upload, downloads, accessing the file system while using dockerized selenium tests. File upload is relatively very simple when you use dockerized grid.

You need to ensure that you set the file detector as shown here. Lets look at an easy example first. In the below, case, we could simply get the href attribute value to build the URL of the static file which we need to download.

Even if you use remote webdriver for a docker grid, you could still get the attribute value and using the link, you could download the file easily by running some commands as shown here. Not all the file downloads might be very easy as the above one. In my application, there is no href attribute for a file download link! The file is getting generated at run time, gets downloaded immediately.

In this case, It might be a challenge to assert if the file is downloaded successfully if you are using docker grid. When you download a file using dockerized selenium grid, It downloads and keeps the downloaded file inside the container. It can control the browser inside the container via RemoteWebDriver object. But, there is no way to access container directory. In this case, How can we assert that file has been downloaded?

So you could map them to a directory somewhere in your host machine. Now, when I use docker selenium grid with volume mapping, the downloaded file is present in my host machine in the specific directory which I mapped. I would suggest you to take a look at the awaitility library as shown above to wait for actions to complete.

Check this article on that. This is great, so far! But, What about your tests itself runs inside a container as shown in the articles below.!? How can 2 containers share the file system? Docker volume mapping will help here as well. In this case, we do the mapping twice. One for your browser node — to get the file in the host directory as we saw above and another mapping for your test container. This is to map the host directory which has the file to your container directory. So that your tests inside the container could see the file.

Lets assume that I have created a docker image with my tests included. If you are not sure how, You need to check these articles first! I also assume that all the downloaded files would be present there somehow like magic!!. So, in that case, I should modify my tests as shown here. Now when I run my tests inside the container, I do the volume mapping.

Now the rest is simple. Running the above command will start a container and run the test inside the container — this will trigger the execution in another docker grid.

Since we map same host folder to both of these containers, the containers can share the files via the mapped folder. As you might already know, we do not need to do the mapping every time through command line. Instead, we could define that in the docker-compose file. Create a docker-compose. Docker saves a huge amount of effort related to infrastructure set ups to run the test automation. We define everything in a single file. By feeding this to docker-compose, you create the entire setup with all the dependencies, directories etc in a single command and gets your tests executed.

Thanks for this genius post. Try deleting that directory from your code and see if that helps. I have tried deleting the folder in my project repository and did not changed any code in the test script. Show 7 more comments. Active Oldest Votes. Improve this answer. Hi, thanks for your reply. I need to set volumes for every browser container in order to set the download path. I got help from here. Now my problem is when i want to download a file, what can be the download path in gitlab-ci?

Add a comment. Statement : ' Let me explain a little. This is the cause of your ' assertion exception ' Propose that the following should be done for efficiency and stability: Update the gitlab-ci. Hi, Thanks a lot your suggestions.

I manually create a folder before, but I understand the docker-compose file can create the 'target' folder, I did not manually create this folder any more.

I have tried you suggestion. But the result is the same. AssertionError appears. OK - lets carry out some troubleshooting. There is something strange. But the test fails. I have down the old contains before I run docker-compose up. I have not used this path in the test scipt. The gitlab runner running on another computer, how can i access the chrome container when the test running in gitlab-ci.

But how can i know if I add it or not? Show 12 more comments. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. Learn more about Collectives on Stack Overflow. The Overflow Blog.

Who owns this outage? Building intelligent escalation chains for modern SRE. Podcast Who is building clouds for the independent developer? Featured on Meta.

Now live: A fully responsive profile. Reducing the weight of our footer. Linked 3. Related Hot Network Questions. Question feed.

Stack Overflow works best with JavaScript enabled.



0コメント

  • 1000 / 1000