使用Selenium WebDriver.dll的Azure函数 [英] Azure Function using Selenium WebDriver.dll

查看:35
本文介绍了使用Selenium WebDriver.dll的Azure函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am trying to use Selenium WebDriver.dll from Azure Function C# code and having following issue when instantiating 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)

2017-10-16T20:02:25.169 Exception while executing function: Functions.fnTestSelenium. Microsoft.Azure.WebJobs.Script: One or more errors occurred. mscorlib: The path is not of a legal form.2017-10-16T20:02:25.278 Function completed (Failure, Id=2fcb928f-ee39-4cfe-99f2-4be2d57e91b2, Duration=843ms)

代码

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

#r "D:\home\site\wwwroot\fnTestSelenium\bin\WebDriver.dll" using 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);
}

推荐答案

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

I don't think you'll have much success running Selenium on Azure Functions.

Azure功能(如WebApp和移动应用程序)在App Service中运行.App Service在称为沙盒的安全环境中运行,该环境具有一定的限制.其中包括使用GDI +.

Azure Functions, like WebApps and Mobile Apps, run in an App Service. The App Service runs in a secure environment called a sandbox which imposes certain limitation. Amongst them, is the use of GDI+.

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

You can see the list of limitation, along with the list of unsupported frameworks https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks

如果您查看底部,您将在不支持的列表中看到Selenimum:

If you check towards the bottom, you will see Selenimum in the list of unsupported:

不支持的其他方案:

Other scenarios that are not supported:

PhantomJS/:尝试连接到本地地址,并且还使用GDI +.

PhantomJS/Selenium: tries to connect to local address, and also uses GDI+.

这篇关于使用Selenium WebDriver.dll的Azure函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