Introduce android 13 CI in project

This commit is contained in:
MohitMali 2022-11-22 11:47:15 +05:30
parent 21c6a27881
commit a0449efffa
10 changed files with 202 additions and 151 deletions

View File

@ -15,8 +15,7 @@ jobs:
coverageReport:
strategy:
matrix:
api-level: [21,30]
target: [ google_apis ]
api-level: [21,30,33]
fail-fast: false
runs-on: macos-11
steps:
@ -41,20 +40,41 @@ jobs:
${{ runner.os }}-gradle-
- name: create instrumentation coverage
uses: ReactiveCircus/android-emulator-runner@v2.23.0
uses: ReactiveCircus/android-emulator-runner@v2.25.0
env:
GRADLE_OPTS: "-Dorg.gradle.internal.http.connectionTimeout=60000 -Dorg.gradle.internal.http.socketTimeout=60000 -Dorg.gradle.internal.network.retry.max.attempts=6 -Dorg.gradle.internal.network.retry.initial.backOff=2000"
if: ${{ matrix.api-level != 33 }}
with:
api-level: ${{ matrix.api-level }}
target: default
arch: x86_64
profile: pixel_2
ndk: 21.4.7075529
ram-size: '4096M'
disk-size: '14G'
sdcard-path-or-size: '1000M'
disable-animations: false
script: bash contrib/instrumentation.sh
- name: create instrumentation coverage on google_apis for android 33
uses: ReactiveCircus/android-emulator-runner@v2.25.0
env:
GRADLE_OPTS: "-Dorg.gradle.internal.http.connectionTimeout=60000 -Dorg.gradle.internal.http.socketTimeout=60000 -Dorg.gradle.internal.network.retry.max.attempts=6 -Dorg.gradle.internal.network.retry.initial.backOff=2000"
if: ${{ matrix.api-level == 33 }}
with:
api-level: ${{ matrix.api-level }}
target: google_apis
arch: x86_64
profile: pixel_2
ndk: 21.4.7075529
ram-size: '4096M'
disk-size: '14G'
sdcard-path-or-size: '1000M'
disable-animations: false
script: bash contrib/instrumentation.sh
- name: Upload screenshot result
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ matrix.api-level }}

View File

@ -17,6 +17,7 @@
*/
package org.kiwix.kiwixmobile.help
import android.os.Build
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
@ -34,18 +35,20 @@ class HelpFragmentTest : BaseActivityTest() {
@Test
fun verifyHelpActivity() {
runOnUiThread { activityRule.activity.navigate(R.id.helpFragment) }
help {
clickOnWhatDoesKiwixDo()
assertWhatDoesKiwixDoIsExpanded()
clickOnWhatDoesKiwixDo()
clickOnWhereIsContent()
assertWhereIsContentIsExpanded()
clickOnWhereIsContent()
clickOnHowToUpdateContent()
assertHowToUpdateContentIsExpanded()
clickOnHowToUpdateContent()
clickOnSendFeedback()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
runOnUiThread { activityRule.activity.navigate(R.id.helpFragment) }
help {
clickOnWhatDoesKiwixDo()
assertWhatDoesKiwixDoIsExpanded()
clickOnWhatDoesKiwixDo()
clickOnWhereIsContent()
assertWhereIsContentIsExpanded()
clickOnWhereIsContent()
clickOnHowToUpdateContent()
assertHowToUpdateContentIsExpanded()
clickOnHowToUpdateContent()
clickOnSendFeedback()
}
}
}
}

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.initial.download
import android.os.Build
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import androidx.test.ext.junit.runners.AndroidJUnit4
@ -53,15 +54,17 @@ class InitialDownloadTest : BaseActivityTest() {
@Test
fun initialDownloadTest() {
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.downloadsFragment) }
initialDownload {
assertLibraryListDisplayed()
refreshList()
waitForDataToLoad()
downloadZimFile()
assertStorageConfigureDialogDisplayed()
clickYesToConfigureStorage()
assertDownloadStart()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.downloadsFragment) }
initialDownload {
assertLibraryListDisplayed()
refreshList()
waitForDataToLoad()
downloadZimFile()
assertStorageConfigureDialogDisplayed()
clickYesToConfigureStorage()
assertDownloadStart()
}
}
}

View File

@ -17,6 +17,7 @@
*/
package org.kiwix.kiwixmobile.intro
import android.os.Build
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
@ -29,8 +30,10 @@ class IntroFragmentTest : BaseActivityTest() {
@Test
fun viewIsSwipeableAndNavigatesToMain() {
runOnUiThread { activityRule.activity.navigate(R.id.introFragment) }
intro(IntroRobot::swipeLeft) clickGetStarted {}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
runOnUiThread { activityRule.activity.navigate(R.id.introFragment) }
intro(IntroRobot::swipeLeft) clickGetStarted {}
}
}
@Before

View File

