Initial commit

Umnik 11 months ago
commit ffd673c739

210
.gitignore vendored

@ -0,0 +1,210 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Android template
# Built application files
*.apk
*.aar
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
# Generated files
bin/
gen/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
# Proguard folder generated by Eclipse
proguard/
# Log Files
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
# External native build folder generated in Android Studio 2.2 and later
.cxx/
# Google Services (e.g. APIs or Firebase)
# google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
# Version control
vcs.xml
# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
# Android Profiling
*.hprof
### Kotlin template
# Compiled class file
# Log file
# BlueJ files
# Mobile Tools for Java (J2ME)
# Package Files #
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml

3
.idea/.gitignore vendored

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

1
app/.gitignore vendored

@ -0,0 +1 @@
/build

@ -0,0 +1,46 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
minSdk 25
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-native-mt'
implementation 'junit:junit:4.13.2'
implementation 'androidx.test.ext:junit:1.1.3'
implementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="xyz.myachin.yaw">
<application />
</manifest>

@ -0,0 +1,5 @@
package xyz.myachin.yaw.core
internal const val SHORT_WAIT = 3_000L
internal const val EXTENDED_WAIT = SHORT_WAIT * 3
internal const val LONG_WAIT = EXTENDED_WAIT * 3

@ -0,0 +1,41 @@
package xyz.myachin.yaw.core.device
import android.os.SystemClock
import android.view.KeyEvent
import xyz.myachin.yaw.core.exceptions.TAssert
import xyz.myachin.yaw.core.os.components.TOsComponents.tDevice
import kotlin.concurrent.thread
/** Working with DEVICE but not OS or apps */
object TDevice {
/** Take screenshot with user way: press buttons Volume- and Power in same time */
fun takeScreenshotAsUser(password: String?) {
/*
я не понимаю почему, но если создать визуальное событие, то скриншот снимается нормально
Потому сначала дёргается звук, потом снимается скриншот
Если звук не дёргать, то иногда будет просто гаснуть экран
Также если дёрнуть звук и затем нажать "Назад", чтобы регулятор громкости исчез, то снова будет гаснуть экран
*/
pressKeyCode(KeyEvent.KEYCODE_VOLUME_DOWN)
val t = thread { pressKeyCode(KeyEvent.KEYCODE_POWER) }
pressKeyCode(KeyEvent.KEYCODE_VOLUME_DOWN)
t.join()
SystemClock.sleep(2_000)
pressDeviceBackButton()
}
/** Press [keycode]. [strict] means assertion if action was failed */
private fun pressKeyCode(keycode: Int, strict: Boolean = true) {
TAssert.assertState(tDevice.pressKeyCode(keycode), strict, "Cannot press key $keycode")
}
/** Press Back button. [strict] means assertion if action was failed */
private fun pressDeviceBackButton(strict: Boolean = true) {
TAssert.assertState(tDevice.pressBack(), strict, "Cannot tap device's back button")
}
}

@ -0,0 +1,38 @@
package xyz.myachin.yaw.core.exceptions
open class TException(message: String) : Exception(message)
class LaunchActivityNotExistsError(pkgName: String) :
TException("Package $pkgName has not own launch activity")
class ObjectStateError(e: String) : TException(e)
class ObjectActionError(e: String) : TException(e)
class UnexpectedClassError(expected: String, actual: String) :
TException("Expected class expected but got $actual")
object TAssert {
/**
* If [strict] is false always returns [stateResult] value.
* If [strict] is true returns [stateResult] value when it is true and throws [ObjectStateError] when [stateResult] value is false.
* [text] adds to [AssertionError] message when [ObjectStateError] throws
*/
internal fun assertState(stateResult: Boolean, strict: Boolean, text: String): Boolean {
try {
assert(stateResult)
} catch (e: AssertionError) {
if (strict) throw ObjectStateError("${text}\n${e.message}")
}
return stateResult
}
internal fun assertAction(actionResult: Boolean, strict: Boolean, text: String): Boolean {
try {
assert(actionResult)
} catch (e: AssertionError) {
if (strict) throw ObjectActionError("${text}\n${e.message}")
}
return actionResult
}
}

