简体   繁体   中英

Visual Studio 2017 not displaying my test in the Test Explorer

I wrote the following script on my computer at work, where the script ran perfectly. However, I can't get it to run on my computer at home. I have the exact version of Visual Studio installed. I click build, it successfully builds, however, it doesn't lead to the test being added to the test explorer.

My code is below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
using OpenQA.Selenium.Support.UI;

namespace TrainLineTest
{
    public class Program 
    {
        public static IWebDriver driver = new ChromeDriver();       

        public static void Main(string[] args)
        { }

        public static void SetUp()
        {
            driver.Manage().Window.Maximize();
            driver.Url = "https://www.thetrainline.com";
        }

        [Test]
        public static void EnterDetails()
        {
            SetUp();

            var OriginStation = driver.FindElement(By.Id("originStation"));
            OriginStation.SendKeys("London Euston");

            var DestinationStation = driver.FindElement(By.Id("destinationStation"));
            DestinationStation.SendKeys("Manchester Picadilly");

            var TravelMethod = driver.FindElement(By.Id("journey-type-return"));
            TravelMethod.Click();

            var OutDate = driver.FindElement(By.Id("outDate"));
            OutDate.Clear();
            OutDate.SendKeys("26-Aug-17");
            OutDate.SendKeys(Keys.Tab);

            Thread.Sleep(700);
            new SelectElement(driver.FindElement(By.Id("outDepartOrArrive"))).SelectByValue("B");
            Thread.Sleep(700);

            new SelectElement(driver.FindElement(By.Id("outHour"))).SelectByValue("9");

            new SelectElement(driver.FindElement(By.Id("outMinute"))).SelectByValue("30");

            Thread.Sleep(700);

            var ReturnDate = driver.FindElement(By.Id("returnDate"));
            ReturnDate.Clear();
            ReturnDate.SendKeys("15-Sep-17");
            ReturnDate.SendKeys(Keys.Tab);

            Thread.Sleep(500);
            new SelectElement(driver.FindElement(By.Id("returnDepartOrArrive"))).SelectByValue("B");
            Thread.Sleep(500);

            new SelectElement(driver.FindElement(By.Id("returnHour"))).SelectByValue("14");

            new SelectElement(driver.FindElement(By.Id("returnMinute"))).SelectByValue("30");

            Thread.Sleep(500);


            var Passengers = driver.FindElement(By.ClassName("passenger-summary-people"));
            Passengers.Click();

            Thread.Sleep(500);

            new SelectElement(driver.FindElement(By.Name("AdultsTravelling"))).SelectByValue("2");

            Thread.Sleep(500);

            new SelectElement(driver.FindElement(By.Name("ChildrenTravelling"))).SelectByValue("1");

            Thread.Sleep(500);

            var JourneyComplete = driver.FindElement(By.CssSelector("#extendedSearchForm > div:nth-child(6) > div:nth-child(1) > div > div > button"));
            JourneyComplete.Click();

            Thread.Sleep(5000);

            var ExtendedSearch = driver.FindElement(By.Id("submitButton"));
            ExtendedSearch.Click();

            Thread.Sleep(5000);
        }

        [TearDown]
        public void CloseApp()
        {
            driver.Close();
        }
    }
}

If you are using NUnit3, you'll need to get NUnit3TestAdapter from the NuGet package manager. Once you have this package you'll be able to build your solution and have them show in Visual Studio's Test Explorer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM