dotnet core2.0 + Docker + Selenium on Linux
原本是使用dotnet core2.0
途中dotnet core2.1發布了於是就更新了(很隨興)
Nuget install
C#
Dockerfile
docker-compose.yml
-----------------------------------------------以下是失敗過程------------------------------------------------------
在這之前花了一個禮拜時間嘗試在autoservice裡面使用chromedriver
在microsoft/dotnet:2.1-aspnetcore-runtime裡面裝了Chrome必須的東西如下:
最終還是回到Cannot start the driver service on http://localhost 的錯誤
結果使用備案selenium/standalone-chrome:3.14.0-dubnium
三個小時內就成功了orz
Nuget install
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.3" />
<PackageReference Include="Selenium.Support" Version="3.14.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.14.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.41.0" />
<PackageReference Include="Selenium.WebDriver.MicrosoftDriver" Version="17.17134.0" />
C#
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using System;
namespace Test
{
public class Schedule
{
public void GoogleInChrome()
{
var Options = new ChromeOptions();
Options.AddArguments("--whitelisted-ips=''");
using (var driver = new RemoteWebDriver(new Uri($"http://chrometester:4444/wd/hub/"), Options.ToCapabilities(), TimeSpan.FromSeconds(600)))
{
driver.Navigate().GoToUrl("http://google.com");
}
}
}
}
Dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime
ENV ASPNETCORE_ENVIRONMENT TEST
WORKDIR /app
EXPOSE 80
COPY bin/TEST/netcoreapp2.1/publish/ .
ENTRYPOINT ["dotnet", "AutoService.dll"]
docker-compose.yml
version: '3'
autoservice:
build:
context: .
dockerfile: Dockerfile
container_name: autoservice
ports:
- "80:80"
depends_on:
- chrometester
networks:
- autotest
chrometester:
container_name: chrome
image: selenium/standalone-chrome:3.14.0-dubnium
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
networks:
- autotest
networks:
autotest:
driver: bridge
-----------------------------------------------以下是失敗過程------------------------------------------------------
在這之前花了一個禮拜時間嘗試在autoservice裡面使用chromedriver
在microsoft/dotnet:2.1-aspnetcore-runtime裡面裝了Chrome必須的東西如下:
FROM microsoft/dotnet:2.1-aspnetcore-runtime
#install for Chrome
RUN apt-get -yqq update && \
apt-get -yqq install curl unzip && \
apt-get -yqq install gnupg2 && \
apt-get -y install git curl libsdl2-mixer-2.0-0 libsdl2-image-2.0-0 libsdl2-2.0-0 && \
apt-get -y install libgtkextra-dev libgconf2-dev libnss3 libasound2 libxtst-dev
# Install Google Chrome
RUN curl -S -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
apt-get -y update && \
apt-get -y install google-chrome-stable && \
rm -rf /var/lib/apt/lists/*
ENV ASPNETCORE_ENVIRONMENT TEST
WORKDIR /app
EXPOSE 80
COPY bin/TEST/netcoreapp2.1/publish/ .
ENTRYPOINT ["dotnet", "UmonService.dll"]
最終還是回到Cannot start the driver service on http://localhost 的錯誤
結果使用備案selenium/standalone-chrome:3.14.0-dubnium
三個小時內就成功了orz
留言
張貼留言