@ -0,0 +1,14 @@
package xyz.myachin.yaw.core.os.components
import android.content.Context
import android.content.pm.PackageManager
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
object TOsComponents {
private val tInstrumentation = InstrumentationRegistry.getInstrumentation()
internal val tDevice: UiDevice = UiDevice.getInstance(tInstrumentation)
internal val tContext: Context get() = tInstrumentation.targetContext
internal val tPackageManager: PackageManager get() = tContext.packageManager
}

@ -0,0 +1,72 @@
package xyz.myachin.yaw.core.os.intent
import android.content.ComponentName
import android.content.Intent
import android.net.Uri
import androidx.core.content.IntentCompat
/** Builder for [Intent] */
class IntentBuilder {
private lateinit var _intent: Intent
/** Creates new empty Intent */
constructor() {
_intent = Intent()
}
/** Creates new intent based on your [intent] */
constructor(intent: Intent) {
_intent = intent
}
/** Returns [Intent] */
fun build() = _intent
/** Add/replace intent's action */
fun action(action: String): IntentBuilder {
_intent.action = action
return this
}
/** Add/replace intent's extra with [String] value */
fun putExtra(key: String, value: String): IntentBuilder {
_intent.putExtra(key, value)
return this
}
/** Add/replace intent's extra with [Boolean] value */
fun putExtra(key: String, value: Boolean): IntentBuilder {
_intent.putExtra(key, value)
return this
}
/** Add/replace intent's extra with [Int] value */
fun putExtraInt(key: String, value: Int): IntentBuilder {
_intent.putExtra(key, value)
return this
}
/** Add/replace intent's extra with [Long] value */
fun putExtra(key: String, value: Long): IntentBuilder {
_intent.putExtra(key, value)
return this
}
/** Add/replace intent's [component] */
fun component(component: ComponentName): IntentBuilder {
_intent.component = component
return this
}
/** Add/replace intent's [android.content.ComponentName] what creates from [pkgName] and [activityName] */
fun component(pkgName: String, activityName: String): IntentBuilder {
_intent.component = ComponentName.createRelative(pkgName, activityName)
return this
}
/** Add/replace intent's data */
fun data(data: Uri): IntentBuilder {
_intent.data = data
return this
}
}

@ -0,0 +1,50 @@
package xyz.myachin.yaw.core.os.ui.actions
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import xyz.myachin.yaw.core.exceptions.TException
import xyz.myachin.yaw.core.os.components.TOsComponents.tContext
import xyz.myachin.yaw.core.os.components.TOsComponents.tPackageManager
import xyz.myachin.yaw.core.os.ui.utils.TOsUtil
object TOsUiAction {
private const val defaultFlags = Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TASK or
Intent.FLAG_ACTIVITY_NO_HISTORY or
Intent.FLAG_ACTIVITY_NO_ANIMATION
/** Makes, but not shows (see [showToast]) toast */
private fun prepareToast(text: Int, time: Int = Toast.LENGTH_SHORT): Toast {
return Toast.makeText(tContext, TOsUtil.getText(text), time)
}
/** Shows toast in current thread. Use [showToastInMainThread] in case non-main thread */
fun showToast(text: Int, time: Int = Toast.LENGTH_SHORT) {
prepareToast(text, time).show()
}
/** Shows toast in main thread from [suspend] functions.
* Use [showToast] if you already in main thread */
suspend fun showToastInMainThread(text: Int, time: Int = Toast.LENGTH_SHORT) {
withContext(Dispatchers.Main) { showToast(text, time) }
}
/** Calls app's launch activity */
@Throws(TException.LaunchActivityNotExists::class)
fun startLaunchActivityAsUser(pkgName: String) {
tPackageManager.getLaunchIntentForPackage(pkgName)?.run {
addFlags(defaultFlags)
tContext.startActivity(this)
return
}
throw TException.LaunchActivityNotExists(pkgName)
}
/** Same as [android.content.Context.startActivity] */
fun startActivity(intent: Intent, bundle: Bundle?) {
tContext.startActivity(intent, bundle)
}
}

