Peter
Peter

Reputation: 231

Tests not appearing in Visual Studio test explorer

I'm having issues setting up my tests. I have tried using a console c# file for my selenium tests which runs the test however it doesn't appear in the test explorer. When I create a unit test c# project it doesn't run or show up in the test explorer. What have done wrong?

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

namespace SeleniumTests1
{
    [TestClass]
    class SeleniumTest
    {
        [TestMethod]
        static void Main(string[] args)
        {

            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.bing.com/");
            driver.Manage().Window.Maximize();

            IWebElement searchInput = driver.FindElement(By.Id("sb_form_q"));
            searchInput.SendKeys("Hello World");
            searchInput.SendKeys(Keys.Enter);

            searchInput = driver.FindElement(By.Id("sb_form_q"));
            string actualvalue = searchInput.GetAttribute("value");

            Assert.AreEqual(actualvalue, "Hello World");
            driver.Close();
        }
    }
}

Upvotes: 6

Views: 4453

Answers (4)

Pavan Joshi
Pavan Joshi

Reputation: 61

Although this one's a rather obvious and straightforward answer, but, looking at the code posted originally by Peter and my own silly mistake I realized that one more place where we can go wrong is by not making our outer test class public without which they would default to internal and the contained tests would not show up in the test explorer. So, the final form of a unit test code would begin with something like this

namespace SeleniumTests1
{
  [TestClass]
  public class SeleniumTest
  {
    [TestMethod]
    public void testMethod(string[] args)
    {

Upvotes: 1

LukeChristopher
LukeChristopher

Reputation: 11

You're making a Main method the test method? Make a separate test project, then reference the project you're testing and move your code to that instead e.g.

namespace Tests
{
    [TestClass]
    public class MyProjTests
    {
        [TestMethod]
        public void Test{
            //your code
        }
    }
}

Upvotes: 1

Peter
Peter

Reputation: 231

I think I may have managed to resolve the issue in this instance by importing the 4 dlls from the net40 file from the selenium website.

Upvotes: 0

Steve Wong
Steve Wong

Reputation: 2256

This may work. I think your TestMethod needs to be public and non-static in order for it to appear in Test Explorer.

namespace SeleniumTests1
{
    [TestClass]
    public class SeleniumTest
    {
        [TestMethod]
        public void Main()
        {

Upvotes: 13

Related Questions