Skip to content

Commit

Permalink
Merge pull request #425 from AppDevNext/BumpMoka
Browse files Browse the repository at this point in the history
Bump Moka
  • Loading branch information
hannesa2 authored Dec 11, 2022
2 parents 54efb4e + 9cc74ee commit 6d63ea3
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 114 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/Android-CI-Espresso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: macOS-latest
strategy:
matrix:
java_version: [11]
java_version: [ 11 ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -49,20 +49,14 @@ jobs:
with:
name: Logcat-Espresso-report
path: sample/build/reports/androidTests/connected
- name: Save logcat output
uses: actions/upload-artifact@v3
if: failure()
with:
name: Logcat-logcat
path: artifacts/logcat.log
- name: png-find
run: find screenshots -name '*.png'
- name: Archive screenshots
uses: actions/upload-artifact@v3
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: Logcat-Screenshots
path: screenshots/adb
path: |
sample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected
sample/build/outputs/androidTest-results/connected
- name: cleanup
run: ./signing/cleanup.sh
Check:
Expand Down
53 changes: 7 additions & 46 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ android {
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: 'true'
}

buildFeatures {
Expand All @@ -38,7 +39,6 @@ android {

namespace 'info.hannes.logcat.sample'
testNamespace 'info.hannes.logcat.sampletest'

}

dependencies {
Expand All @@ -51,49 +51,10 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"

androidTestImplementation 'com.github.AppDevNext:Moka:1.4'
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_core"
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation "androidx.test:runner:$runnerVersion"
androidTestImplementation "androidx.test:core:$coreVersion"

androidTestImplementation "androidx.test.ext:junit:$extJUnitVersion"
androidTestImplementation "androidx.test.ext:truth:1.4.0"
}

def adbDirectory = '/storage/emulated/0/Download'
def reportsDirectory = "$projectDir/../screenshots/adb"

def clearScreenshotsTask = task('clearScreenshots', type: Exec) {
executable "${android.getAdbExe().toString()}"
args 'shell', 'rm', '-r', adbDirectory
}

def createScreenshotDirectoryTask = task('createScreenshotDirectory', type: Exec, group: 'reporting') {
executable "${android.getAdbExe().toString()}"
args 'shell', 'mkdir', '-p', adbDirectory
}

def fetchScreenshotsTask = task('fetchScreenshots', type: Exec, group: 'reporting') {
executable "${android.getAdbExe().toString()}"
args 'pull', adbDirectory + '/.', reportsDirectory

dependsOn {
createScreenshotDirectoryTask
}

doFirst {
new File(reportsDirectory).mkdirs()
}
}

tasks.whenTaskAdded { task ->
if (task.name == 'connectedDebugAndroidTest' || task.name == 'cAT') {
task.mustRunAfter {
clearScreenshotsTask
}
task.finalizedBy {
fetchScreenshotsTask
}
}
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.github.AppDevNext:Moka:1.6'
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.4"
androidTestUtil "androidx.test.services:test-services:1.4.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.0"
androidTestImplementation "androidx.test:rules:1.5.0" // GrantPermissionRule
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package info.hannes.logcat

import android.Manifest
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import androidx.test.rule.GrantPermissionRule
import com.moka.utils.Screenshot
import info.hannes.logcat.ui.BothLogActivity
import org.hamcrest.Matchers.allOf
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestName
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class AllFragmentsTest {

@get:Rule
var mActivityTestRule = ActivityScenarioRule(BothLogActivity::class.java)
val activityScenarioRule = activityScenarioRule<BothLogActivity>()

@get:Rule
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE)
var nameRule = TestName()

@Test
fun basicTest() {
Expand All @@ -36,7 +34,9 @@ class AllFragmentsTest {
onView(withText("Logcat")).check(ViewAssertions.matches(isDisplayed()))
onView(withText("Logfile")).check(ViewAssertions.matches(isDisplayed()))

Screenshot.takeScreenshot("End")
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
}

}
23 changes: 12 additions & 11 deletions sample/src/androidTest/java/info/hannes/logcat/LogcatTest.kt
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
package info.hannes.logcat

import android.Manifest
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import androidx.test.rule.GrantPermissionRule
import com.moka.lib.assertions.MatchOperator
import com.moka.lib.assertions.WaitingAssertion
import com.moka.utils.Screenshot
import info.hannes.logcat.ui.LogcatActivity
import org.hamcrest.Matchers.allOf
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestName
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class LogcatTest {

@get:Rule
var mActivityTestRule = ActivityScenarioRule(LogcatActivity::class.java)
val activityScenarioRule = activityScenarioRule<LogcatActivity>()

@get:Rule
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)
var nameRule = TestName()

@Test
fun basicLogcatTest() {
onView(allOf(withContentDescription("Logcat"), withParent(withId(info.hannes.logcat.ui.R.id.action_bar)), isDisplayed()))

WaitingAssertion.checkAssertion(info.hannes.logcat.ui.R.id.log_recycler, isDisplayed(), 1500)
Screenshot.takeScreenshot("Step1")
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-Step1")
WaitingAssertion.assertRecyclerAdapterItemsCount(info.hannes.logcat.ui.R.id.log_recycler, 15, MatchOperator.GREATER, 1500)
Screenshot.takeScreenshot("End")
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-End")
}

}
30 changes: 18 additions & 12 deletions sample/src/androidTest/java/info/hannes/logcat/MainActivityTest.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package info.hannes.logcat

import android.Manifest
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import androidx.test.rule.GrantPermissionRule
import com.moka.utils.Screenshot
import info.hannes.logcat.sample.MainActivity
import org.hamcrest.Matchers.allOf
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestName
import org.junit.runner.RunWith


Expand All @@ -23,18 +23,18 @@ import org.junit.runner.RunWith
class MainActivityTest {

@get:Rule
val mActivityTestRule = ActivityScenarioRule(MainActivity::class.java)
val activityScenarioRule = activityScenarioRule<MainActivity>()

@get:Rule
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE)
var nameRule = TestName()

@Before
fun openDrawer() {
val navMain = onView(allOf(withContentDescription("Navigate up"), isDisplayed()))
navMain.perform(click())
Screenshot.takeScreenshot("End")
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
}

@Test
Expand All @@ -43,15 +43,19 @@ class MainActivityTest {
menu.check(matches(isDisplayed()))
menu.perform(click())
Thread.sleep(1000)
Screenshot.takeScreenshot("End")
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
}

@Test
fun navigationFileTest() {
val menu = onView(withText("Timber Logfile"))
menu.check(matches(isDisplayed()))
menu.perform(click())
Screenshot.takeScreenshot("End")
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
}

@Test
Expand All @@ -60,7 +64,9 @@ class MainActivityTest {
menu.check(matches(isDisplayed()))
menu.perform(click())
Thread.sleep(1000)
Screenshot.takeScreenshot("End")
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
}

}
27 changes: 20 additions & 7 deletions sample/src/androidTest/java/info/hannes/logcat/ResumeTest.kt
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
package info.hannes.logcat

import android.Manifest
import androidx.test.core.app.takeScreenshot
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import androidx.test.uiautomator.UiDevice
import com.moka.lib.assertions.MatchOperator
import com.moka.lib.assertions.RecyclerViewItemCountAssertion
import info.hannes.logcat.ui.LogfileActivity
import info.hannes.logcat.utils.RecyclerViewItemDuplicateAssertion
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestName
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class ResumeTest {

@get:Rule
var mActivityTestRule = ActivityScenarioRule(LogfileActivity::class.java)
val activityScenarioRule = activityScenarioRule<LogfileActivity>()

@get:Rule
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE)
var nameRule = TestName()

@Ignore("It doesn't work")
@Test
fun checkForDuplicateAfterPressRecentApps() {
// Might be a good idea to initialize it somewhere else
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1-start")
uiDevice.pressRecentApps()
Thread.sleep(WAIT)
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")

uiDevice.pressRecentApps()
Thread.sleep(WAIT)
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")

// final checks
val recycler = Espresso.onView(ViewMatchers.withId(info.hannes.logcat.ui.R.id.log_recycler))
recycler.check(RecyclerViewItemDuplicateAssertion())
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-5")

recycler.check(RecyclerViewItemCountAssertion(2, MatchOperator.GREATER_EQUAL))
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-6")
}

companion object {
Expand Down
Loading

0 comments on commit 6d63ea3

Please sign in to comment.