How to get a C# azure service that uses ChromeDriver to work in an Azure Cloud Service

淺唱寂寞╮ 提交于 2019-12-10 15:28:17

问题


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?


回答1:


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.

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...




回答2:


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



来源:https://stackoverflow.com/questions/46247034/how-to-get-a-c-sharp-azure-service-that-uses-chromedriver-to-work-in-an-azure-cl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!