我正在.NET中编写自动测试,但[SetUp]有点问题-在[Test]之前没有出现,Chrome浏览器甚至没有打开新窗口-我不知道为什么。
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Net;
using System.Threading;
using Tests.Settings;
namespace Tests.TestCaseScenario
{
public class BaseTestCaseTemplate
{
protected string password;
protected string userName;
protected string websideURL;
public IWebDriver Driver = new ChromeDriver();
//load before each test
[SetUp]
public void SetUp()
{
//load userconfig.json
var UserConfigReader = new UserConfigReader();
var CurrentUserConfig = UserConfigReader.LoadJsonConfigToObj(UserConfigPath);
password = CurrentUserConfig.Password;
userName = CurrentUserConfig.UserName;
websideURL = CurrentUserConfig.WebsiteURL;
Driver.Navigate().GoToUrl(websideURL);
Driver.Manage().Window.Maximize();
}
}
}
这是我的测试课
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
namespace Tests.TestCaseScenario
{
[TestClass]
public class SimplyChecking : BaseTestCaseTemplate
{
[Test]
public void ApplicationCheckerSimple()
{
HomePage homePage = new HomePage();
homePage.Login(userName, password);
}
}
}
和我的Page类:
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
namespace Tests.Pages
{
public class HomePage : BasePageTemplate
{
[FindsBy(How = How.Id, Using = "UserName")]
private IWebElement UserName;
[FindsBy(How = How.Id, Using = "Password")]
private IWebElement Password;
[FindsBy(How = How.ClassName, Using = "btn-primary")]
private IWebElement LoginButton;
public void Login(string user, string password)
{
UserName.SendKeys(user);
Password.SendKeys(password);
LoginButton.Click();
}
}
}
测试甚至无法运行-它不会返回任何值(通过或失败),但是当我为[TestMethod]更改[Test]时,它将运行并给出否定的结果。