Skip to content

Instantly share code, notes, and snippets.

@BramYeh
Created July 12, 2020 06:52
Show Gist options
  • Save BramYeh/8720463800116e770287a1c3d1b9b604 to your computer and use it in GitHub Desktop.
Save BramYeh/8720463800116e770287a1c3d1b9b604 to your computer and use it in GitHub Desktop.
Basic Page Class
import android.os.SystemClock
import androidx.test.espresso.Espresso
open class Page {
inline fun <reified T : Page> on(): T {
// reference: https://blog.kotlin-academy.com/creating-a-random-instance-of-any-class-in-kotlin-b6168655b64a
val page = T::class.constructors.first().call()
page.verify()
return page
}
open fun verify(): Page {
assert(false)
return this
}
fun back(): Page {
Espresso.pressBack()
return this
}
fun wait(milliseconds: Long): Page {
SystemClock.sleep(milliseconds)
return this
}
companion object {
inline fun <reified T : Page> on(): T {
return Page().on()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment