Cameron Aavik
Cameron Aavik

Reputation: 812

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

I am currently attempting to set up Coded UI Testing for a Web App. I created a "Coded UI Test Project" using Visual Studio Enterprise 2015.

I have installed the Microsoft WebDriver and added the 4 NuGet Packages needed to the Coded UI Test Project.

When using the "Coded UI Test Builder", I start on a fresh, new tab on Microsoft Edge, then hit record on the UI Test Builder. No matter what action I take, the builder spits out:

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

I have not installed the Chrome WebDriver myself, but when I click on Chrome and do various things it does work correctly and creates the code for the recorded section. Is there a step I may have forgotten to get this working correctly for Microsoft Edge?

Upvotes: 0

Views: 1552

Answers (1)

Cameron Aavik
Cameron Aavik

Reputation: 812

I was under the pretense when I made this question that I would be able to use the Coded UI Tests with Microsoft Edge. However, it turns out that it just isn't compatible at this point in time.

If you wish to do UI Tests with Microsoft Edge you will need to create a Unit Test Project (Not Coded UI Test Project). You will also not be able to use the UI Test Builder with it.

Here is an example UI Test with a Unit Test Project used with 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");
        }
    }
}

More Information can be found in this blog post

Upvotes: 3

Related Questions