|
1 | 1 | package com.sample.browserstack.samplecalculator; |
2 | 2 |
|
3 | | -import android.content.Context; |
4 | | -import androidx.test.platform.app.InstrumentationRegistry; |
| 3 | +import static androidx.test.espresso.action.ViewActions.click; |
| 4 | +import static androidx.test.espresso.action.ViewActions.replaceText; |
| 5 | +import static androidx.test.espresso.matcher.ViewMatchers.withId; |
| 6 | + |
| 7 | +import android.util.Log; |
| 8 | + |
| 9 | +import androidx.test.espresso.Espresso; |
| 10 | +import androidx.test.ext.junit.rules.ActivityScenarioRule; |
5 | 11 | import androidx.test.ext.junit.runners.AndroidJUnit4; |
6 | 12 |
|
| 13 | +import org.junit.Assert; |
| 14 | +import org.junit.Assume; |
| 15 | +import org.junit.Before; |
| 16 | +import org.junit.Ignore; |
| 17 | +import org.junit.Rule; |
7 | 18 | import org.junit.Test; |
| 19 | +import org.junit.experimental.categories.Category; |
8 | 20 | import org.junit.runner.RunWith; |
9 | 21 |
|
10 | | -import static org.junit.Assert.*; |
| 22 | +import com.browserstack.accessibility.AccessibilityUtils; |
11 | 23 |
|
12 | 24 | /** |
13 | 25 | * Instrumented test, which will execute on an Android device. |
|
16 | 28 | */ |
17 | 29 | @RunWith(AndroidJUnit4.class) |
18 | 30 | public class ExampleInstrumentedTest { |
| 31 | + @Rule |
| 32 | + public ActivityScenarioRule<MainActivity> activityScenarioRule = |
| 33 | + new ActivityScenarioRule<>(MainActivity.class); |
| 34 | + |
| 35 | + @Before |
| 36 | + public void myBeforeEach() throws Exception{ |
| 37 | + Log.d("TRANSFORMATION_LOGS", "From @Before"); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testCalculatorBasicOperation() { |
| 42 | + android.util.Log.d("TRANSFORMATION_LOGS", "IN TEST"); |
| 43 | + Espresso.onView(withId(R.id.buttonTwo)).perform(click()); |
| 44 | + Espresso.onView(withId(R.id.buttonAdd)).perform(click()); |
| 45 | + Espresso.onView(withId(R.id.buttonThree)).perform(click()); |
| 46 | + Espresso.onView(withId(R.id.buttonEqual)).perform(click()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void exceptionFailedTest() throws Exception { |
| 51 | + Espresso.onView(withId(R.id.buttonFive)).perform(click()); |
| 52 | + Espresso.onView(withId(R.id.buttonMultiply)).perform(click()); |
| 53 | + Espresso.onView(withId(R.id.buttonTwo)).perform(click()); |
| 54 | + Espresso.onView(withId(R.id.buttonEqual)).perform(click()); |
| 55 | + throw new Exception("EXCEPTION FROM TEST"); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + @Category(ExampleInstrumentedTest.class) |
| 60 | + public void assertionFailedTest() throws Exception { |
| 61 | + Log.d("TEST_LOGS", "testStarted"); |
| 62 | + |
| 63 | + Espresso.onView(withId(R.id.buttonOne)).perform(click()); |
| 64 | + Espresso.onView(withId(R.id.buttonAdd)).perform(click()); |
| 65 | + Espresso.onView(withId(R.id.buttonOne)).perform(click()); |
| 66 | + Espresso.onView(withId(R.id.buttonEqual)).perform(click()); |
| 67 | + |
| 68 | + Log.d("PERFORM_SCAN_LOGS", "beforeScan"); |
| 69 | + AccessibilityUtils.performEspressoAppAccessibilityScan(""); |
| 70 | + Log.d("PERFORM_SCAN_LOGS", "afterScan"); |
| 71 | + |
| 72 | + Thread.sleep(10000); |
| 73 | + |
| 74 | + Log.d("A11Y_RESULTS_SUMMARY", AccessibilityUtils.getResultsSummary().toString()); |
| 75 | + Log.d("A11Y_RESULTS", AccessibilityUtils.getResults().toString()); |
| 76 | + |
| 77 | + Assert.assertTrue(false); |
| 78 | + Thread.sleep(2000); |
| 79 | + |
| 80 | + Log.d("TEST_LOGS", "testEnded"); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + @Category(MainActivity.class) |
| 85 | + public void testTags() throws InterruptedException{ |
| 86 | + Log.d("TEST_LOGS", "testStarted"); |
| 87 | + |
| 88 | + Assert.assertTrue(true); |
| 89 | + Thread.sleep(10000); |
| 90 | + |
| 91 | + Log.d("A11Y_RESULTS_SUMMARY", AccessibilityUtils.getResultsSummary().toString()); |
| 92 | + Log.d("A11Y_RESULTS", AccessibilityUtils.getResults().toString()); |
| 93 | + |
| 94 | + Log.d("TEST_LOGS", "testEnded"); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + @Ignore |
| 99 | + public void testIgnored() throws InterruptedException { |
| 100 | + Log.d("TRANSFORMATION_LOGS", "testIgnored"); |
| 101 | + Thread.sleep(2000); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + @Ignore("IGNORE MESSAGE") |
| 106 | + public void testIgnoredWithMessage() throws InterruptedException { |
| 107 | + Log.d("TRANSFORMATION_LOGS", "testIgnoredWithMessage"); |
| 108 | + Thread.sleep(2000); |
| 109 | + } |
| 110 | + |
19 | 111 | @Test |
20 | | - public void useAppContext() { |
21 | | - // Context of the app under test. |
22 | | - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); |
23 | | - assertEquals("com.sample.browserstack.samplecalculator", appContext.getPackageName()); |
| 112 | + public void testAssumptionFailure() throws InterruptedException { |
| 113 | + Assume.assumeTrue(false); |
| 114 | + Thread.sleep(2000); |
24 | 115 | } |
25 | 116 | } |
0 commit comments