两种测试方法在 Watin、Gallio 和 MbUnit 中不能同时工作
当我编写这段代码时,它工作正常
using System;
using WatiN.Core;
using MbUnit.Framework;
using Gallio.Framework;
using System.Text.RegularExpressions;
using System.Collections;
using System.IO;
using System.Drawing;
using Gallio.Model;
namespace DialogHandlerTestWithWatin
{
[TestFixture]
class Program
{
//This is WatiN - create IE instance
public static IE ie = new IE();
[SetUp]
public void DoTestSetup()
{
IE.Settings.WaitForCompleteTimeOut = 60;
}
[TearDown]
public static void TestNavigateToMedappz()
{
if (ie != null)
{
if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
{
Assert.Fail("Unable to navigate to the medappz application");
ie.Close();
ie.Dispose();
ie = null;
}
}
}
//This funcn navigate us to the Medappz Application
[Test]
public static void NavigateToMedappz()
{
using (TestLog.BeginSection("Go to Medappz"))
{
Assert.IsNotNull(ie);
ie.GoTo("http://192.168.10.82/Sage/");
ie.ShowWindow(NativeMethods.WindowShowStyle.Maximize);
}
//This is NUnit - check that ie instance is not null
Assert.IsNotNull(ie, "Error creating IE instance.");
Assert.AreEqual("Login Page", ie.Title);
}
但是当我在这段代码中添加另一个测试方法时,
[TearDown]
public static void TestLoginToMedappz()
{
if (ie != null)
{
if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
{
Assert.Fail("Unable to Login");
}
}
}
[Test]
public static void LoginToMedappz()
{
using (TestLog.BeginSection("Login to Medappz"))
{
TextField UserName = ie.TextField(Find.ByName("txtUserName"));
UserName.TypeText("<username>");
TextField Password = ie.TextField(Find.ByName("txtPassword"));
Assert.IsTrue(UserName.Exists, "UserName Textbox does not exist");
Assert.IsTrue(Password.Exists, "Password Textbox does not exist");
Password.TypeText("<password>");
Button btnLogin = ie.Button(Find.ByName("btnLogin"));
Assert.IsTrue(btnLogin.Exists, "btnLogin button does not exist");
btnLogin.Blur();
btnLogin.Click();
}
}
测试开始失败,只打开一个空白的 IE 窗口,几秒钟后,第一个测试方法被执行,但第二个方法没有执行没有被处决。加里奥测试报告说是
鲁特 110 结果:2 次运行,1 次通过,1 次失败,0 次不确定,0 次跳过 持续时间:44.042秒 断言:3 WatiN.Core.Exceptions.ElementNotFoundException:找不到 INPUT(文本密码文本区域隐藏)或 TEXTAREA 元素标记匹配条件:属性“名称”,值为“txtUserName”
When I am writing this piece of code it works fine
using System;
using WatiN.Core;
using MbUnit.Framework;
using Gallio.Framework;
using System.Text.RegularExpressions;
using System.Collections;
using System.IO;
using System.Drawing;
using Gallio.Model;
namespace DialogHandlerTestWithWatin
{
[TestFixture]
class Program
{
//This is WatiN - create IE instance
public static IE ie = new IE();
[SetUp]
public void DoTestSetup()
{
IE.Settings.WaitForCompleteTimeOut = 60;
}
[TearDown]
public static void TestNavigateToMedappz()
{
if (ie != null)
{
if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
{
Assert.Fail("Unable to navigate to the medappz application");
ie.Close();
ie.Dispose();
ie = null;
}
}
}
//This funcn navigate us to the Medappz Application
[Test]
public static void NavigateToMedappz()
{
using (TestLog.BeginSection("Go to Medappz"))
{
Assert.IsNotNull(ie);
ie.GoTo("http://192.168.10.82/Sage/");
ie.ShowWindow(NativeMethods.WindowShowStyle.Maximize);
}
//This is NUnit - check that ie instance is not null
Assert.IsNotNull(ie, "Error creating IE instance.");
Assert.AreEqual("Login Page", ie.Title);
}
But when I add another test method in this code as
[TearDown]
public static void TestLoginToMedappz()
{
if (ie != null)
{
if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
{
Assert.Fail("Unable to Login");
}
}
}
[Test]
public static void LoginToMedappz()
{
using (TestLog.BeginSection("Login to Medappz"))
{
TextField UserName = ie.TextField(Find.ByName("txtUserName"));
UserName.TypeText("<username>");
TextField Password = ie.TextField(Find.ByName("txtPassword"));
Assert.IsTrue(UserName.Exists, "UserName Textbox does not exist");
Assert.IsTrue(Password.Exists, "Password Textbox does not exist");
Password.TypeText("<password>");
Button btnLogin = ie.Button(Find.ByName("btnLogin"));
Assert.IsTrue(btnLogin.Exists, "btnLogin button does not exist");
btnLogin.Blur();
btnLogin.Click();
}
}
Then the test started failing, only a blank IE window opens up and after few seconds the first test method is executed but the second method doesn't gets executed.The Gallio test report says
Root
110
Results: 2 run, 1 passed, 1 failed, 0 inconclusive, 0 skipped
Duration: 44.042s
Assertions: 3
WatiN.Core.Exceptions.ElementNotFoundException: Could not find INPUT (text password textarea hidden) or TEXTAREA element tag matching criteria: Attribute 'name' with value 'txtUserName'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两次考试是在同一个班级吗?我从来没有在同一个班级见过两次拆解。另外,如果 TestNavigateToMedappz 在 LoginToMedappz 之前调用,那么您的 ie 变量将已经被释放。您只需进行一次拆解,然后在 LoginToMedappz 开始时调用 NavigateToMedappz 怎么样?
Are the two tests in the same class? I've never seen two teardowns in the same class. Also, if TestNavigateToMedappz is called before LoginToMedappz then your ie variable will have already been disposed. How about you have just one teardown, then at the start of LoginToMedappz you call NavigateToMedappz?
这就是我认为你想要做的......
你这里有两个测试。 NavigateToMedappz 测试尝试导航到您的应用程序。 LoginToMedappz 测试首先尝试导航到您的应用程序,然后尝试登录。
哈!
Here's what I think you're trying to do...
You have two tests here. The NavigateToMedappz test tries to navigate to your app. The LoginToMedappz test first tries to navigate to your app, and THEN it tries to login.
HTH!