Visual Studio 在进行编码 UI 测试时,将 Microsoft Edge 检测为 Windows 存储应用程序不正确

Visual Studio detecting Microsoft Edge as Windows Store App incorrectly when making Coded UI Test

我目前正在尝试为 Web 应用程序设置编码 UI 测试。我使用 Visual Studio Enterprise 2015 创建了一个 "Coded UI Test Project"。

我已经安装了编码 UI 测试项目所需的 Microsoft WebDriver and added the 4 NuGet Packages

使用 "Coded UI Test Builder" 时,我在 Microsoft Edge 上打开一个全新的选项卡,然后在 UI 测试生成器上点击记录。无论我采取什么行动,建造者都吐槽:

To test Windows Store apps, use the Coded UI Test project template for Windows Store apps under the Windows Store node.

我自己没有安装 Chrome WebDriver,但是当我单击 Chrome 并执行各种操作时,它确实可以正常工作并为记录的部分创建代码。是否有一个步骤我可能忘记了让 Microsoft Edge 正常工作?

当我提出这个问题时,我假装可以在 Microsoft Edge 中使用编码 UI 测试。但是,事实证明它目前不兼容。

如果您想使用 Microsoft Edge 进行 UI 测试,您将需要创建一个单元测试项目(未编码 UI 测试项目)。您也将无法使用 UI 测试生成器。

这是一个示例UI使用与 Microsoft Edge 一起使用的单元测试项目进行测试

using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Support.UI;

namespace ExampleUITest
{
    [TestClass]
    public class ExampleUITest
    {
        private IWebDriver driver;
        private string serverPath = "Microsoft Web Driver";
        private string baseUrl = "http://example.com";


        [TestInitialize]
        public void TestInitialize()
        {
            if (Environment.Is64BitOperatingSystem)
            {
                serverPath = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"), serverPath);
            }
            else
            {
                serverPath = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), serverPath);
            }
            var options = new EdgeOptions
            {
                PageLoadStrategy = EdgePageLoadStrategy.Eager
            };
            driver = new EdgeDriver(serverPath, options);
            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(5));
        }

        [TestCleanup]
        public void TestFinalize()
        {
            // Automatically closes window after test is run
            driver?.Close();
        }

        [TestMethod]
        public void LoadHomePage()
        {
            driver.Url = baseUrl;

            var element = driver.FindElement(By.LinkText("Example Link Text"));
            element.Click();

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
            wait.Until(w => w.Url == $"{baseUrl}/ExampleLink");
            Assert.AreEqual(driver.Url, $"{baseUrl}/ExampleLink");
        }
    }
}

更多信息可以在blog post

中找到