2015-05-27 52 views
1

我使用Espresso2.0。Espresso2.0 typeText(string)bug?

String str = "Hello_world"; 
onView(withId(R.id.et_jumpfrom)) 
     .perform( typeText(str) , closeSoftKeyboard() ); 
onView(withId(R.id.btn_jumpform_reshow)) 
     .perform(click()); 

// check the result 
onView(withId(R.id.tv_jumpfrom_display)) 
     .check(matches(withText(str))); 

當我使用

typeText("hello") 

檢查()的結果是OK。

但是,當我使用

typeText("Hello_world"); 

檢查失敗。

我檢查了錯誤信息,並發現了EditText上實際上是輸入

H'e'l'l'o_'w'o'r'l'd 

這是很奇怪的。我該如何解決這個問題?


下面是我的全部代碼:

  1. 的build.gradle

    dependencies { 
        // Testing-only dependencies 
        androidTestCompile 'com.android.support.test:runner:0.2' 
        androidTestCompile ('com.android.support.test.espresso:espresso-core:2.1') 
    } 
    
  2. 測試

    import static android.support.test.espresso.Espresso.onView; 
    import static android.support.test.espresso.Espresso.pressBack; 
    import static android.support.test.espresso.action.ViewActions.click; 
    import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; 
    import static android.support.test.espresso.action.ViewActions.typeText; 
    import static android.support.test.espresso.assertion.ViewAssertions.matches; 
    import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 
    import static android.support.test.espresso.matcher.ViewMatchers.withId; 
    import static android.support.test.espresso.matcher.ViewMatchers.withText; 
    import static org.hamcrest.Matchers.containsString; 
    
    @RunWith(AndroidJUnit4.class) 
    @LargeTest 
    public class JumpActivityTest { 
        public String str = "Espresso_Test"; 
    
        @Rule 
        public ActivityTestRule<JumpFromActivity> actvRule = new ActivityTestRule<>(JumpFromActivity.class); 
    
        @Test 
        public void changeText_sameActv() { 
         onView(withId(R.id.et_jumpfrom)) 
           .perform(typeText(str), closeSoftKeyboard()); 
         onView(withId(R.id.btn_jumpform_reshow)) 
           .perform(click()); 
    
         // check the result 
         onView(withId(R.id.tv_jumpfrom_display)) 
           .check(matches(withText(str))); 
        }  
    
    } 
    
  3. 期待

    的EditText上被輸入 「Espress_Test」

  4. 實際輸出

    android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "Espresso_Test"' doesn't match the selected view. 
    Expected: with text: is "Espresso_Test" 
    Got: "TextView{id=2131165188, res-name=tv_jumpfrom_display, visibility=VISIBLE, width=353, height=59, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=183.0, y=96.0, text=E's'p're's'so'_T'e'st, input-type=0, ime-target=false, has-links=false}" 
    
    at dalvik.system.VMStack.getThreadStackTrace(Native Method) 
    at java.lang.Thread.getStackTrace(Thread.java:579) 
    at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:82) 
    ... 
    

然後我看到的EditText文本實際上

text=E's'p're's'so'_T'e'st 
+0

與論壇網站不同,我們不使用「謝謝」或「任何幫助表示讚賞」,或在[so]上簽名。請參閱「[應該'嗨','謝謝',標語和致敬從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be –

+0

你爲什麼要編輯這個人的標題並混淆其他人? 現在沒有任何區別,但他明確指出在第一行使用2.0 @JohnSaunders – appoll

+0

@snwr,I無法重現您的問題,請張貼測試和預期結果,並確保您使用的是正確的標識符。似乎您在測試課程中或在測試課程中使用了錯誤的標識符 – appoll

回答

0

是這是因爲IME。

百度輸入法有這個問題。

它會很好的谷歌輸入法。