【发布时间】:2015-06-30 10:44:11
【问题描述】:
我需要将多个浏览器测试装置组合到我的框架中的帮助。 我的目标是通过定义 testFixture 的类型依次在多个浏览器上运行测试:ChromeDriver、InternetExplorerDriver 等。
我已按照 Pluralsight 上的教程之一来构建我的框架。现在看起来像这样:
TestClass:登录测试
[TestFixture]
public class LoginTest : PortalTest
{
[Test]
public void LoginUser()
{
Assert.IsTrue(HomePage.IsAt, "Failed to login. ");
}
}
接下来,PortalTest 基类:
public class PortalTest
{
[SetUp]
public void Init()
{
Driver.Initialize();
LoginPage.Goto();
LoginPage.LoginAs("user").WithPassword("pass").Login();
}
[TearDown]
public void CleanUp()
{
Driver.Close();
}
}
使用 GoTo() 登录页面:
public class LoginPage
{
public static void Goto()
{
//var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
//wait.Until(d => d.SwitchTo().ActiveElement().GetAttribute("id") == "UserName");
Driver.Instance.Navigate().GoToUrl(Driver.BaseAddress + "Account/LogOn?ReturnUrl=%2FHome");
if (Driver.Instance.Title != "Login")
{
throw new Exception("Not on Login page");
}
}
还有初始化 FirefoxDriver 的驱动程序类:
public class Driver : TestBase
{
public static IWebDriver Instance { get; set; }
public static void Initialize()
{
Instance = new FirefoxDriver();
// wait 5 sec
Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
}
如您所见,Driver 类扩展了 TestBase。这一个定义了多个浏览器案例并返回适当的驱动程序。
我尝试了几次,但没有运气。 我基于的相关帖子: https://stackoverflow.com/a/7854838/2920121
http://makit.net/testing-aspdotnet-mvc-application-with-selenium-and-nunit
【问题讨论】:
标签: c# selenium selenium-webdriver nunit