Skip to content

Create shared UIElement finders #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4b64076
Create ui testing assertion module
corrado4eyes Sep 20, 2023
8e01f4c
Update strings structure and references
corrado4eyes Sep 20, 2023
261df5a
Update unit tests
corrado4eyes Sep 20, 2023
0c126d5
Update gradle files so that platforms can use the new module
corrado4eyes Sep 20, 2023
d0b1367
Update platforms tests and layout
corrado4eyes Sep 20, 2023
5052d8f
Add simple stub implementation for Node
corrado4eyes Sep 20, 2023
ea46cd7
Update tests
corrado4eyes Sep 20, 2023
9a8435d
Update TestCase class with sealed class and cases
corrado4eyes Sep 20, 2023
4fb3b11
Update assertion library
corrado4eyes Sep 20, 2023
bef8a79
Remove prints and update feature file
corrado4eyes Sep 20, 2023
8946885
Use identifier in android source set instead of Hardcoded string. Add…
corrado4eyes Sep 25, 2023
9f08e91
Add usage of application map for arguments
corrado4eyes Sep 25, 2023
157d5b5
Add doc for applicationArguments
corrado4eyes Sep 25, 2023
d928217
Rename exceptions removing prefix
corrado4eyes Sep 25, 2023
b3aced6
Update feature file
corrado4eyes Sep 26, 2023
ae07b35
Remove waitUntil from assertion method
corrado4eyes Sep 26, 2023
3eccea1
Rename files
corrado4eyes Sep 26, 2023
379c97f
Extract interface
corrado4eyes Sep 27, 2023
9f1a71a
Refactor so that TestCase interface is used. Also add platform specif…
corrado4eyes Sep 27, 2023
0f68652
Update view model and views created unit test
corrado4eyes Sep 27, 2023
1a51498
Update feature files
corrado4eyes Sep 27, 2023
32171a5
Update ui test files
corrado4eyes Sep 27, 2023
9109529
Update mock auth service and LoginVMTest
corrado4eyes Sep 27, 2023
223e289
Add `launchScreen` paramenter. Put arguments in different lines
corrado4eyes Sep 29, 2023
1d0af2c
Add APIs to scroll scroll views
corrado4eyes Sep 29, 2023
521bf85
Add SKIE to convert kotlin sealed classes into exhaustive enums in sw…
corrado4eyes Oct 2, 2023
dbfa64e
Remove empty lines
corrado4eyes Oct 2, 2023
9507f10
Add example for cross platform code
corrado4eyes Oct 2, 2023
57ffde9
Surround call by try/catches and add 25 retries on scrolls
corrado4eyes Oct 2, 2023
bd05f28
Update ui tests
corrado4eyes Oct 2, 2023
61b37da
Add logout call if the test configuration states that the user is log…
corrado4eyes Oct 2, 2023
da1690c
Add documentation
corrado4eyes Oct 2, 2023
4f606b3
Merge branch 'main' into feature/36-create-shared-button-finder
corrado4eyes Oct 2, 2023
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
Prev Previous commit
Next Next commit
Use identifier in android source set instead of Hardcoded string. Add…
… map to set application arguments.
  • Loading branch information
corrado4eyes committed Sep 25, 2023
commit 8946885fcbd659c0daad114f074fdaedb1713c3d
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ actual class DefaultApplicationAdapter(

val instrumentation = InstrumentationRegistry.getInstrumentation()
val appPackage = instrumentation.targetContext.packageName
val activityName = "$appPackage.MainActivity"
val activityName = "$appPackage.$identifier"
val intent = Intent(Intent.ACTION_MAIN)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.setClassName(instrumentation.targetContext, activityName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.corrado4eyes.pistakio

import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.flow.MutableStateFlow

class CMAppLaunchedAlreadyException : Throwable() {
override val message: String = "The app is already launched"
Expand All @@ -18,10 +17,12 @@ enum class TimeoutDuration(val duration: Duration) {
LONG(60.seconds)
}

typealias ApplicationArguments = Map<String, String>?
typealias ApplicationArguments = Map<String, String>

interface ApplicationAdapter {

val applicationArguments: ApplicationArguments

fun launch(identifier: String? = null, arguments: Map<String, String>)
fun findView(tag: String): Node
fun tearDown()
Expand All @@ -33,27 +34,41 @@ interface ApplicationAdapter {
interface TearDownHandler {
fun tearDown()
}

operator fun get(key: String): String?
operator fun set(key: String, value: String)
}

abstract class BaseApplicationAdapter : ApplicationAdapter {
private val isAppLaunched = MutableStateFlow(false)

private val _applicationArguments = mutableMapOf<String, String>()
override val applicationArguments: ApplicationArguments
get() = _applicationArguments

private var isAppLaunched = false

override fun launch(identifier: String?, arguments: Map<String, String>) {
if (isAppLaunched.value) {
if (isAppLaunched) {
throw CMAppLaunchedAlreadyException()
}
isAppLaunched.value = true

isAppLaunched = true
}

override fun tearDown() {
isAppLaunched.value = false
isAppLaunched = false
}

protected fun assertAppIsRunning() {
if (!isAppLaunched.value) {
if (!isAppLaunched) {
throw CMAppNotLaunchedYetException()
}
}

override operator fun get(key: String): String? = applicationArguments[key]
override operator fun set(key: String, value: String) {
_applicationArguments[key] = value
}
}

expect class DefaultApplicationAdapter: BaseApplicationAdapter
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.corrado4eyes.pistakio.Node
import com.corrado4eyes.pistakio.TimeoutDuration

class StubApplication : BaseApplicationAdapter() {

var launchCalled = 0
var launchArguments: ApplicationArguments = emptyMap()
override fun launch(identifier: String?, arguments: Map<String, String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import platform.XCTest.XCUIElementTypeAny
actual class DefaultApplicationAdapter(app: XCUIApplication?) : BaseApplicationAdapter() {
private val app: XCUIApplication = app ?: XCUIApplication()

@Suppress("UNCHECKED_CAST")
override fun launch(identifier: String?, arguments: Map<String, String>) {
super.launch(identifier, arguments)
app.setLaunchEnvironment((arguments as Map<Any?, *>))
Expand Down