Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/722 automatic screen captures for Play Store #803

Draft
wants to merge 5 commits into
base: current-stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ dependencies {
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'

androidTestImplementation 'tools.fastlane:screengrab:2.0.0'
}

repositories {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2020 Martin Denham, Tuomas Airaksinen and the And Bible contributors.
*
* This file is part of And Bible (http://github.com/AndBible/and-bible).
*
* And Bible is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* And Bible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with And Bible.
* If not, see http://www.gnu.org/licenses/.
*
*/

package net.bible.android.activity

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers.withId
import org.junit.runner.RunWith
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

import net.bible.android.view.activity.page.MainBibleActivity
import net.bible.android.view.activity.page.MainBibleActivity.Companion.mainBibleActivity
import org.crosswire.jsword.passage.VerseFactory
import org.crosswire.jsword.versification.system.Versifications
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import tools.fastlane.screengrab.Screengrab
import tools.fastlane.screengrab.cleanstatusbar.CleanStatusBar
import tools.fastlane.screengrab.locale.LocaleTestRule
import java.util.*

/*
HOWTO:
- run tests by command `fastlane screengrab`

TODO:
- We need to have zip of modules in each Play Store language
- We need to have db with certain bookmarks, notes and workspaces
- We we might need to have certain settings (those can be set runtime too)
- In each locale, we need to automatically choose the local bible module, or the first local bible module

Screenshots must be captured on emulator that DOES NOT have Google Play additions in it (must allow root).

*/

@RunWith(AndroidJUnit4::class)
@LargeTest
class MainBibleActivityTests {
@get:Rule var activityRule = ActivityTestRule(MainBibleActivity::class.java)
@get:Rule var localeTestRule = LocaleTestRule()

@Test
fun testMainActivity() {
val doc = mainBibleActivity.swordDocumentFacade.bibles.find { it.language.code == Locale.getDefault().language }

mainBibleActivity.documentControl.currentPage.setCurrentDocumentAndKey(doc,
VerseFactory.fromString(Versifications.instance().getVersification("KJV"), "John.3.16"))

Thread.sleep(1000)
Screengrab.screenshot("main_bible_view")
}

companion object {
@BeforeClass @JvmStatic
fun beforeAll() {
CleanStatusBar.enableWithDefaults()
}

@AfterClass @JvmStatic
fun afterAll() {
CleanStatusBar.disable()
}
}
}
19 changes: 18 additions & 1 deletion app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@
xmlns:tools="http://schemas.android.com/tools"
package="net.bible.android.activity">

<!-- begin screengrab -->

<!-- Allows unlocking your device and activating its screen so UI tests can succeed -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<!-- Allows for storing and retrieving screenshots -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- Allows changing locales -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" tools:ignore="ProtectedPermissions" />
<!-- Indicates the use of the clean status bar feature -->
<uses-feature android:name="tools.fastlane.screengrab.cleanstatusbar"/>
<!-- Allows for changing the status bar -->
<uses-permission android:name="android.permission.DUMP" tools:ignore="ProtectedPermissions" />
<!-- end screengrab -->

<application
android:name="net.bible.android.DebugApp"
tools:replace="android:name" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ class MainBibleActivity : CustomTitlebarActivityBase(), VerseActionModeMediator.
/**
* allow current page to save any settings or data before being changed
*/
fun onEvent(event: PreBeforeCurrentPageChangeEvent) {
fun onEventMainThread(event: PreBeforeCurrentPageChangeEvent) {
val currentPage = windowControl.activeWindowPageManager.currentPage
// save current scroll position so history can return to correct place in document
currentPage.currentYOffsetRatio = currentPosition
Expand Down
17 changes: 17 additions & 0 deletions fastlane/Screengrabfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# remove the leading '#' to uncomment lines

app_package_name('net.bible.android.activity.debug')
use_tests_in_packages(['net.bible.android.activity'])

app_apk_path('app/build/outputs/apk/debug/app-debug.apk')
tests_apk_path('app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk')

use_adb_root(true)

locales(['en-US', 'fr-FR', 'fi-FI'])

# clear all previously generated screenshots in your local output directory before creating new ones
clear_previous_screenshots(true)

# For more information about all available options run
# fastlane screengrab --help