Search code examples
c#visual-studioselenium.net-coreexcel-addins

C# UI Test being ignored and not running?


So I wrote a test and am trying to run it but when I right click it and hit, "Run Selected Test" the green loading bar moves up for less than a second and just stops. Fairly new to this so excuse my ignorance.

Test being ignored & not running.

This is the stack trace I get from the test output when I try to run it.

This is my session class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;

public class CCSession
{
    // Note: append /wd/hub to the URL if you're directing the test at Appium
    protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";

    protected static WindowsDriver<WindowsElement> session;

    private const string ExcelAppId = @"C:\Program Files\Microsoft Office\root\Office16\EXCEL.exe"; // test

    public static void Setup(TestContext context)
    {
        // Launch Excel application if it is not yet launched
        if (session == null)
        {
            // Create a new session to launch Excel application
            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", ExcelAppId);
            appCapabilities.SetCapability("deviceName", "WindowsPC");
            session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(session);

            session.FindElementByName("Blank workbook").Click();

            // Verify that Excel is started with untitled new file
            Assert.AreEqual("Book1 - Excel", session.Title);

            // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
            session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
        }
    }

    public static void TearDown()
    {
        // Close the application and delete the session
        if (session != null)
        {
            session.Close();

            try
            {
                // Dismiss Save dialog if it is blocking the exit
                session.FindElementByName("Don't Save").Click();
            }
            catch { }

            session.Quit();
            session = null;
        }
    }
}

Test class:

using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Api.Dto;
using CEL.CostCalculator.Api.CalculationResults;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
using Tests.Fixtures.DataPorts;

[TestClass]
public class CCExcelAddInTests : CCSession
{
    [TestMethod]
    public void EditorEnterText()
    {
        Assert.AreEqual("Book1 - Excel", session.Title);
    }

    [ClassInitialize]
    public static void ClassInitialize(TestContext context)
    {
        Setup(context);
    }

    [ClassCleanup]
    public static void ClassCleanup()
    {
        TearDown();
    }
}

Any help's appreciated. :)


Solution

  • My test projects .csproj file was corrupted. Corrected and tests are visibly running again.