[英]How can I run a test in a private IE browser in C#, using Selenium in Visual Studio?
[英]How can I get my Selenium test to run in Visual Studio?
我正在尝试开发脚本来测试我编写的应用程序。 我创建的第一个脚本是一个简单的登录、验证几件事并注销的脚本。 我可以让它出现在测试资源管理器中,但由于某种原因它不会运行。 我检查了 output 日志并得到了几个错误,但不确定它们指向哪里。
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Threading;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl(@"http://localhost/github/restaurant/login.php"); //nav to page
Thread.Sleep(2000); // Implicit wait to ensure page is loaded
Assert.IsTrue(driver.FindElement(By.XPath("//*[@id='username']")).Displayed); //look for username field
IWebElement userField = driver.FindElement(By.XPath("//*[@id='username']")); //mapping userfield to username
userField.SendKeys("admin"); //typing admin into userfield
Assert.IsTrue(driver.FindElement(By.XPath("//*[@id='password']")).Displayed); //looking for password field
IWebElement pwField = driver.FindElement(By.XPath("//*[@id='password']")); //mapping pwField to password
pwField.SendKeys("password"); //typing password into pwField
driver.FindElement(By.XPath("//*[@id='login']")).Click(); //clicking login btn
Thread.Sleep(1000); // Implicit wait to ensure page is loaded
Assert.IsTrue(driver.FindElement(By.XPath("//*[@id='logout']")).Displayed); //look for logout button
driver.FindElement(By.XPath("//*[@id='logout']")).Click(); //clicking logout button
Thread.Sleep(1000); //implicit wait
}
}
}
那是我的脚本,我得到的错误如下。 有没有人知道脚本的问题是什么?
System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.DotnetHostHelper.TryGetExecutablePath(String executableBaseName, String& executablePath)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.DotnetHostHelper.GetDotnetPath()
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
[6/15/2020 2:36:11.594 PM] ========== Discovery aborted: 0 tests found (0:00:00.0241822) ==========
从“TEMP”文件夹中删除 specflow 文件,重建解决方案并重试。 看看结果如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.