2017-08-22 4 views
1

Ich betreiben einige Testcodes von Espresso WebEspresso webView webkeys Ausfälle auf dem Android 8.0-Simulator

@Test 
public void typeTextInInput_clickButton_SubmitsForm() { 
    // Lazily launch the Activity with a custom start Intent per test. 
    mActivityRule.launchActivity(withWebFormIntent()); 

    // Selects the WebView in your layout. If you have multiple WebView objects, 
    // you can also use a matcher to select a given WebView, 
    // onWebView(withId(R.id.web_view)). 
    onWebView() 
     // Find the input element by ID. 
     .withElement(findElement(Locator.ID, "text_input")) 

     // Clear previous input and enter new text into the input element. 
     .perform(clearElement()) 
     .perform(DriverAtoms.webKeys(MACCHIATO)) 

     // Find the "Submit" button and simulate a click using JavaScript. 
     .withElement(findElement(Locator.ID, "submitBtn")) 
     .perform(webClick()) 

     // Find the response element by ID, and verify that it contains the 
     // entered text. 
     .withElement(findElement(Locator.ID, "response")) 
     .check(webMatches(getText(), containsString(MACCHIATO))); 
} 

Es ist auf dem 7.1.1 Simulator gearbeitet, aber nicht auf den 8,0 Ich habe die Fehlermeldung als

verursacht durch: java.lang.RuntimeException: Fehler in evaluationEvaluation: Status: 13 Wert: {message = gesetzt Kann die Auswahl end} hasMessage: true Nachricht: nicht das Ende der Selektion

einstellen

wenn ich den Code

element. 
     .perform(clearElement()) 
     .perform(DriverAtoms.webKeys(MACCHIATO)) => perform(webClick()) 

Dann funktioniert es ändern. Ich denke, es kann das Element finden, das die Aktion nicht ausführt. Muss ich irgendetwas in meinem Code ändern?

Antwort

1

Ich bin mit dem gleichen Problem konfrontiert. Bitte beachten Sie diesen Beitrag in Cant add text to webview text field with Espresso

Mein Code funktioniert für Android 7.1.1 Simulator, aber es schlägt auch auf dem Android 8.0 Simulator. Ich habe es gelöst, indem ich Folgendes in der build.gradle getan habe.

1) Aktualisieren Sie die Espresso-Bibliothek. Ich war auf:

androidTestCompile 'com.android.support.test:runner:0.5' 
androidTestCompile 'com.android.support.test:rules:0.5' 
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') 

Nun, um es:

androidTestCompile 'com.android.support.test:runner:1.0.0' 
androidTestCompile 'com.android.support.test:rules:1.0.0' 
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0' 
androidTestCompile('com.android.support.test.espresso:espresso-contrib:3.0.0') 

2) Nachdem das tun, Ihre Anwendung möglicherweise nicht zu bauen. Es könnte sagen, dass es den Test nicht finden können: Läufer: 1.0.0 In diesem Fall müssen Sie

repositories { 
    maven { url "https://maven.google.com" } 
} 

3) das folgende Problem hinzuzufügen, den Sie lösen könnte müssen, ist, dass es um „-Versionen für App beschweren könnte (2x.xx) und Test-App (2x.xx) unterscheiden sich " " Also füge ich das folgende in die Größe ein.

configurations.all { 
    resolutionStrategy.force 'com.android.support:support-annotations:2x.x.x' 
} 

4) Zusätzlich müssen Sie möglicherweise sicherstellen, dass Sie den Runner hinzugefügt haben.

defaultConfig { 
     "android.support.test.runner.AndroidJUnitRunner" 
} 
+0

Danke, es funktioniert für mich. Ich bin seit einiger Zeit in der alten Version von Android Espresso. – Puff

Verwandte Themen