Skip to content

Commit

Permalink
Isolate UI tests and ignore in CI, test CardBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy committed Oct 1, 2018
1 parent f807afa commit 98047f2
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ install:
- adb shell input keyevent 82 &

script:
- ./gradlew jacocoTestReport -Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest
- ./gradlew jacocoTestReport -Pandroid.testInstrumentationRunnerArguments.notPackage=com.ichi2.anki.uitests

# Codacy integration, partials for all APIs, then an optional finalize
after_success:
Expand Down
13 changes: 9 additions & 4 deletions AnkiDroid/src/androidTest/java/com.ichi2.anki.tests/Shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ public boolean checkCondition() {
/** Get the current activity so, to inspect for View ids */
private Activity getCurrentActivity() {
final Activity[] activity = new Activity[1];
onView(isRoot()).check((view, noViewFoundException) ->
activity[0] = scanForActivity(view.findViewById(android.R.id.content).getContext()));
onView(isRoot()).check((view, noViewFoundException) -> {
View content = view.findViewById(android.R.id.content);
if (content != null) {
activity[0] = scanForActivity(content.getContext());
}
});
return activity[0];
}

Expand Down Expand Up @@ -115,10 +119,11 @@ public static File getTestDir(Context context) {
* @return See getTestDir.
*/
private static File getTestDir(Context context, String name) {
String suffix = "";
if (!TextUtils.isEmpty(name)) {
name = "-" + name;
suffix = "-" + name;
}
File dir = new File(context.getCacheDir(), "testfiles" + name);
File dir = new File(context.getCacheDir(), "testfiles" + suffix);
if (!dir.exists()) {
assertTrue(dir.mkdir());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ichi2.anki.tests;
package com.ichi2.anki.uitests;


import android.Manifest;
Expand All @@ -15,6 +15,7 @@
import com.azimolabs.conditionwatcher.ConditionWatcher;
import com.ichi2.anki.IntentHandler;
import com.ichi2.anki.R;
import com.ichi2.anki.tests.Shared;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
Expand All @@ -35,12 +36,14 @@
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withSubstring;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;

@LargeTest
@SuppressWarnings("PMD.ExcessiveMethodLength")
@RunWith(AndroidJUnit4.class)
public class ActivityTestUI {

Expand Down Expand Up @@ -290,14 +293,8 @@ public void activityTestUI() throws Exception {
isDisplayed()));
floatingActionButton.perform(click());

ViewInteraction appCompatTextView = onView(
allOf(withId(R.id.CardEditorCardsText), withText("Cards: Card 1"),
childAtPosition(
allOf(withId(R.id.CardEditorCardsButton),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
0)));
ConditionWatcher.waitForCondition(new Shared.ViewItemWaitingInstruction(R.id.CardEditorCardsText));
ViewInteraction appCompatTextView = onView(allOf(withId(R.id.CardEditorCardsText), withSubstring("Cards: Card 1")));
appCompatTextView.perform(scrollTo(), click());

ViewInteraction actionMenuItemView = onView(
Expand Down
Loading

0 comments on commit 98047f2

Please # to comment.