Skip to content
Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package com.kaspersky.components.kautomator.common.resources
import androidx.annotation.StringRes
import androidx.test.platform.app.InstrumentationRegistry

internal object KString : ResourceNameProvider() {
override val rClassName = "R\$string"

fun getString(@StringRes resId: Int): String = InstrumentationRegistry.getInstrumentation().targetContext.getString(resId)
}
internal object KString {
fun getString(@StringRes resId: Int): String =
InstrumentationRegistry.getInstrumentation().targetContext.getString(resId)
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.annotation.StringRes
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.BySelector
import androidx.test.uiautomator.BySelectorHack
import com.kaspersky.components.kautomator.common.resources.KId
import com.kaspersky.components.kautomator.common.resources.KString
import com.kaspersky.components.kautomator.component.common.KautomatorMarker
import java.util.regex.Pattern
Expand Down Expand Up @@ -50,8 +49,10 @@ class UiViewBuilder {
* @param resourceId id to match
*/
fun withId(@IdRes resourceId: Int) {
val packageName = InstrumentationRegistry.getInstrumentation().targetContext.packageName
val resName = KId.resolveResName(packageName, resourceId)
val fullName = InstrumentationRegistry.getInstrumentation()
.targetContext.resources.getResourceName(resourceId)
val packageName = fullName.substringBefore(":")
val resName = fullName.substringAfterLast("/")
return withResourceName(packageName, resName)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins { id("convention.android-app") }

android {
namespace = "com.kaspersky.kaspresso.kautomatorsample.compiletimertest"
defaultConfig {
applicationId = "com.kaspersky.kaspresso.kautomatorsample.compiletimertest"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}
testOptions { execution = "ANDROIDX_TEST_ORCHESTRATOR" }
}

dependencies {
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.constraint)
androidTestImplementation(projects.kaspresso)
androidTestImplementation(libs.androidXTestExtJunitKtx)
androidTestImplementation(libs.androidXTestExtJunit)
androidTestUtil(libs.androidXTestOrchestrator)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android.enableAppCompileTimeRClass=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kaspersky.kaspresso.kautomatorsample.compiletimertest.screen

import com.kaspersky.components.kautomator.component.edit.UiEditText
import com.kaspersky.components.kautomator.component.text.UiButton
import com.kaspersky.components.kautomator.component.text.UiTextView
import com.kaspersky.components.kautomator.screen.UiScreen
import com.kaspersky.kaspresso.kautomatorsample.compiletimertest.R

object MainScreen : UiScreen<MainScreen>() {
override val packageName = "com.kaspersky.kaspresso.kautomatorsample.compiletimertest"

val editText = UiEditText { withId(R.id.editText) }
val button = UiButton { withId(R.id.button) }
val textView = UiTextView { withId(R.id.textView) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.kaspersky.kaspresso.kautomatorsample.compiletimertest.test

import androidx.test.ext.junit.rules.activityScenarioRule
import com.kaspersky.kaspresso.kautomatorsample.compiletimertest.MainActivity
import com.kaspersky.kaspresso.kautomatorsample.compiletimertest.screen.MainScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Rule
import org.junit.Test

class WithIdSanityTest : TestCase() {

@get:Rule
val activityRule = activityScenarioRule<MainActivity>()

@Test
fun withIdResolvesResourcesCorrectly() = run {
step("Locate views by integer R.id references") {
MainScreen {
editText { isDisplayed() }
button { isDisplayed() }
textView { isDisplayed() }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat">

<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.kaspersky.kaspresso.kautomatorsample.compiletimertest

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editText" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/button" />

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ include(
":samples:adbserver-sample",
":samples:kaspresso-sample",
":samples:kautomator-sample",
":samples:kautomator-sample:kautomator-compiletime-r-sanity",
":samples:kautomator-sample-app-upgrade",
":samples:kaspresso-allure-support-sample",
":samples:kaspresso-compose-support-sample",
Expand Down
Loading