safary
safary

Reputation: 325

'A project with output type of class library cannot be started directly'

I created new unit test project and and trying to test some links with selenium webdriver, but I am getting this error. When I change output type to console or windows, I get 'Program does not contain a static 'Main' method suitable for an entry point'. Please help me fix this

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using System.Collections.Generic;
using OpenQA.Selenium.Support.PageObjects;

namespace billingtest

{
    [TestClass]
    public class test
    {
        FirefoxDriver driver;

    [TestInitialize()]
    public void SyncDriver()
    {
        driver = new FirefoxDriver();
        driver.Manage().Window.Maximize();
    }

    [TestMethod]
    public void LoginToBilling()
    {

        driver.Navigate().GoToUrl("http://localhost:57862");
        driver.FindElement(By.Id("UserNameOrEmail")).SendKeys("aa");
        driver.FindElement(By.Id("Password")).SendKeys("aa");
        driver.FindElement(By.XPath(".//*[@id='main']/form/div[3]/input")).Click();
        driver.FindElement(By.XPath(".//*[@id='content-main']/div/div/a[3]")).Click();
    }

    [FindsBy(How = How.TagName, Using = "a")]
    public static IList<IWebElement> LinkElements { get; set; }


    public void LoopLink()
    {
        int count = LinkElements.Count;

        for (int i = 0; i < count; i++)
        {
            driver.FindElements(By.TagName("a"))[i].Click();
        }

    }

    [TestCleanup]
    public void TearDown()
    {
        driver.Quit();
    }
}

}

Upvotes: 1

Views: 2475

Answers (1)

Ian
Ian

Reputation: 1251

To run a unit test, put your cursor on the test method and click on the "Run Tests in Current Context" button (also in the 'Test' menu in VS).

See also https://msdn.microsoft.com/en-us/library/ms182524(v=vs.90).aspx.

You should also add some validation to your test method, so that VS can report whether it passed or failed. Add something like:

Assert.IsTrue(outcome);

where outcome is a boolean that indicates the success of your test method.

Upvotes: 2

Related Questions