Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function using Selenium WebDriver.dll

i am trying to use Selenium WebDriver.dll from Azure Function C# code and having following issue when instantiating WebDriver.

Error:

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)

Code

#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);
}
like image 471
Ron Malinin Avatar asked Oct 16 '17 20:10

Ron Malinin


People also ask

Can I use selenium on Azure function?

Selenium is the standard tool for automated web browser testing. On top of that, Selenium is a popular tool for web scraping. When creating a web scraper in Azure, Azure Functions is a logical candidate to run your code in.

How do you integrate Selenium scripts with azure DevOps?

Selenium requires the agent to be run in interactive mode to execute the UI tests. In the VM open web browser, sign in to your Azure DevOps organization and navigate to the Agent pools tab: Choose Azure DevOps, Organization settings. Choose Agent pools.

Can I run Azure function locally?

Your local functions can connect to live Azure services, and you can debug them on your local computer using the full Functions runtime.


1 Answers

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

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

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

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

Other scenarios that are not supported:

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

like image 186
Cloud SME Avatar answered Sep 19 '22 13:09

Cloud SME