Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98756

Selenium chrome-standalone download file without popup

$
0
0

I'm trying to run Selenium in docker. Therefore I have the selenium/standalone-chrome together with node in my docker-compose:

# Inspired by https://www.testmo.com/guides/github-actions-selenium/services:  chrome:    image: selenium/standalone-chrome    shm_size: '2gb'    ports:      - 4444:4444 # Selenium service      - 5900:5900 # VNC server      - 7900:7900 # VNC browser client    volumes:      - ./:/project      - ./download:/Downloads    working_dir: /project  node:    image: node:19    volumes:      - ./:/project    working_dir: /project    tty: true    depends_on:      - chrome

I use Selenium with JavaScript. In my test file in my before I try to convince chrome not to open a popup for download, since I can't easily interact with that:

before(async () => {    if (!fs.existsSync(downloadDirectory)){        fs.mkdirSync(downloadDirectory);    }    const downloadPath = path.resolve('download');    let options = new chrome.Options();    options.setUserPreferences({"profile.default_content_settings.popups": 0,"download.default_directory": downloadPath,"download.prompt_for_download": false,"download.directory_upgrade": true,"download.prompt_for_download": false,"plugins.always_open_pdf_externally": true,"plugins.plugins_disabled": "Chrome PDF Viewer","pdfjs.disabled": true,"download.extensions_to_open": "applications/pdf"    });    const host = process.env.SELENIUM || undefined;    const server = host ? `http://${host}:4444` : '';    driver = await new Builder()        .usingServer(server)        .forBrowser(Browser.CHROME)        .setChromeOptions(options)        .build()    await driver.manage().setTimeouts({ implicit: implicitWait });});

However, when I run the test inside docker (I'm getting inside with docker compose exec node bash and run the tests with SELENIUM=chrome npx mocha test/badge.spec.js), I still get a popup. What am I doing wrong? If you want to see the whole code, you can see it here.


Viewing all articles
Browse latest Browse all 98756

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>