use*_*299 6 c# asp.net selenium azure selenium-webdriver
我有:ASP.NET Core2 App + Selenium来使用浏览器自动执行一些操作。
它在本地运行完美。使用所有 nuget 和 exe 的最新版本。
部署到 Azure 后,创建 Webdriver 时出现问题。
我试过:
新的 ChromeDriver(ChromeDriverService.CreateDefaultService("./CORE/ExeFiles"), chromeOptions);
了解一些防火墙或防病毒阻止内容,但找不到在 Azure 上配置必要属性的位置。
如何在 Azure 上使用 Selenium? 一些最简单的例子请??,我为此奋斗了3天=(
PS 还可以找到这篇文章https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks ,最后是这样的:
不支持: PhantomJS/Selenium:尝试连接到本地地址,并且还使用 GDI+。
备择方案?如何在 Azure 上使用 Selenium?
它不适用于应用服务,并且您已经找到了解释它的限制和限制页面。
话虽这么说,它在云服务(带有角色)上运行得很好,是的,很好的云服务。
WebRole 示例 —
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
using OpenQA.Selenium.Support.UI;
namespace WebRole1.Controllers
{
public class PhantomController : ApiController
{
/// <summary>
/// Run PhantomJS UI tests against the specified URL
/// </summary>
/// <param name="URL">URL to test</param>
public string Get(string URL)
{
string result = UITests.Test(URL);
return result;
}
}
/// <summary>
/// UITests class
/// </summary>
public class UITests
{
/// <summary>
/// Test implementation
/// </summary>
/// <param name="URL">URL to test</param>
/// <returns></returns>
public static string Test(string URL)
{
// Initialize the Chrome Driver
// Place phantomjs.exe driver in the project root,
// meaning same folder as WebRole.cs
using (var driver = new PhantomJSDriver())
{
try
{
// Go to the home page
driver.Navigate().GoToUrl(URL);
IWebElement input;
WebDriverWait wait = new WebDriverWait(
driver, TimeSpan.FromSeconds(2));
Func<IWebDriver, IWebElement> _emailInputIsVisible =
ExpectedConditions.ElementIsVisible(By.Id("email"));
wait.Until(_emailInputIsVisible);
input = driver.FindElementById("email");
input.SendKeys("imposter@mailinator.com");
driver.FindElementById("submit").Click();
var alertbox = driver.FindElementById("alert");
if (alertbox.Text.Contains("disposable"))
{
return "PASS";
}
else
{
return "FAIL: alertbox.Text should contain " +
"the word 'disposable'";
}
}
catch (Exception ex)
{
return $"FAIL: {ex.Message}";
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用Headless Chrome查看Azure 容器实例。还有一个.NET SDK。
归档时间: |
|
查看次数: |
10326 次 |
最近记录: |