Added download test

This commit is contained in:
mhutti1 2017-04-14 14:49:52 +02:00
parent 8efac394b7
commit b6fce0dd57
5 changed files with 131 additions and 35 deletions

View File

@ -2,16 +2,22 @@ package org.kiwix.kiwixmobile.testutils;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static org.kiwix.kiwixmobile.utils.NetworkUtils.parseURL;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.support.v4.content.ContextCompat;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity.Book;
/**
* Created by mhutti1 on 07/04/17.
@ -36,4 +42,22 @@ public class TestUtils {
}
}
}
public static Matcher<Object> withContent(final String content) {
return new BoundedMatcher<Object, Book>(Book.class) {
@Override
public boolean matchesSafely(Book myObj) {
if (myObj.getUrl() != null) {
return myObj.getUrl().contains(content);
} else {
return myObj.file.getPath().contains(content);
}
}
@Override
public void describeTo(Description description) {
description.appendText("with content '" + content + "'");
}
};
}
}

View File

@ -0,0 +1,104 @@
package org.kiwix.kiwixmobile.utils;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.action.ViewActions.swipeLeft;
import static android.support.test.espresso.action.ViewActions.swipeRight;
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.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.kiwix.kiwixmobile.testutils.TestUtils.withContent;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import javax.inject.Inject;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kiwix.kiwixmobile.KiwixApplication;
import org.kiwix.kiwixmobile.R;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class DownloadTest {
@Rule
public ActivityTestRule<SplashActivity> mActivityTestRule = new ActivityTestRule<>(
SplashActivity.class);
@Test
public void donwloadTest() {
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.get_content_card), withText("Get Content")));
appCompatButton.perform(scrollTo(), click());
ViewInteraction appCompatTextView = onView(
allOf(withText("Device"), isDisplayed()));
appCompatTextView.perform(click());
ViewInteraction appCompatTextView2 = onView(
allOf(withText("Online"), isDisplayed()));
appCompatTextView2.perform(click());
ViewInteraction viewPager2 = onView(
allOf(withId(R.id.container),
withParent(allOf(withId(R.id.zim_manager_main_activity),
withParent(withId(android.R.id.content)))),
isDisplayed()));
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
onData(withContent("ray_charles")).inAdapterView(withId(R.id.library_list)).perform(click());
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatTextView3 = onView(
allOf(withText("Device"), isDisplayed()));
appCompatTextView3.perform(click());
onData(withContent("ray_charles")).inAdapterView(withId(R.id.zimfilelist)).perform(click());
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
onView(withText("Get Content"))
.perform(click());
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
e.printStackTrace();
}
onData(withContent("ray_charles")).inAdapterView(withId(R.id.zimfilelist)).perform(longClick());
onView(withId(android.R.id.button1)).perform(click());
}
}

View File

@ -105,26 +105,6 @@ public class ZimTest {
onView(withText("Home"))
.perform(click());
/*ViewInteraction appCompatButton = onView(
allOf(withId(R.id.get_content_card), withText("Get Content")));
appCompatButton.perform(scrollTo(), click());
TestUtils.allowPermissionsIfNeeded();
ViewInteraction appCompatTextView = onView(
allOf(withText("Device"), isDisplayed()));
appCompatTextView.perform(click());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
onData(withContent("ray charles")).inAdapterView(withId(R.id.zimfilelist)).perform(click());*/
onWebView().withElement(findElement(Locator.LINK_TEXT, "A Fool for You"));
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.RIGHT));
@ -199,18 +179,4 @@ public class ZimTest {
}
};
}
public static Matcher<Object> withContent(final String content) {
return new BoundedMatcher<Object, Book>(Book.class) {
@Override
public boolean matchesSafely(Book myObj) {
return parseURL(getInstrumentation().getTargetContext(), myObj.file.getPath()).equals(content);
}
@Override
public void describeTo(Description description) {
description.appendText("with content '" + content + "'");
}
};
}
}

View File

@ -41,7 +41,6 @@ public class KiwixApplication extends Application {
}
public void setApplicationComponent(ApplicationComponent applicationComponent) {
Log.d("test", applicationComponent.toString());
this.applicationComponent = applicationComponent;
}
}

View File

@ -3,7 +3,9 @@ package org.kiwix.kiwixmobile.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import java.util.UUID;
import org.kiwix.kiwixmobile.KiwixMobileActivity;
import org.kiwix.kiwixmobile.R;
public class NetworkUtils {
@ -56,6 +58,7 @@ public class NetworkUtils {
details = details.trim().replaceAll(" +", " ");
return details;
} catch (Exception e) {
Log.d(KiwixMobileActivity.TAG_KIWIX, "Context invalid url");
return "";
}
}