简体   繁体   English

是否可以在 Windows Docker 容器中像测试一样运行 Selenium

[英]Is it possible to run Selenium like tests in a Windows Docker Container

we have a Windows Electron application that runs e2e Tests via Spectron.我们有一个 Windows Electron 应用程序,它通过 Spectron 运行 e2e 测试。 The application is platform-dependent and won't run on Linux (Containers).该应用程序依赖于平台,不能在 Linux(容器)上运行。 We want to run our Spectron e2e Tests inside a preconfigured Docker container to have them isolated.我们希望在预配置的 Docker 容器中运行我们的 Spectron e2e 测试以将它们隔离。 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.为了掌握它,我构建了一个最小的 nodejs 应用程序,它基本上什么都不做,并且有一个 e2e 测试 (jest),可以打开浏览器选项卡并检查标题,没有功能只是一个简单的尖峰。

I created a Dockerfile to build a container to run the tests:我创建了一个 Dockerfile 来构建一个容器来运行测试:

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.请注意,这是一个 Windows 容器,因为我们的主应用程序还需要一个 Windows 容器才能运行。 The container builds and runs the test but crashes with the error: SessionNotCreatedError: session not created thrown by from tab crashed .容器构建并运行测试,但因错误而崩溃: SessionNotCreatedError: session not created by from tab crashed On my Windows Host, the test runs fine.在我的 Windows 主机上,测试运行良好。

Is there anything wrong with my Dockerfile or is this simply not possible in a Windows container?我的 Dockerfile 有什么问题吗,或者这在 Windows 容器中根本不可能?

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 :我认为这与问题无关,但这里也是容器执行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');
            });
    });
 
});

We had a similar problem, but we are using .net-core with Selenium.我们遇到了类似的问题,但我们将 .net-core 与 Selenium 一起使用。 For some reason, installing the Chromedriver did not work inside container, so we had to do two things:出于某种原因,在容器内安装 Chromedriver 不起作用,因此我们必须做两件事:

  1. manually download the driver based on the chrome version and export the zip into the working directory.手动下载基于chrome版本的驱动,将zip文件导出到工作目录。 (It's been a while though, and we did not really update the image, installing via choco may be working now) (虽然已经有一段时间了,我们并没有真正更新映像,现在通过 choco 安装可能会起作用)
  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.看看我的 repo: https : //github.com/yamac-kurtulus/Windows-Docker-Images/tree/master/DotnetCore%20Selenium%20With%20Chrome相关部分在 Dockerfile 中的第 23 行之后。

Note: If you are not very deep into the project, I strongly suggest you to migrate to Linux.注意:如果你对项目不是很深入,我强烈建议你迁移到Linux。 Working with Docker on Windows is like a nightmare that you cannot wake up from.在 Windows 上使用 Docker 就像一场你无法醒来的噩梦。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Jenkins CI在Docker容器中运行Selenium测试的最简单方法 - Easiest way to run Selenium tests in a Docker container over Jenkins CI 在docker容器中运行nodeJS app,selenium和webdriver.io测试 - Running nodeJS app, selenium and webdriver.io tests in docker container 从另一个Docker容器运行Zalenium的Selenium命令 - Run Selenium Commands For Zalenium from another Docker Container Docker 容器上的 Selenium - Selenium on a Docker container 是否可以编辑/更改代码并将代码保存在 docker 容器中,或者如果无法将可编辑应用程序连接到 docker 容器并运行它 - Is it possible to edit/alter and save the code in a docker container or, failing that connect an editable app to a docker container, and run it 尝试在Windows Docker容器中运行React时出现fswatch错误 - fswatch error when trying to run react in a windows docker container 在Docker容器中运行和调试测试 - Running and debugging tests in a Docker container 如何使用 alpine 镜像在 Docker 容器中运行单元测试并保存结果? - How can I run units tests in Docker container using alpine image and save the results? vsts 托管代理 docker 容器(ubuntu) - 无法运行夜间测试(连接到端口 4444 上的 127.0.0.1 时出错 - vsts hosted agent docker container (ubuntu) - unable to run nightwatch tests (Error connecting to 127.0.0.1 on port 4444 在 docker Selenium_Hub、Selenium-Node-Chrome-Debug 和带有 Mocha + Selenium-Webdriver (JS) 的容器中运行测试时无法上传文件 - Can not upload files when running tests in docker Selenium_Hub, Selenium-Node-Chrome-Debug and a container w/ Mocha + Selenium-Webdriver (JS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM