How can I access file downloaded using RSelenium in Github Actions?

24 views Asked by At

I have a test repo in GitHub and I am using GitHub Actions to visit a URL and download a .zip file, using RSelenium and a Docker container running Selenium Firefox. As shown in the code below, I run the Docker image, and I have set up the volumes so that the download folder in my repo is "connected" to the /home/seluser/Downloads where Firefox downloads the .zip file in the Docker container:

on:
  push:
    branches: main

jobs:
  testFlow:
    # The type of OS
    runs-on: ubuntu-latest
    
    services:
      selenium:
        image: selenium/standalone-firefox:111.0-20230328
        ports:
          - '4444:4444'
        volumes:
          - /github/workspace/data/downloads:/home/seluser/Downloads

    steps:
      - name: Set up Docker
        uses: actions/checkout@v2
          
      # Load repo and install R and renv
      - uses: actions/checkout@v4
      - uses: r-lib/actions/setup-r@v2
        with:
          r-version: 'renv'
      - uses: r-lib/actions/setup-renv@v2

      - name: Install libcurl
        run: sudo apt-get install libcurl4-openssl-dev

      # Run R script
      - name: Script
        run: Rscript scripts/test.R

I have tested the following the test.R script locally and it works: the .zip file is downloaded in the container and it appears in the downloads folder in my system. However, when running it on GitHub, it correctly connects to the website but nothing is downloaded. What am I doing wrong? Here is the script I'm using to test it:

fprof <- RSelenium::makeFirefoxProfile(
  list(
    browser.download.dir = "/home/seluser/Downloads"
  )
)

remDr <- RSelenium::remoteDriver(
  remoteServerAddr = "localhost",
  port = 4444L,
  browserName = "firefox",
  extraCapabilities = fprof
)

dir.create(here::here("data", "downloads"), recursive = TRUE)

remDr$open(silent = TRUE)

remDr$navigate("https://demo.borland.com/testsite/download_testpage.php")

Sys.sleep(5)

print(remDr$getTitle())
print(remDr$getCurrentUrl())

remDr$findElement("xpath", "//tr[@filename='Small.zip']//td")$clickElement()
remDr$findElement("xpath", "//button[@id='downloadButton']")$clickElement()

remDr$close()

print(list.dirs("data", recursive = TRUE))
print(list.files("data", recursive = TRUE))
0

There are 0 answers