@ -0,0 +1,14 @@
package xyz.myachin.yaw.core.os.ui.utils
import xyz.myachin.yaw.core.os.components.TOsComponents.tContext
object TOsUtil {
/** Extracts string resource by [resId]. Example: `R.string.some_string` */
fun getText(resId: Int): String {
return tContext.getString(resId)
}
fun getText(resId: Int, vararg format: Any): String {
return tContext.getString(resId, format)
}
}

@ -0,0 +1,48 @@
package xyz.myachin.yaw.core.wait
import android.os.SystemClock
object TWait {
private fun end(timeout: Long): Long {
return SystemClock.elapsedRealtime() + timeout
}
fun waitForBool(
func: () -> Boolean,
expectation: Boolean,
timeout: Long
): Boolean {
val end = end(timeout)
while (SystemClock.elapsedRealtime() <= end) {
if (func() == expectation) return true
}
return false
}
fun waitForText(
func: (String, Boolean) -> Boolean,
text: String,
case: Boolean,
expectation: Boolean,
timeout: Long
): Boolean {
val end = end(timeout)
while (SystemClock.elapsedRealtime() <= end) {
if (func(text, case) == expectation) return true
}
return false
}
fun waitForText(
func: (Regex) -> Boolean,
regex: Regex,
expectation: Boolean,
timeout: Long
): Boolean {
val end = end(timeout)
while (SystemClock.elapsedRealtime() <= end) {
if (func(regex) == expectation) return true
}
return false
}
}

@ -0,0 +1,11 @@
package xyz.myachin.yaw.ui.highlevel
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.ui.lowlevel.actions.impls.TClickableImpl
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIClickable
import xyz.myachin.yaw.ui.lowlevel.checker.impls.TViewHasTextImpl
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewHasText
class TButtonGeneric(private val uiSelector: UiSelector) :
TIClickable by TClickableImpl(uiSelector),
TIViewHasText by TViewHasTextImpl(uiSelector)

@ -0,0 +1,11 @@
package xyz.myachin.yaw.ui.highlevel
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.ui.lowlevel.actions.impls.TClickableImpl
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIClickable
import xyz.myachin.yaw.ui.lowlevel.checker.impls.TViewHasCheckboxImpl
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewHasCheckbox
class TCheckboxGeneric(private val uiSelector: UiSelector) :
TIViewHasCheckbox by TViewHasCheckboxImpl(uiSelector),
TIClickable by TClickableImpl(uiSelector)

@ -0,0 +1,14 @@
package xyz.myachin.yaw.ui.highlevel
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.ui.lowlevel.actions.impls.TReadableImpl
import xyz.myachin.yaw.ui.lowlevel.actions.impls.TWriteableImpl
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIReadable
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIWriteable
import xyz.myachin.yaw.ui.lowlevel.checker.impls.TViewHasTextImpl
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewHasText
class TEditTextGeneric(private val uiSelector: UiSelector) :
TIViewHasText by TViewHasTextImpl(uiSelector),
TIReadable by TReadableImpl(uiSelector),
TIWriteable by TWriteableImpl(uiSelector)

@ -0,0 +1,11 @@
package xyz.myachin.yaw.ui.highlevel
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.ui.lowlevel.actions.impls.TReadableImpl
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIReadable
import xyz.myachin.yaw.ui.lowlevel.checker.impls.TViewHasTextImpl
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewHasText
class TTextGeneric(private val uiSelector: UiSelector) :
TIViewHasText by TViewHasTextImpl(uiSelector),
TIReadable by TReadableImpl(uiSelector)

