package com.asksven.betterbatterystats;
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.WindowManager;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
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.scrollTo;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
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;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class ClickThroughTest
{
@Rule
public ActivityTestRule<StatsActivity> mActivityTestRule = new ActivityTestRule<>(StatsActivity.class);
@Before
public void setUp() {
final StatsActivity activity = mActivityTestRule.getActivity();
Runnable wakeUpDevice = new Runnable() {
public void run() {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
};
activity.runOnUiThread(wakeUpDevice);
}
@Test
public void clickThroughTest()
{
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
ViewInteraction appCompatTextView = onView(
allOf(withId(R.id.title), withText("Set Custom Ref."), isDisplayed()));
appCompatTextView.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
ViewInteraction appCompatTextView2 = onView(
allOf(withId(R.id.title), withText("Graphs"), isDisplayed()));
appCompatTextView2.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
ViewInteraction appCompatImageButton = onView(
allOf(withContentDescription("Navigate up"),
withParent(withId(R.id.toolbar)),
isDisplayed()));
appCompatImageButton.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
ViewInteraction appCompatTextView3 = onView(
allOf(withId(R.id.title), withText("Raw Stats"), isDisplayed()));
appCompatTextView3.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
ViewInteraction appCompatImageButton2 = onView(
allOf(withContentDescription("Navigate up"),
withParent(withId(R.id.toolbar)),
isDisplayed()));
appCompatImageButton2.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
ViewInteraction appCompatTextView4 = onView(
allOf(withId(R.id.title), withText("Settings"), isDisplayed()));
appCompatTextView4.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
ViewInteraction appCompatImageButton3 = onView(
allOf(withContentDescription("Navigate up"),
withParent(withId(R.id.toolbar)),
isDisplayed()));
appCompatImageButton3.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
ViewInteraction appCompatTextView5 = onView(
allOf(withId(R.id.title), withText("About"), isDisplayed()));
appCompatTextView5.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
ViewInteraction appCompatImageButton4 = onView(
allOf(withContentDescription("Navigate up"),
withParent(withId(R.id.toolbar)),
isDisplayed()));
appCompatImageButton4.perform(click());
}
}