![](/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.