我在设置测试时遇到问题。我已经尝试使用控制台 c# 文件进行运行测试的 selenium 测试,但是它没有出现在测试资源管理器中。当我创建单元测试 c# 项目时,它不会运行或显示在测试资源管理器中。做错了什么?
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();
}
}
}
最佳答案
这可能有效。我认为您的 TestMethod 需要是public
和非静态的才能出现在 Test Explorer 中。
namespace SeleniumTests1
{
[TestClass]
public class SeleniumTest
{
[TestMethod]
public void Main()
{
关于c# - 测试未出现在 Visual Studio 测试资源管理器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35870418/