3

I have used .NetCore2 App and try to takes the screenshot of given URL. It works perfect on local but After deploy to Azure have problems on create Webdriver.

 at OpenQA.Selenium.DriverService..ctor(String servicePath, Int32 port, String driverServiceExecutableName, Uri driverServiceDownloadUrl)
↵   at OpenQA.Selenium.Chrome.ChromeDriverService..ctor(String executablePath, String executableFileName, Int32 port)
↵   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
↵   at SceenshotApp.Service.Screenshot.TakeScreenshot(String url, Int32 width, Int32 height, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Service\Screenshot.cs:line 21
↵   at SceenshotApp.Controllers.HomeController.TakeScreenshot(String url, Int32 width, Int32 height, Int32 scale, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Controllers\HomeController.cs:line 51"

below my code

 public static string GetScreenshot(string url)
    {
        ChromeOptions options = new ChromeOptions();
        var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
        driver.Manage().Window.Size = new System.Drawing.Size(1000, 768);
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100);
        driver.Navigate().GoToUrl(url);
        driver.Close();
        driver.Quit();
        return path;
    }

How can I use Chrome driver on Azure?

Nayeem Mansoori
  • 821
  • 1
  • 15
  • 41
  • 1
    Due to azure web app sandbox, the selenium is not supported on azure web app. – Ivan Glasenberg Jul 19 '19 at 05:18
  • @Ivan Yang : thanks for reply, any alternatives ? – Nayeem Mansoori Jul 19 '19 at 05:23
  • It's not a good solution, but it can work if deploys to azure vm. – Ivan Glasenberg Jul 19 '19 at 05:27
  • my path is under Nuget package Selenium.Chrome.WebDriver – Nayeem Mansoori Jul 19 '19 at 05:36
  • @Dimitar : I'm using var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options); – Nayeem Mansoori Jul 19 '19 at 05:40
  • Can you post the full exception (currently it's a bit cutted) stack trace ? – Dimitar Jul 19 '19 at 05:55
  • OpenQA.Selenium.DriverServiceNotFoundException The file D:\home\site\wwwroot\chromedriver.exe does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html at OpenQA.Selenium.DriverService..ctor(String servicePath, Int32 port, String driverServiceExecutableName, Uri driverServiceDownloadUrl) ↵ at OpenQA.Selenium.Chrome.ChromeDriverService..ctor(String executablePath, String executableFileName, Int32 port) – Nayeem Mansoori Jul 19 '19 at 06:00
  • its not working even not works on local – Nayeem Mansoori Jul 19 '19 at 06:11
  • @Dimitar, you should test it yourself then answer the op. And as per the [azure web app sandbox limitation](https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks), it's not supported. – Ivan Glasenberg Jul 19 '19 at 06:23

1 Answers1

6

As @IvanYang said, Selenium is not supported on Azure App Service for Windows, as the figure below from Azure Web App sandbox.

enter image description here

The reason is Win32k.sys (User32/GDI32) Restrictions

enter image description here

However, you can try to deploy your .net core app to Azure App Service on Linux, which be based on docker image.

So you can follow the quick start tutorial Create an ASP.NET Core app in App Service on Linux to migrate your current app for Linux. And due to Selenium requires headless chrome, you must have to install chromium or chrome or their headless distributions and webdriver in the docker image or write in the Dockerfile first, please refer to the offical document Tutorial: Build a custom image and run in App Service from a private registry to know it.

As reference, there are many blogs which helps for you and you can search via Google/Bing, such as Selenium in Docker with DotNetCore Chrome in Linux and Headless Mode.

Hope it helps.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43