2017-10-16 30 views
2

我想从Azure函数C#代码中使用Selenium WebDriver.dll,并在实例化WebDriver时遇到以下问题。使用Selenium WebDriver.dll Azure函数

错误:

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:\家\网站\ 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); 
} 
+0

请大家分钟来正确地将代码格式化为代码,带有注释(>)标记的错误消息,删除标题样式等,以便更容易阅读。 – JeffC

回答

2

我不认为在Azure函数上运行Selenium会有很大的成功。

Azure函数(如WebApps和移动应用程序)在App Service中运行。应用程序服务运行在一个称为沙箱的安全环境中,这个环境有一定的限制。其中,就是使用GDI +。

你可以看到限制的名单,与不支持框架的列表一起https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks

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

Other scenarios that are not supported:

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