Skip to content
Open
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
61 changes: 61 additions & 0 deletions app/src/androidTest/kotlin/info/appdev/chartexample/StartTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.GeneralClickAction
import androidx.test.espresso.action.Press
import androidx.test.espresso.action.Tap
import androidx.test.espresso.action.ViewActions.captureToBitmap
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import info.appdev.chartexample.fragments.ViewPagerSimpleChartDemo
import info.appdev.chartexample.notimportant.ContentItem
import info.appdev.chartexample.notimportant.DemoBase
import info.appdev.chartexample.notimportant.DemoBase.Companion.optionMenus
import info.appdev.chartexample.notimportant.DemoBaseCompose
Expand Down Expand Up @@ -64,12 +71,17 @@ class StartTest {
onView(ViewMatchers.isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })

var compose: Boolean
var optionMenu = ""
// iterate samples - only items with classes (not section headers)
MainActivity.menuItems.forEachIndexed { index, contentItem ->
contentItem.clazz?.let { contentClass ->
compose = false
Timber.d("Intended ${index}-${contentClass.simpleName}: ${contentItem.name}")

if (contentItem.clazz == ViewPagerSimpleChartDemo::class.java || contentItem.clazz == ListViewBarChartActivity::class.java)
return@forEachIndexed

try {
// Use description to uniquely identify items since names can be duplicated
// If description exists, use it; otherwise fall back to name
Expand Down Expand Up @@ -124,6 +136,7 @@ class StartTest {
)
}
} else if (DemoBaseCompose::class.java.isAssignableFrom(contentClass)) {
compose = true
// Test Compose dropdown menu for DemoBaseCompose activities
Timber.d("Testing Compose menu for: ${contentClass.simpleName}")
optionMenu = ""
Expand Down Expand Up @@ -206,6 +219,9 @@ class StartTest {
Timber.d("Unknown activity type: ${contentClass.simpleName}")
}

if (!compose)
doClickTest(index, contentClass, contentItem)

//Thread.sleep(100)
Espresso.pressBack()

Expand All @@ -226,6 +242,35 @@ class StartTest {
}
}

private fun doClickTest(index: Int, contentClass: Class<out DemoBase>, contentItem: ContentItem<out DemoBase>) {
onView(withId(R.id.chart1)).perform(click())
onView(ViewMatchers.isRoot())
.perform(captureToBitmap { bitmap: Bitmap ->
bitmap.writeToTestStorage(
"${javaClass.simpleName}_${nameRule.methodName}-${index}-${contentClass.simpleName}-${contentItem.name}-click"
.replace(" ", "")
)
})

onView(withId(R.id.chart1)).perform(clickXY(20, 20))
onView(ViewMatchers.isRoot())
.perform(captureToBitmap { bitmap: Bitmap ->
bitmap.writeToTestStorage(
"${javaClass.simpleName}_${nameRule.methodName}-${index}-${contentClass.simpleName}-${contentItem.name}-click2020"
.replace(" ", "")
)
})

onView(withId(R.id.chart1)).perform(clickXY(70, 70))
onView(ViewMatchers.isRoot())
.perform(captureToBitmap { bitmap: Bitmap ->
bitmap.writeToTestStorage(
"${javaClass.simpleName}_${nameRule.methodName}-${index}-${contentClass.simpleName}-${contentItem.name}-click7070"
.replace(" ", "")
)
})
}

private fun screenshotOfOptionMenu(simpleName: String, menuTitle: String) {
onView(withText(menuTitle)).perform(click())
Timber.d("screenshotOfOptionMenu ${menuTitle}-${simpleName}")
Expand All @@ -236,4 +281,20 @@ class StartTest {
)
}

fun clickXY(x: Int, y: Int): ViewAction {
return GeneralClickAction(
Tap.SINGLE,
{ view ->
val location = IntArray(2)
view!!.getLocationOnScreen(location)
val screenX = (location[0] + x).toFloat()
val screenY = (location[1] + y).toFloat()
floatArrayOf(screenX, screenY)
},
Press.FINGER,
0, // inputDevice
0 // deviceState
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ class ListViewMultiChartActivity : DemoBase() {
/** adapter that supports 3 different item types */
private class ChartDataAdapter(context: Context, chartItems: MutableList<ChartItem?>) : ArrayAdapter<ChartItem>(context, 0, chartItems) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
return getItem(position)!!.getView(position, convertView, context)!!
return getItem(position)!!.getView(position, convertView, context)!!.apply {
// to find chart in Espresso test
when (position) {
0 -> id = R.id.chart1
1 -> id = R.id.chart2
2 -> id = R.id.chart3
}
}
}

override fun getItemViewType(position: Int): Int {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading