0

we have a Windows Electron application that runs e2e Tests via Spectron. The application is platform-dependent and won't run on Linux (Containers). We want to run our Spectron e2e Tests inside a preconfigured Docker container to have them isolated. To get a grasp of it I have built a minimal nodejs application that does basically nothing and has an e2e test (jest) that opens a browser tab and checks the title, no functionality just a simple spike.

I created a Dockerfile to build a container to run the tests:

FROM  mcr.microsoft.com/windows:20H2-amd64
 
RUN mkdir "C:/app"
WORKDIR "C:/app"
COPY app "C:/app"
 
RUN powershell -Command \
    Set-ExecutionPolicy unrestricted; 
 
ENV chocolateyUseWindowsCompression false
RUN powershell -Command \
    iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); 
 
RUN choco install googlechrome -y --version=91.0.4472.101 --ignore-checksums
RUN choco install chromedriver -y --version=91.0.4472.1010 --ignore-checksums
RUN choco install nodejs-lts -y --version=14.17.1
 
RUN npm config set strict-ssl false
RUN npm install 
 
ENTRYPOINT npm test

Note this is a Windows container, as our main app will also need a Windows container to run. The container builds and runs the test but crashes with the error: SessionNotCreatedError: session not created thrown by from tab crashed. On my Windows Host, the test runs fine.

Is there anything wrong with my Dockerfile or is this simply not possible in a Windows container?

I don't think it's relevant to the problem but here is also the test file that gets executed when the container does npm test:

describe('test google.com', () => {
    const {
        Builder,
        By,
        Key,
        until
    } = require('selenium-webdriver');
    var driver;
 
    beforeEach(() => {
        driver = new Builder()
            .forBrowser('chrome')
            .build();
    });
 
    afterEach(() => {
        driver.quit();
    });
 
    it('should open google search', async () => {
        await driver.get('http://www.google.com');
        driver
            .getTitle()
            .then(title => {
                expect(title).toEqual('Google');
            });
    });
 
});
Tom
  • 3,807
  • 4
  • 33
  • 58

1 Answers1

0

We had a similar problem, but we are using .net-core with Selenium. For some reason, installing the Chromedriver did not work inside container, so we had to do two things:

  1. manually download the driver based on the chrome version and export the zip into the working directory. (It's been a while though, and we did not really update the image, installing via choco may be working now)
  2. Even stranger thing is that we had to install some fonts for some reason.

Take look at my repo: https://github.com/yamac-kurtulus/Windows-Docker-Images/tree/master/DotnetCore%20Selenium%20With%20Chrome The relevant part is after line 23 in the Dockerfile.

Note: If you are not very deep into the project, I strongly suggest you to migrate to Linux. Working with Docker on Windows is like a nightmare that you cannot wake up from.

Yamuk
  • 750
  • 8
  • 27
  • Hey thanks, yeah I know it's a nightmare. Sadly there is no way around it, as it is a windows based product interacting with windows APIs. So generally you were able to run Selenium tests on chrome inside the container which is derived from servercore? I wasn't sure if it would work because the container has technically no GIU so I wasn't sure if chrome and in extension selenium is even able to run. – Tom Jul 02 '21 at 12:33
  • Yes it is working, but it was giving the same "SessionNotCreatedError" until I copied the fonts using that script that I found somewhere I don't remember. – Yamuk Jul 02 '21 at 12:45