Skip to content

Commit 2283f1b

Browse files
committed
Resume test
1 parent 0690096 commit 2283f1b

File tree

1 file changed

+53
-0
lines changed
  • basicSample/src/androidTest/java/info/mqtt/java/example

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package info.mqtt.java.example
2+
3+
import android.Manifest
4+
import androidx.test.espresso.Espresso
5+
import androidx.test.espresso.matcher.ViewMatchers
6+
import androidx.test.ext.junit.rules.ActivityScenarioRule
7+
import androidx.test.ext.junit.runners.AndroidJUnit4
8+
import androidx.test.platform.app.InstrumentationRegistry
9+
import androidx.test.rule.GrantPermissionRule
10+
import androidx.test.uiautomator.UiDevice
11+
import com.moka.lib.assertions.MatchOperator
12+
import com.moka.lib.assertions.RecyclerViewItemCountAssertion
13+
import com.moka.utils.Screenshot
14+
import org.junit.Rule
15+
import org.junit.Test
16+
import org.junit.runner.RunWith
17+
18+
@RunWith(AndroidJUnit4::class)
19+
class ResumeTest {
20+
21+
@get:Rule
22+
var mActivityTestRule = ActivityScenarioRule(PahoExampleActivity::class.java)
23+
24+
@get:Rule
25+
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
26+
Manifest.permission.WRITE_EXTERNAL_STORAGE,
27+
Manifest.permission.READ_EXTERNAL_STORAGE
28+
)
29+
30+
@Test
31+
fun checkForDuplicateAfterPressRecentApps() {
32+
val recycler = Espresso.onView(ViewMatchers.withId(R.id.history_recycler_view))
33+
recycler.check(RecyclerViewItemCountAssertion(3, MatchOperator.GREATER_EQUAL))
34+
Screenshot.takeScreenshot("BeforeResume")
35+
36+
// Might be a good idea to initialize it somewhere else
37+
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
38+
uiDevice.pressRecentApps()
39+
Screenshot.takeScreenshot("HomeButton")
40+
Thread.sleep(WAIT_LONG)
41+
42+
uiDevice.pressRecentApps()
43+
Thread.sleep(WAIT)
44+
45+
recycler.check(RecyclerViewItemCountAssertion(3, MatchOperator.GREATER_EQUAL))
46+
Screenshot.takeScreenshot("AfterResume")
47+
}
48+
49+
companion object {
50+
const val WAIT_LONG = 6 * 60 * 1000L
51+
const val WAIT = 1000L
52+
}
53+
}

0 commit comments

Comments
 (0)