我用 WatiN 编写了一个测试,当用 F10 单步执行代码时,测试成功,但是当我从上下文菜单中执行“运行测试”命令时,测试失败。
这是我的测试:
[TestMethod]
[STAThread]
public void Should_show_captcha_after_three_invalid_login_attempts_with_invalid_username()
{
// Given
int numberOfLoginAttempts = 3;
// When
for (int loginAttempt = 1; loginAttempt <= numberOfLoginAttempts; loginAttempt++)
{
EnterUsername(LoginSettings.ValidUserName);
EnterPassword(loginAttempt.ToString());
ClickLoginButton();
// Check we are still on the loginpage
Assert.IsTrue(_browser.Title.Contains("Inloggen"));
}
bool isCaptchaVisible = _browser.Page<LoginPage>().Captcha.Exists;
// Then
Assert.IsTrue(isCaptchaVisible);
// Make sure to clear the login attempts for next test cases
RemoveLoginAttempts();
}
仅供参考:在数据库中,我们根据用户名跟踪 loginAttempts。当登录尝试次数 > 2 时,将显示验证码。我遇到的问题是DB中的计数器保持1。当我手动单步执行测试时,计数器增加了。
这怎么可能?