andytriboletti

Untitled

Jan 19th, 2016
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package com.greenrobot.yesorno.test;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.support.test.InstrumentationRegistry;
  6. import android.support.test.rule.ActivityTestRule;
  7. import android.support.test.runner.AndroidJUnit4;
  8. import android.support.test.uiautomator.By;
  9. import android.support.test.uiautomator.UiDevice;
  10. import android.support.test.uiautomator.Until;
  11. import android.test.suitebuilder.annotation.LargeTest;
  12.  
  13. import com.greenrobot.yesorno.Home;
  14.  
  15. import org.junit.Before;
  16. import org.junit.Rule;
  17. import org.junit.Test;
  18. import org.junit.runner.RunWith;
  19.  
  20. import static android.support.test.espresso.Espresso.onView;
  21. import static android.support.test.espresso.assertion.ViewAssertions.matches;
  22. import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
  23. import static android.support.test.espresso.matcher.ViewMatchers.withId;
  24.  
  25. import com.greenrobot.yesorno.R;
  26.  
  27.  
  28. /**
  29. * Created by andytriboletti on 1/15/16.
  30. */
  31. @RunWith(AndroidJUnit4.class)
  32. @LargeTest
  33. public class TestLogin {
  34.  
  35. private UiDevice mDevice;
  36.  
  37. private static final String PACKAGE_NAME = "com.greenrobot.yesorno";
  38. private static final int LAUNCH_TIMEOUT = 5000;
  39.  
  40. @Rule
  41. public ActivityTestRule<Home> mActivityRule = new ActivityTestRule(Home.class);
  42.  
  43. public TestLogin() {
  44. super();
  45. }
  46.  
  47. @Before
  48. public void initTest() {
  49. // Initialize UiDevice instance

  50. mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
  51.  
  52. // Start from the home screen
  53. mDevice.pressHome();
  54.  
  55. // Wait for launcher

  56. String launcherPackage = mDevice.getCurrentPackageName();
  57. mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);
  58.  
  59. // Launch the app

  60. Context context = InstrumentationRegistry.getContext();
  61. Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
  62.  
  63. // Clear out any previous instances

  64. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
  65. context.startActivity(intent);
  66.  
  67. // Wait for the app to appear

  68. mDevice.wait(Until.hasObject(By.pkg(PACKAGE_NAME).depth(0)), LAUNCH_TIMEOUT);
  69. }
  70.  
  71. @Test
  72. public void testLogin() {
  73. onView(withId(R.id.welcome)).check(matches(isDisplayed()));
  74.  
  75. // onView(withText("Hello world!")).check(matches(isDisplayed()));
  76.  
  77. //onView(withId(R.id.changeTextBt)).perform(click());
  78.  
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment