Created
October 26, 2017 10:32
-
-
Save hussainahmad/4565fc76b3498c3a8e43651646449007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.companyName.myProject; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.support.test.InstrumentationRegistry; | |
import android.support.test.rule.ActivityTestRule; | |
import android.support.test.runner.AndroidJUnit4; | |
import com.companyName.myProject.R; | |
import com.companyName.myProject.home.ui.MainActivity; | |
import junit.framework.Assert; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import static android.support.test.espresso.Espresso.onView; | |
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; | |
/** | |
* Created by Hussain Sherwani on 10/17/2017. | |
*/ | |
@RunWith(AndroidJUnit4.class) | |
public class InstrumentedDeepLinkTest { | |
// If you want to use this Test please modify Deep Link , As I remove links due to security Problem. | |
// Enjoy the Test | |
private static final Uri DEEP_LINK_URI_HOME = Uri.parse("DeepLink for Home"); | |
private static final Uri DEEP_LINK_URI_LANDING_PAGE_MEN = Uri.parse("DeepLink for landing page man"); | |
private static final Uri DEEP_LINK_URI_LANDING_PAGE_WOMEN = Uri.parse("DeepLink for landing page woman"); | |
private static final Uri DEEP_LINK_URI_LANDING_PAGE_KIDS = Uri.parse("DeepLink for landing page Kid"); | |
private static final Uri DEEP_LINK_URI_CART = Uri.parse("DeepLink for cart"); | |
private static final Uri DEEP_LINK_URI_BRAND = Uri.parse("DeepLink for brand"); | |
private static final Uri DEEP_LINK_URI_CATEGORY = Uri.parse("DeepLink for category"); | |
private static final Uri DEEP_LINK_URI_PRODUCT_DETAIL = Uri.parse("DeepLink for product detail"); | |
onView(withId(R.id.textViewProductName)).check(matches(withText("Product Name"))); | |
} | |
@Rule | |
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<MainActivity>(MainActivity.class, true, false) { | |
@Override | |
protected void beforeActivityLaunched() { | |
InstrumentationRegistry.getTargetContext(); | |
super.beforeActivityLaunched(); | |
} | |
}; | |
@Test | |
public void setDeepLinkUriHome() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_HOME)); | |
onView(withId(R.id.main_root_layout)).check(matches(isDisplayed())); | |
} | |
@Test | |
public void setDeepLinkUriLandingPageWomen() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_LANDING_PAGE_WOMEN)); | |
onView(withId(R.id.search_view_container)).check(matches(isDisplayed())); | |
onView(withId(R.id.toolbar_title)).check(matches(withText(R.string.women))); | |
} | |
@Test | |
public void setDeepLinkUriLandingPageMen() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_LANDING_PAGE_MEN)); | |
onView(withId(R.id.search_view_container)).check(matches(isDisplayed())); | |
onView(withId(R.id.toolbar_title)).check(matches(withText(R.string.men))); | |
} | |
@Test | |
public void setDeepLinkUriLandingPageKids() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_LANDING_PAGE_KIDS)); | |
onView(withId(R.id.search_view_container)).check(matches(isDisplayed())); | |
onView(withId(R.id.toolbar_title)).check(matches(withText(R.string.kids))); | |
} | |
@Test | |
public void setDeepLinkUriBrand() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_BRAND)); | |
onView(withId(R.id.headerRootView)).check(matches(isDisplayed())); | |
} | |
@Test | |
public void setDeepLinkUriProductDetail() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_PRODUCT_DETAIL)); | |
onView(withId(R.id.product_detail_view)).check(matches(isDisplayed())); | |
onView(withId(R.id.textViewProductName)).check(matches(withText("Product Name"))); | |
} | |
@Test | |
public void setDeepLinkUriCategory() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_CATEGORY)); | |
onView(withId(R.id.headerRootView)).check(matches(isDisplayed())); | |
onView(withId(R.id.toolbar_title)).check(matches(withText(R.string.women))); | |
} | |
@Test | |
public void setDeepLinkUriCart() { | |
activityRule.launchActivity(new Intent(Intent.ACTION_VIEW, DEEP_LINK_URI_CART)); | |
onView(withId(R.id.root_cart_fragment)).check(matches(isDisplayed())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment