【问题标题】:Display a error message according to the no. of tries?根据编号显示错误信息。的尝试?
【发布时间】:2014-05-05 22:26:17
【问题描述】:

我是 Java 和 Android 的新手。在下面的 sn-p 中,当用户名和密码不正确时,我会显示一条错误消息。现在我需要在 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);
}

【问题讨论】:

    标签: java android if-statement conditional-statements


    【解决方案1】:
     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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-29
      • 2013-06-25
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 2015-04-11
      • 2016-07-25
      • 2013-08-20
      相关资源
      最近更新 更多