[英]C# Selenium testing with MS Edge driver
I am using C#, Microsoft.VisualStudio.TestTools.UnitTesting and Selenium to test a website.我正在使用 C#、Microsoft.VisualStudio.TestTools.UnitTesting 和 Selenium 来测试网站。
I know MS Edge is no longer being developed, and is being replaced with a Chromium-based product.我知道 MS Edge 不再被开发,而是被基于 Chromium 的产品所取代。 In the interim, I would still like to be able to tell my customers that Edge is a supported browser until the replacement occurs.
在此期间,在更换发生之前,我仍然希望能够告诉我的客户 Edge 是受支持的浏览器。
But it looks like using the selenium EdgeDriver requires a valid microsoftwebdriver - and the latest one is not compatible with the latest version of Windows - my machine uses Windows 10 Version 1809 / build 17763.379.但看起来使用 selenium EdgeDriver 需要一个有效的 microsoftwebdriver - 最新版本与最新版本的 Windows 不兼容 - 我的机器使用 Windows 10 Version 1809 / build 17763.379。
Has anyone been able to get Edge testing to work with Selenium on a Windows 10 build 1809 machine?有没有人能够在 Windows 10 build 1809 机器上进行 Edge 测试以使用 Selenium? If so, please show some sample code and needed steps / references / usings / etc.
如果是这样,请显示一些示例代码和所需的步骤/参考/使用/等。
If seen a few posting about this where some responses say it is impossible, and others say it is possible - but the ones that say it is possible don't show any actual code or reference names.如果看到一些关于此的帖子,其中一些回复说这是不可能的,而其他人则说这是可能的 - 但那些说可能的人不会显示任何实际代码或参考名称。
I apologize to any readers that I didn't post the solution I eventually found - which is quite simple.我向所有读者道歉,我没有发布我最终找到的解决方案——这很简单。 Here's the code of instantiating the driver:
这是实例化驱动程序的代码:
var service = OpenQA.Selenium.Edge.EdgeDriverService.CreateDefaultService(@"C:\Drivers", @"msedgedriver.exe");
service.UseVerboseLogging = true;
service.UseSpecCompliantProtocol = true;
service.Start();
var options = new OpenQA.Selenium.Edge.EdgeOptions();
// For future reference - please check to see if there are options that should be set...
driver = new RemoteWebDriver(service.ServiceUrl, options);
As you can see, I keep the latest edge driver in a dircetory called "C:\\Drivers".如您所见,我将最新的边缘驱动程序保存在名为“C:\\Drivers”的目录中。 The latest driver can always be downloaded from the selenium website downloads page ( https://www.selenium.dev/downloads/ ) - expand the Browsers section on that page.
始终可以从 selenium 网站下载页面 ( https://www.selenium.dev/downloads/ ) 下载最新的驱动程序 - 展开该页面上的浏览器部分。
Sample C# Code示例 C# 代码
else if (AppSettings.Browser == "Edge")
{
EdgeOptions edgeOptions = new EdgeOptions()
{
UseInPrivateBrowsing = true,
};
driver = new EdgeDriver(edgeOptions);
}
and Remove all Nuget references to MicrosoftDriver, Clean the Solution Then Run the below command in CMD Admin mode并删除对 MicrosoftDriver 的所有 Nuget 引用,清理解决方案然后在 CMD 管理模式下运行以下命令
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0 DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Note: This Solution is for Microsoft Edge version 18 or Above注意:此解决方案适用于 Microsoft Edge 18 或更高版本
Well after a long time navigating the internet found a solution for that!经过很长一段时间的互联网导航,找到了解决方案!
At least you have to remove your NuGet package WebDriver(actual version) and install the beta version, then go to this website https://www.nuget.org/packages/Selenium.WebDriver/4.0.0-beta2 copy the beta nuget you want in my case 4.0.0 till the moment, then open your visual studio (mine is 2019) Tools>Nuget Package Manager>Package Manger Console here you paste your copy.至少你得把你的NuGet包WebDriver(实际版)去掉,安装beta版,然后去这个网站https://www.nuget.org/packages/Selenium.WebDriver/4.0.0-beta2复制beta nuget在我的情况下,你现在想要 4.0.0,然后打开你的 Visual Studio(我的是 2019 年)工具>Nuget 包管理器>包管理器控制台在这里粘贴你的副本。 Ps.
附言。 make download from edge chromium
从边缘铬进行下载
using OpenQA.Selenium.Edge;
public class Example Edger
{
private IWebDriver driver;
public void SetupTest()
{
driver = new EdgeDriver();
driver.Manage().Window.Maximize();
}
}
You need to install edge driver version equal to the version of edge in your system.您需要安装与系统中 edge 版本相同的 edge 驱动程序版本。 To find edge version number go to settings->about microsoft edge .Download the correct version from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver After downloading you need to change the name of driver to MicrosoftWebDriver.exe from msedgedriver.exe.
要查找边缘版本号,请转到设置->关于 microsoft edge。从https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver下载正确的版本下载后,您需要更改驱动程序的名称从 msedgedriver.exe 到 MicrosoftWebDriver.exe。 Then It will work :)
然后它会工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.