如何获取使用ChromeDriver在Azure云服务中工作的C

如何获取使用ChromeDriver在Azure云服务中工作的C

本文介绍了如何获取使用ChromeDriver在Azure云服务中工作的C#Azure服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个使用Selenium.WebDriver.ChromeDriver的C#Azure云服务,但是当我将其部署到Azure时它不起作用(在本地运行良好-可能是因为我安装了Chrome).我在服务中部署了chromedriver.exe,但由于未找到chrome.exe而失败.我尝试部署chrome.exe副本,但是没有用.我也尝试添加GoogleChrome nuget程序包,但这也没有用.

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.

有人知道一种使用Selenium/Chromedriver来工作的C#Azure服务的方法吗?

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

推荐答案

要使其在Azure云服务上运行,您需要三件事

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

  • 您的CloudService/Roles/Role目录中包含的ChromeSetup.exe文件
  • 服务定义文件中的一行,用于调用运行上述文件的启动脚本
  • 该启动脚本包含在您的辅助角色的项目中

要添加ChromeSetup.exe,请右键单击云服务下方的角色名称,然后单击添加项目",然后找到上次下载chrome安装程序的位置.

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.

将启动任务添加到ServiceDefinition.cdef文件中(以下最新项目为例).

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

这篇关于如何获取使用ChromeDriver在Azure云服务中工作的C#Azure服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:18