![](/img/trans.png)
[英]Easiest way to run Selenium tests in a Docker container over Jenkins CI
[英]Is it possible to run Selenium like tests in a Windows Docker Container
我们有一个 Windows Electron 应用程序,它通过 Spectron 运行 e2e 测试。 该应用程序依赖于平台,不能在 Linux(容器)上运行。 我们希望在预配置的 Docker 容器中运行我们的 Spectron e2e 测试以将它们隔离。 为了掌握它,我构建了一个最小的 nodejs 应用程序,它基本上什么都不做,并且有一个 e2e 测试 (jest),可以打开浏览器选项卡并检查标题,没有功能只是一个简单的尖峰。
我创建了一个 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
请注意,这是一个 Windows 容器,因为我们的主应用程序还需要一个 Windows 容器才能运行。 容器构建并运行测试,但因错误而崩溃: SessionNotCreatedError: session not created
by from tab crashed
。 在我的 Windows 主机上,测试运行良好。
我的 Dockerfile 有什么问题吗,或者这在 Windows 容器中根本不可能?
我认为这与问题无关,但这里也是容器执行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');
});
});
});
我们遇到了类似的问题,但我们将 .net-core 与 Selenium 一起使用。 出于某种原因,在容器内安装 Chromedriver 不起作用,因此我们必须做两件事:
看看我的 repo: https : //github.com/yamac-kurtulus/Windows-Docker-Images/tree/master/DotnetCore%20Selenium%20With%20Chrome相关部分在 Dockerfile 中的第 23 行之后。
注意:如果你对项目不是很深入,我强烈建议你迁移到Linux。 在 Windows 上使用 Docker 就像一场你无法醒来的噩梦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.