@ -0,0 +1,11 @@
package xyz.myachin.yaw.ui.highlevel
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.ui.lowlevel.actions.impls.TClickableImpl
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIClickable
import xyz.myachin.yaw.ui.lowlevel.checker.impls.TViewHasCheckboxImpl
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewHasCheckbox
class TToggleButtonGeneric(private val uiSelector: UiSelector) :
TIViewHasCheckbox by TViewHasCheckboxImpl(uiSelector),
TIClickable by TClickableImpl(uiSelector)

@ -0,0 +1,41 @@
package xyz.myachin.yaw.ui.lowlevel.actions.impls
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.core.EXTENDED_WAIT
import xyz.myachin.yaw.core.exceptions.ObjectActionError
import xyz.myachin.yaw.core.exceptions.TAssert
import xyz.myachin.yaw.core.os.components.TOsComponents.tDevice
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIClickable
class TClickableImpl(private val uiSelector: UiSelector) : TIClickable {
private val uiObject: UiObject get() = tDevice.findObject(uiSelector)
@Throws(ObjectActionError::class)
override fun wantTap(assertIfFalse: Boolean): Boolean {
return TAssert.assertAction(
uiObject.click(),
assertIfFalse,
"Tap on '$uiObject (${uiObject.className})' failed"
)
}
@Throws(ObjectActionError::class)
override fun wantLongTap(assertIfFalse: Boolean): Boolean {
return TAssert.assertAction(
uiObject.longClick(),
assertIfFalse,
"Long tap on '$uiObject (${uiObject.className})' failed"
)
}
@Throws(ObjectActionError::class)
override fun wantTapForNewTransition(assertIfFalse: Boolean, timeout: Long): Boolean {
return TAssert.assertAction(
uiObject.clickAndWaitForNewWindow(timeout),
assertIfFalse,
"Tap on '$uiObject (${uiObject.className})' failed." +
" No new screen has appeared"
)
}
}

@ -0,0 +1,14 @@
package xyz.myachin.yaw.ui.lowlevel.actions.impls
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.core.os.components.TOsComponents.tDevice
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIReadable
class TReadableImpl(private val uiSelector: UiSelector) : TIReadable {
private val uiObject: UiObject get() = tDevice.findObject(uiSelector)
override fun extractString(): String {
return uiObject.text
}
}

@ -0,0 +1,23 @@
package xyz.myachin.yaw.ui.lowlevel.actions.impls
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.core.exceptions.TAssert
import xyz.myachin.yaw.core.os.components.TOsComponents.tDevice
import xyz.myachin.yaw.ui.lowlevel.actions.interfaces.TIWriteable
class TWriteableImpl(private val uiSelector: UiSelector) : TIWriteable {
private val uiObject: UiObject get() = tDevice.findObject(uiSelector)
override fun wantSetText(text: String, assertIfFalse: Boolean): Boolean {
return TAssert.assertAction(
uiObject.setText(text),
assertIfFalse,
"Failed to set text \"$text\" for $uiObject (${uiObject.className})"
)
}
override fun wantClearText() {
uiObject.clearTextField()
}
}

@ -0,0 +1,12 @@
package xyz.myachin.yaw.ui.lowlevel.actions.interfaces
import xyz.myachin.yaw.core.EXTENDED_WAIT
interface TIClickable {
fun wantTap(assertIfFalse: Boolean = true): Boolean
fun wantLongTap(assertIfFalse: Boolean = true): Boolean
fun wantTapForNewTransition(
assertIfFalse: Boolean = true,
timeout: Long = EXTENDED_WAIT
): Boolean
}

@ -0,0 +1,5 @@
package xyz.myachin.yaw.ui.lowlevel.actions.interfaces
interface TIReadable {
fun extractString(): String
}

@ -0,0 +1,6 @@
package xyz.myachin.yaw.ui.lowlevel.actions.interfaces
interface TIWriteable {
fun wantSetText(text: String, assertIfFalse: Boolean = true): Boolean
fun wantClearText()
}

