2017-10-16 76 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+.