我是java和Android的新手。在下面的代码段中,我在用户名&中显示错误消息密码不正确。现在我需要在2次错误尝试后在错误消息中添加一些额外的信息。 如果我需要设置一个计数器来识别尝试? 我该怎么办?
public void testBadCredentials() throws Exception {
RestClientFactoryTest.setPrefixAllInstances("login-failure");
XMLRPCFactoryTest.setPrefixAllInstances("login-failure");
mSolo.enterText(0, "test"); //username
mSolo.enterText(1, "test"); //password
mSolo.clickOnText(mSolo.getString(R.string.sign_in));
boolean errorMessageFound = mSolo.searchText(mSolo.getString(R.string.username_or_password_incorrect));
assertTrue("Error message not found", errorMessageFound);
}
答案 0 :(得分:0)
private static n0_attamp = 0;
public void testBadCredentials() throws Exception {
n0_attamp++;
RestClientFactoryTest.setPrefixAllInstances("login-failure");
XMLRPCFactoryTest.setPrefixAllInstances("login-failure");
mSolo.enterText(0, "test"); //username
mSolo.enterText(1, "test"); //password
mSolo.clickOnText(mSolo.getString(R.string.sign_in));
boolean errorMessageFound = mSolo.searchText(mSolo.getString(R.string.username_or_password_incorrect));
if(n0_attamp = 3)
{
assertTrue("3rd try", errorMessageFound);
//reinitialize counter
n0_attamp = 0;
}
else
assertTrue("Error message not found", errorMessageFound);
}