@ -0,0 +1,89 @@
package xyz.myachin.yaw.ui.lowlevel.checker.impls
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.core.exceptions.ObjectStateError
import xyz.myachin.yaw.core.exceptions.TAssert
import xyz.myachin.yaw.core.exceptions.UnexpectedClassError
import xyz.myachin.yaw.core.os.components.TOsComponents.tDevice
import xyz.myachin.yaw.core.wait.TWait
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewGeneric
class TViewGenericImpl(private val uiSelector: UiSelector) : TIViewGeneric {
private val uiObject: UiObject get() = tDevice.findObject(uiSelector)
/**
* Returns object is exists or not when [assertIfFalse] is `false`.
* Returns `true` when object is exists or throws [ObjectStateError] when both [assertIfFalse] is `true` and object not exists.
* Wait up to [timeout] ms
*/
@Throws(ObjectStateError::class)
override fun wantExists(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
uiObject.waitForExists(timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) not exists after $timeout ms"
)
}
/**
* Returns object is not exists or exists when [assertIfFalse] is `false`.
* Returns `true` when object is not exists or throws [ObjectStateError] when both [assertIfFalse] is `true` and object exists.
* Wait up to [timeout] ms
*/
@Throws(ObjectStateError::class)
override fun wantNotExists(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
TWait.waitForBool(uiObject::exists, false, timeout),
assertIfFalse, "$uiObject (${uiObject.className}) exists after $timeout ms"
)
}
/**
* Returns object is gone or not when [assertIfFalse] is `false`.
* Returns `true` when object is gone or throws [ObjectStateError] when both [assertIfFalse] is `true` and object not gone.
* Wait up to [timeout] ms
*/
@Throws(ObjectStateError::class)
override fun wantGone(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
uiObject.waitUntilGone(timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) does not gone after $timeout ms"
)
}
/**
* Returns object is enabled or not when [assertIfFalse] is `false`.
* Returns `true` when object is enabled or throws [ObjectStateError] when both [assertIfFalse] is `true` and object is disabled.
* Wait up to [timeout] ms
*/
@Throws(ObjectStateError::class)
override fun wantEnabled(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
TWait.waitForBool(uiObject::isEnabled, true, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) disabled after $timeout ms"
)
}
/**
* Returns object is enabled or not when [assertIfFalse] is `false`.
* Returns `true` when object is disabled or throws [ObjectStateError] when both [assertIfFalse] is `true` and object is enabled.
* Wait up to [timeout] ms
*/
@Throws(ObjectStateError::class)
override fun wantDisabled(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
TWait.waitForBool(uiObject::isEnabled, false, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) enabled after $timeout ms"
)
}
/** Assertion for object's class name */
@Throws(UnexpectedClassError::class)
override fun checkClassIs(clazz: String) {
if (uiObject.className != clazz) throw UnexpectedClassError(clazz, uiObject.className)
}
}

@ -0,0 +1,45 @@
package xyz.myachin.yaw.ui.lowlevel.checker.impls
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.core.exceptions.ObjectStateError
import xyz.myachin.yaw.core.exceptions.TAssert
import xyz.myachin.yaw.core.os.components.TOsComponents.tDevice
import xyz.myachin.yaw.core.wait.TWait
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewGeneric
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewHasCheckbox
class TViewHasCheckboxImpl(private val uiSelector: UiSelector) : TIViewHasCheckbox,
TIViewGeneric by TViewGenericImpl(uiSelector) {
private val uiObject: UiObject get() = tDevice.findObject(uiSelector)
/**
* Returns object is checkable or not when [assertIfFalse] is `false`.
* Returns `true` when object is checkable or throws [ObjectStateError] when both [assertIfFalse] is `true` and object is not checkable.
* Wait up to [timeout] ms
*/
@Throws(ObjectStateError::class)
override fun wantCheckable(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
TWait.waitForBool(uiObject::isCheckable, true, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) not checkable after $timeout ms"
)
}
override fun wantChecked(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
TWait.waitForBool(uiObject::isChecked, true, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) not checked after $timeout ms"
)
}
override fun wantUnchecked(timeout: Long, assertIfFalse: Boolean): Boolean {
return TAssert.assertState(
TWait.waitForBool(uiObject::isChecked, false, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) checked after $timeout ms"
)
}
}