@ -19,6 +19,7 @@ package org.kiwix.kiwixmobile.language
import android.Manifest
import android.app.Instrumentation
import android.os.Build
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import androidx.test.ext.junit.rules.ActivityScenarioRule
@ -67,18 +68,20 @@ class LanguageFragmentTest {
@Test
fun testLanguageFragment() {
UiThreadStatement.runOnUiThread {
activityScenarioRule.scenario.onActivity {
it.navigate(R.id.downloadsFragment)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
UiThreadStatement.runOnUiThread {
activityScenarioRule.scenario.onActivity {
it.navigate(R.id.downloadsFragment)
}
}
}
language {
waitForDataToLoad()
clickOnLanguageIcon()
searchAndSaveLanguage("german", "German")
clickOnLanguageIcon()
searchAndSaveLanguage("italiano", "Italian")
language {
waitForDataToLoad()
clickOnLanguageIcon()
searchAndSaveLanguage("german", "German")
clickOnLanguageIcon()
searchAndSaveLanguage("italiano", "Italian")
}
}
}
}

View File

@ -17,6 +17,7 @@
*/
package org.kiwix.kiwixmobile.main
import android.os.Build
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
@ -49,32 +50,34 @@ class TopLevelDestinationTest : BaseActivityTest() {
@Test
fun testTopLevelDestination() {
ActivityScenario.launch(KiwixMainActivity::class.java)
topLevel {
clickReaderOnBottomNav {
}
clickLibraryOnBottomNav {
assertGetZimNearbyDeviceDisplayed()
clickFileTransferIcon {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
ActivityScenario.launch(KiwixMainActivity::class.java)
topLevel {
clickReaderOnBottomNav {
}
clickLibraryOnBottomNav {
assertGetZimNearbyDeviceDisplayed()
clickFileTransferIcon {
}
}
clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed)
clickBookmarksOnNavDrawer {
assertBookMarksDisplayed()
clickOnTrashIcon()
assertDeleteBookmarksDialogDisplayed()
}
clickHistoryOnSideNav {
assertHistoryDisplayed()
clickOnTrashIcon()
assertDeleteHistoryDialogDisplayed()
}
clickHostBooksOnSideNav(ZimHostRobot::assertMenuWifiHotspotDiplayed)
clickSettingsOnSideNav(SettingsRobot::assertMenuSettingsDisplayed)
clickHelpOnSideNav(HelpRobot::assertToolbarDisplayed)
clickSupportKiwixOnSideNav()
assertExternalLinkDialogDisplayed()
pressBack()
}
clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed)
clickBookmarksOnNavDrawer {
assertBookMarksDisplayed()
clickOnTrashIcon()
assertDeleteBookmarksDialogDisplayed()
}
clickHistoryOnSideNav {
assertHistoryDisplayed()
clickOnTrashIcon()
assertDeleteHistoryDialogDisplayed()
}
clickHostBooksOnSideNav(ZimHostRobot::assertMenuWifiHotspotDiplayed)
clickSettingsOnSideNav(SettingsRobot::assertMenuSettingsDisplayed)
clickHelpOnSideNav(HelpRobot::assertToolbarDisplayed)
clickSupportKiwixOnSideNav()
assertExternalLinkDialogDisplayed()
pressBack()
}
}

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.note
import android.os.Build
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
@ -35,11 +36,13 @@ class NoteFragmentTest : BaseActivityTest() {
@Test
fun verifyNoteFragment() {
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.notesFragment) }
note {
assertToolbarExist()
assertNoteRecyclerViewExist()
assertSwitchWidgetExist()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.notesFragment) }
note {
assertToolbarExist()
assertNoteRecyclerViewExist()
assertSwitchWidgetExist()
}
}
}
}

View File

