How to get a C# azure service that uses ChromeDriv

2019-06-26 01:06发布

I've written a C# Azure cloud service that uses Selenium.WebDriver.ChromeDriver but it doesn't work when I deploy it to Azure (Locally it runs fine - probably because I have Chrome installed). I deploy chromedriver.exe with my service but it fails because chrome.exe isn't found. I've tried deploying a copy of chrome.exe but that didn't work. I also tried adding the GoogleChrome nuget package but this also didn't work.

Anyone know a way to get a C# azure service that uses Selenium/Chromedriver to work?

2条回答
可以哭但决不认输i
2楼-- · 2019-06-26 01:47

Three things you'll need to get this to run on an Azure cloudservice

  • ChromeSetup.exe file included in your CloudService/Roles/Role directory
  • A line in your service definition file to call a startup script that runs the above file
  • That startup script included in your worker role's project

To add ChromeSetup.exe, right click on the name of your role beneath the cloud service and just "Add Item" and find where you downloaded the chrome installer last.

Example of Where to Add ChromeSetup.exe from recent project

The startup task is added by going into the ServiceDefinition.cdef file--example from a recent project below.

<WorkerRole name="WebReportDownloader" vmsize="Small">
<Startup>
  <Task commandLine="Initialization\Startup.cmd" executionContext="elevated" taskType="simple">
    <Environment>
      <Variable name="MyVersionNumber" value="1.0.0.0" />
    </Environment>
  </Task>
</Startup>

The script the above task calls is pretty simple and logging anything to a text file is optional from my reading:

ECHO The current version is %MyVersionNumber% >> "%TEMP%\StartupLog.txt" 2>&1
START ChromeSetup.exe 
EXIT /B 0

Hopefully this saves you some of the grief I ran into while piecing together several resources...

查看更多
乱世女痞
3楼-- · 2019-06-26 02:03

I found another way of doing this without having to install Chrome - instead of using Chrome I ended up using Chromium.

For this I just downloaded the Chromium archive from https://chromium.woolyss.com/download/ then have it extract to my binaries directory - this still has Chrome.exe binary but doesn't need installing

查看更多
登录 后发表回答