@ -0,0 +1,59 @@
package xyz.myachin.yaw.ui.lowlevel.checker.impls
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector
import xyz.myachin.yaw.core.exceptions.ObjectStateError
import xyz.myachin.yaw.core.exceptions.TAssert
import xyz.myachin.yaw.core.os.components.TOsComponents.tDevice
import xyz.myachin.yaw.core.wait.TWait
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewGeneric
import xyz.myachin.yaw.ui.lowlevel.checker.interfaces.TIViewHasText
class TViewHasTextImpl(private val uiSelector: UiSelector) : TIViewHasText,
TIViewGeneric by TViewGenericImpl(uiSelector) {
private val uiObject: UiObject get() = tDevice.findObject(uiSelector)
@Throws(ObjectStateError::class)
override fun wantTextIs(
text: String,
caseSensitive: Boolean,
timeout: Long,
assertIfFalse: Boolean
): Boolean {
return TAssert.assertState(
TWait.waitForText(uiObject.text::equals, text, caseSensitive, true, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) has not text \"$text\"." +
" Found: \"${uiObject.text}\""
)
}
@Throws(ObjectStateError::class)
override fun wantTextContains(
text: String,
caseSensitive: Boolean,
timeout: Long,
assertIfFalse: Boolean
): Boolean {
return TAssert.assertState(
TWait.waitForText(uiObject.text::contains, text, caseSensitive, true, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) has not text \"$text\"." +
" Found: \"${uiObject.text}\""
)
}
@Throws(ObjectStateError::class)
override fun checkTextLike(
regex: Regex,
timeout: Long,
assertIfFalse: Boolean
): Boolean {
return TAssert.assertState(
TWait.waitForText(uiObject.text::contains, regex, true, timeout),
assertIfFalse,
"$uiObject (${uiObject.className}) has not matched with regex \"${regex.pattern} (${regex.options})\"." +
" Found: \"${uiObject.text}\""
)
}
}

@ -0,0 +1,12 @@
package xyz.myachin.yaw.ui.lowlevel.checker.interfaces
import xyz.myachin.yaw.core.SHORT_WAIT
interface TIViewGeneric {
fun wantExists(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
fun wantNotExists(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
fun wantGone(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
fun wantEnabled(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
fun wantDisabled(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
fun checkClassIs(clazz: String)
}

@ -0,0 +1,9 @@
package xyz.myachin.yaw.ui.lowlevel.checker.interfaces
import xyz.myachin.yaw.core.SHORT_WAIT
interface TIViewHasCheckbox {
fun wantCheckable(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
fun wantChecked(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
fun wantUnchecked(timeout: Long = SHORT_WAIT, assertIfFalse: Boolean = true): Boolean
}

@ -0,0 +1,25 @@
package xyz.myachin.yaw.ui.lowlevel.checker.interfaces
import xyz.myachin.yaw.core.SHORT_WAIT
interface TIViewHasText {
fun wantTextIs(
text: String,
caseSensitive: Boolean,
timeout: Long = SHORT_WAIT,
assertIfFalse: Boolean = true
): Boolean
fun wantTextContains(
text: String,
caseSensitive: Boolean,
timeout: Long = SHORT_WAIT,
assertIfFalse: Boolean = true
): Boolean
fun checkTextLike(
regex: Regex,
timeout: Long = SHORT_WAIT,
assertIfFalse: Boolean = true
): Boolean
}

@ -0,0 +1,3 @@
<resources>
<string name="app_name">YAW</string>
</resources>

@ -0,0 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

@ -0,0 +1,21 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

@ -0,0 +1,6 @@
#Tue Nov 23 19:43:35 MSK 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

185
gradlew vendored

@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

89
gradlew.bat vendored

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

@ -0,0 +1,10 @@
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "YAW"
include ':app'
Loading…
Cancel
Save