【问题标题】:Azure Function using Selenium WebDriver.dll使用 Selenium WebDriver.dll 的 Azure 函数
【发布时间】:2017-10-16 20:04:13
【问题描述】:

我正在尝试使用 Azure Function C# 代码中的 Selenium WebDriver.dll 并在实例化 WebDriver 时遇到以下问题。

错误:

2017-10-16T20:02:25.169 执行函数时出现异常:Functions.fnTestSelenium。 Microsoft.Azure.WebJobs.Script:出现一个或多个错误。 mscorlib:路径不是合法形式。2017-10-16T20:02:25.278 功能完成(失败,Id=2fcb928f-ee39-4cfe-99f2-4be2d57e91b2,持续时间=843ms)

代码

#r "D:\home\site\wwwroot\fnTestSelenium\bin\WebDriver.dll" 使用 System.Net;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    IWebDriver driver=new FirefoxDriver();
    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();

    // Set name to query string or body data
    name = name ?? data?.name;

    return name == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}

【问题讨论】:

  • 请花一点时间将您的代码正确格式化为代码、带有注释 (>) 标记的错误消息、删除标题样式等,以便更容易阅读。

标签: c# azure selenium selenium-webdriver azure-functions


【解决方案1】:

我认为在 Azure Functions 上运行 Selenium 不会取得很大成功。

Azure Functions,如 WebApp 和移动应用,在应用服务中运行。应用服务在称为沙盒的安全环境中运行,该环境具有一定的限制。其中,就是使用GDI+。

您可以查看限制列表,以及不支持的框架列表https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks

如果你往底部检查,你会在不支持的列表中看到 Selenimum:

其他不支持的场景:

PhantomJS/Selenium:尝试连接到本地地址,也使用 GDI+。

【讨论】:

  • 我可以在本地机器上使用 Azure 功能运行 selenium bot,但在实时服务器上它会失败。有什么不同?为什么它首先在本地运行?
  • 在本地您拥有完整的访问权限。应用服务是一个共享环境,如上所述,应用服务沙箱不允许这样做。如果要在应用服务中运行,请尝试在应用服务中运行图片
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 2021-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多