2012-07-27 33 views

回答

2

[1] 「A」 型上的文本框

[2] solo.sendKey(97); //這裏97是ascii字符「a」的關鍵代碼。

這裏我代表一個很好的例子。

public void testAutomation_typetext() 
{ 

    solo.clickOnEditText(0); 
    ch_array = "[email protected]".toCharArray(); 
    for(int i=0;i<ch_array.length;i++) 
    { 
     solo.sendKey(fun_get_android_keycode(ch_array[i])); 
    } 
} 


    public int fun_get_android_keycode(char ch) 
    { 
     int keycode = ch;//String.valueOf(ch).codePointAt(0); 
     Log.v(TAG,"in fun : "+ch+" : "+keycode + ""); 

     if(keycode>=97 && keycode <=122) 
     { 
      Log.v(TAG,"atoz : "+ch+" : "+keycode + " : " + (keycode-68)); 
      return keycode-68; 
     } 
     else if(keycode>=65 && keycode <=90) 
     { 
      Log.v(TAG,"atoz : "+ch+" : "+keycode + " : " + (keycode-36)); 
      return keycode-36; 
     } 
     else if(keycode>=48 && keycode <=57) 
     { 
      Log.v(TAG,"0to9"+ch+" : "+keycode + " : " + (keycode-41)); 
      return keycode-41; 
     } 
     else if(keycode==64) 
     { 
      Log.v(TAG,"@"+ch+" : "+keycode + " : " + "77"); 
      return KeyEvent.KEYCODE_AT; 
     } 
     else if(ch=='.') 
     { 
      Log.v(TAG,"DOT "+ch+" : "+keycode + " : " + "158"); 
      return KeyEvent.KEYCODE_PERIOD; 
     } 
     else if(ch==',') 
     { 
      Log.v(TAG,"comma "+ch+" : "+keycode + " : " + "55"); 
      return KeyEvent.KEYCODE_COMMA; 
     } 
     return 62; 
} 

我希望這會有助於您的最佳自動化測試案例。 謝謝。

相關問題