来自 Main() 或 exe 的 Selenium NUnit 运行
Selenium NUnit run from Main() or exe
我想 运行 来自 exe 的所有 selenium 测试。我尝试了此线程中提到的解决方案 ()
这是我写的
public class Runner{
public static int Main(string[] args)
{
return new AutoRun(Assembly.GetCallingAssembly())
.Execute(new String[]{"/test:Runner.Foo.Login" });}
[TestFixture]
public class Foo
{
IWebDriver driver;
[Test]
public void Initialize()
{
driver = new FirefoxDriver();// (@"C:\Selenium\Firefox");
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait =
TimeSpan.FromSeconds(10);
Console.WriteLine("Setup Browser");
}
[Test]
public void Login()
{
eWb.Classes.LoginUser.eWbLogin(driver, ConfigurationSettings.AppSettings["UserId"],
ConfigurationSettings.AppSettings["Password"], "CU");
}}}}
控制台打开,无法读取测试方法登录。
您正在将 Assembly.GetCallingAssemby()
作为构造函数参数传递给 AutoRun
。由于这是在您的 Main 中,因此没有调用程序集,因此我假设传递的值为 null。被告知要在 null
中查找测试,AutoRun 几乎可以保证不会找到任何测试。
正确的调用是根本不传递任何参数,因为测试实际上是在进行调用的程序集中进行的。 AutoRun 本身会找出调用程序集是什么,并且应该找到您的测试。
您列出的 SO 答案未使用 GetCallingAssembly
。它使用 GetExecutingAssembly
。然而,由于没有任何论证同样有效,这就是我要使用的。事实上,对于 NUnit,您通常应该首先使用默认值,并且只在需要时调整参数。
建议同时阅读文档:https://github.com/nunit/docs/wiki
我想 运行 来自 exe 的所有 selenium 测试。我尝试了此线程中提到的解决方案 (
这是我写的
public class Runner{
public static int Main(string[] args)
{
return new AutoRun(Assembly.GetCallingAssembly())
.Execute(new String[]{"/test:Runner.Foo.Login" });}
[TestFixture]
public class Foo
{
IWebDriver driver;
[Test]
public void Initialize()
{
driver = new FirefoxDriver();// (@"C:\Selenium\Firefox");
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait =
TimeSpan.FromSeconds(10);
Console.WriteLine("Setup Browser");
}
[Test]
public void Login()
{
eWb.Classes.LoginUser.eWbLogin(driver, ConfigurationSettings.AppSettings["UserId"],
ConfigurationSettings.AppSettings["Password"], "CU");
}}}}
控制台打开,无法读取测试方法登录。
您正在将 Assembly.GetCallingAssemby()
作为构造函数参数传递给 AutoRun
。由于这是在您的 Main 中,因此没有调用程序集,因此我假设传递的值为 null。被告知要在 null
中查找测试,AutoRun 几乎可以保证不会找到任何测试。
正确的调用是根本不传递任何参数,因为测试实际上是在进行调用的程序集中进行的。 AutoRun 本身会找出调用程序集是什么,并且应该找到您的测试。
您列出的 SO 答案未使用 GetCallingAssembly
。它使用 GetExecutingAssembly
。然而,由于没有任何论证同样有效,这就是我要使用的。事实上,对于 NUnit,您通常应该首先使用默认值,并且只在需要时调整参数。
建议同时阅读文档:https://github.com/nunit/docs/wiki