File tree Expand file tree Collapse file tree
kautomator/src/main/kotlin/com/kaspersky/components/kautomator
component/common/builders
samples/kautomator-sample/kautomator-compiletime-r-sanity
androidTest/kotlin/com/kaspersky/kaspresso/kautomatorsample/compiletimertest
kotlin/com/kaspersky/kaspresso/kautomatorsample/compiletimertest Expand file tree Collapse file tree Load diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,8 +3,7 @@ package com.kaspersky.components.kautomator.common.resources
33import androidx.annotation.StringRes
44import androidx.test.platform.app.InstrumentationRegistry
55
6- internal object KString : ResourceNameProvider() {
7- override val rClassName = " R\$ string"
8-
9- fun getString (@StringRes resId : Int ): String = InstrumentationRegistry .getInstrumentation().targetContext.getString(resId)
10- }
6+ internal object KString {
7+ fun getString (@StringRes resId : Int ): String =
8+ InstrumentationRegistry .getInstrumentation().targetContext.getString(resId)
9+ }
Load diff This file was deleted.
Load diff This file was deleted.
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import androidx.annotation.StringRes
99import androidx.test.platform.app.InstrumentationRegistry
1010import androidx.test.uiautomator.BySelector
1111import androidx.test.uiautomator.BySelectorHack
12- import com.kaspersky.components.kautomator.common.resources.KId
1312import com.kaspersky.components.kautomator.common.resources.KString
1413import com.kaspersky.components.kautomator.component.common.KautomatorMarker
1514import java.util.regex.Pattern
@@ -50,8 +49,10 @@ class UiViewBuilder {
5049 * @param resourceId id to match
5150 */
5251 fun withId (@IdRes resourceId : Int ) {
53- val packageName = InstrumentationRegistry .getInstrumentation().targetContext.packageName
54- val resName = KId .resolveResName(packageName, resourceId)
52+ val fullName = InstrumentationRegistry .getInstrumentation()
53+ .targetContext.resources.getResourceName(resourceId)
54+ val packageName = fullName.substringBefore(" :" )
55+ val resName = fullName.substringAfterLast(" /" )
5556 return withResourceName(packageName, resName)
5657 }
5758
Original file line number Diff line number Diff line change 1+ plugins { id(" convention.android-app" ) }
2+
3+ android {
4+ namespace = " com.kaspersky.kaspresso.kautomatorsample.compiletimertest"
5+ defaultConfig {
6+ applicationId = " com.kaspersky.kaspresso.kautomatorsample.compiletimertest"
7+ testInstrumentationRunner = " androidx.test.runner.AndroidJUnitRunner"
8+ testInstrumentationRunnerArguments[" clearPackageData" ] = " true"
9+ }
10+ testOptions { execution = " ANDROIDX_TEST_ORCHESTRATOR" }
11+ }
12+
13+ dependencies {
14+ implementation(libs.appcompat)
15+ implementation(libs.material)
16+ implementation(libs.constraint)
17+ androidTestImplementation(projects.kaspresso)
18+ androidTestImplementation(libs.androidXTestExtJunitKtx)
19+ androidTestImplementation(libs.androidXTestExtJunit)
20+ androidTestUtil(libs.androidXTestOrchestrator)
21+ }
Original file line number Diff line number Diff line change 1+ android.enableAppCompileTimeRClass =true
Original file line number Diff line number Diff line change 1+ package com.kaspersky.kaspresso.kautomatorsample.compiletimertest.screen
2+
3+ import com.kaspersky.components.kautomator.component.edit.UiEditText
4+ import com.kaspersky.components.kautomator.component.text.UiButton
5+ import com.kaspersky.components.kautomator.component.text.UiTextView
6+ import com.kaspersky.components.kautomator.screen.UiScreen
7+ import com.kaspersky.kaspresso.kautomatorsample.compiletimertest.R
8+
9+ object MainScreen : UiScreen<MainScreen>() {
10+ override val packageName = " com.kaspersky.kaspresso.kautomatorsample.compiletimertest"
11+
12+ val editText = UiEditText { withId(R .id.editText) }
13+ val button = UiButton { withId(R .id.button) }
14+ val textView = UiTextView { withId(R .id.textView) }
15+ }
Original file line number Diff line number Diff line change 1+ package com.kaspersky.kaspresso.kautomatorsample.compiletimertest.test
2+
3+ import androidx.test.ext.junit.rules.activityScenarioRule
4+ import com.kaspersky.kaspresso.kautomatorsample.compiletimertest.MainActivity
5+ import com.kaspersky.kaspresso.kautomatorsample.compiletimertest.screen.MainScreen
6+ import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
7+ import org.junit.Rule
8+ import org.junit.Test
9+
10+ class WithIdSanityTest : TestCase () {
11+
12+ @get:Rule
13+ val activityRule = activityScenarioRule<MainActivity >()
14+
15+ @Test
16+ fun withIdResolvesResourcesCorrectly () = run {
17+ step(" Locate views by integer R.id references" ) {
18+ MainScreen {
19+ editText { isDisplayed() }
20+ button { isDisplayed() }
21+ textView { isDisplayed() }
22+ }
23+ }
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <manifest xmlns : android =" http://schemas.android.com/apk/res/android" >
3+
4+ <application
5+ android : allowBackup =" true"
6+ android : supportsRtl =" true"
7+ android : theme =" @style/Theme.AppCompat" >
8+
9+ <activity android : name =" .MainActivity"
10+ android : exported =" true" >
11+ <intent-filter >
12+ <action android : name =" android.intent.action.MAIN" />
13+ <category android : name =" android.intent.category.LAUNCHER" />
14+ </intent-filter >
15+ </activity >
16+
17+ </application >
18+
19+ </manifest >
You can’t perform that action at this time.
0 commit comments