@ -17,6 +17,7 @@
*/
package org.kiwix.kiwixmobile.search
import android.os.Build
import androidx.core.content.edit
import androidx.core.net.toUri
import androidx.preference.PreferenceManager
@ -52,43 +53,45 @@ class SearchFragmentTest : BaseActivityTest() {
@Test
fun searchFragmentSimple() {
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.libraryFragment) }
val loadFileStream =
SearchFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
val zimFile = File(context.cacheDir, "testzim.zim")
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->
val outputStream: OutputStream = FileOutputStream(zimFile)
outputStream.use { it ->
val buffer = ByteArray(inputStream.available())
var length: Int
while (inputStream.read(buffer).also { length = it } > 0) {
it.write(buffer, 0, length)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.libraryFragment) }
val loadFileStream =
SearchFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
val zimFile = File(context.cacheDir, "testzim.zim")
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->
val outputStream: OutputStream = FileOutputStream(zimFile)
outputStream.use { it ->
val buffer = ByteArray(inputStream.available())
var length: Int
while (inputStream.read(buffer).also { length = it } > 0) {
it.write(buffer, 0, length)
}
}
}
}
UiThreadStatement.runOnUiThread {
activityRule.activity.navigate(
actionNavigationLibraryToNavigationReader()
.apply { zimFileUri = zimFile.toUri().toString() }
)
}
search { checkZimFileSearchSuccessful(R.id.readerFragment) }
UiThreadStatement.runOnUiThread {
if (zimFile.canRead()) {
activityRule.activity.openSearch(searchString = "Android")
} else {
throw RuntimeException(
"File $zimFile is not readable." +
" Original File $zimFile is readable = ${zimFile.canRead()}" +
" Size ${zimFile.length()}"
UiThreadStatement.runOnUiThread {
activityRule.activity.navigate(
actionNavigationLibraryToNavigationReader()
.apply { zimFileUri = zimFile.toUri().toString() }
)
}
}
search {
clickOnSearchItemInSearchList()
checkZimFileSearchSuccessful(R.id.readerFragment)
search { checkZimFileSearchSuccessful(R.id.readerFragment) }
UiThreadStatement.runOnUiThread {
if (zimFile.canRead()) {
activityRule.activity.openSearch(searchString = "Android")
} else {
throw RuntimeException(
"File $zimFile is not readable." +
" Original File $zimFile is readable = ${zimFile.canRead()}" +
" Size ${zimFile.length()}"
)
}
}
search {
clickOnSearchItemInSearchList()
checkZimFileSearchSuccessful(R.id.readerFragment)
}
}
}

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.settings
import android.Manifest
import android.os.Build
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
@ -47,38 +48,42 @@ class KiwixSettingsFragmentTest {
@Before
fun setup() {
// Go to IntroFragment
UiThreadStatement.runOnUiThread { activityTestRule.activity.navigate(R.id.introFragment) }
intro(IntroRobot::swipeLeft) clickGetStarted { }
StandardActions.openDrawer()
StandardActions.enterSettings()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
UiThreadStatement.runOnUiThread { activityTestRule.activity.navigate(R.id.introFragment) }
intro(IntroRobot::swipeLeft) clickGetStarted { }
StandardActions.openDrawer()
StandardActions.enterSettings()
}
}
@Test
fun testSettingsActivity() {
settingsRobo {
assertZoomTextViewPresent()
assertVersionTextViewPresent()
clickLanguagePreference()
assertLanguagePrefDialogDisplayed()
dismissDialog()
toggleBackToTopPref()
toggleOpenNewTabInBackground()
toggleExternalLinkWarningPref()
toggleWifiDownloadsOnlyPref()
clickStoragePreference()
// Let's pause here for a moment because calculating storage takes some time
BaristaSleepInteractions.sleep(TEST_PAUSE_MS.toLong())
assertStorageDialogDisplayed()
dismissDialog()
clickClearHistoryPreference()
assertHistoryDialogDisplayed()
dismissDialog()
clickNightModePreference()
assertNightModeDialogDisplayed()
dismissDialog()
clickCredits()
assertContributorsDialogDisplayed()
dismissDialog()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
settingsRobo {
assertZoomTextViewPresent()
assertVersionTextViewPresent()
clickLanguagePreference()
assertLanguagePrefDialogDisplayed()
dismissDialog()
toggleBackToTopPref()
toggleOpenNewTabInBackground()
toggleExternalLinkWarningPref()
toggleWifiDownloadsOnlyPref()
clickStoragePreference()
// Let's pause here for a moment because calculating storage takes some time
BaristaSleepInteractions.sleep(TEST_PAUSE_MS.toLong())
assertStorageDialogDisplayed()
dismissDialog()
clickClearHistoryPreference()
assertHistoryDialogDisplayed()
dismissDialog()
clickNightModePreference()
assertNightModeDialogDisplayed()
dismissDialog()
clickCredits()
assertContributorsDialogDisplayed()
dismissDialog()
}
}
}
}

View File

@ -19,6 +19,7 @@ package org.kiwix.kiwixmobile.splash
import android.Manifest
import android.content.Context
import android.os.Build
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso
@ -66,38 +67,42 @@ class KiwixSplashActivityTest {
@Test
fun testFirstRun() {
shouldShowIntro(true)
activityScenario.recreate()
activityScenario.onActivity {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
Espresso.onView(ViewMatchers.withId(R.id.get_started))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
shouldShowIntro(true)
activityScenario.recreate()
activityScenario.onActivity {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
Espresso.onView(ViewMatchers.withId(R.id.get_started))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
// Verify that the value of the "intro shown" boolean inside
// the SharedPreferences Database is not changed until
// the "Get started" button is pressed
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
Assert.assertEquals(
true,
preferences.getBoolean(
SharedPreferenceUtil.PREF_SHOW_INTRO,
true
// Verify that the value of the "intro shown" boolean inside
// the SharedPreferences Database is not changed until
// the "Get started" button is pressed
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
Assert.assertEquals(
true,
preferences.getBoolean(
SharedPreferenceUtil.PREF_SHOW_INTRO,
true
)
)
)
}
}
}
@Test
fun testNormalRun() {
shouldShowIntro(false)
activityScenario.recreate()
activityScenario.onActivity {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
Intents.intended(
IntentMatchers.hasComponent(
KiwixMainActivity::class.java.canonicalName
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
shouldShowIntro(false)
activityScenario.recreate()
activityScenario.onActivity {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
Intents.intended(
IntentMatchers.hasComponent(
KiwixMainActivity::class.java.canonicalName
)
)
)
}
}
}