FioriBaseTestTags

open class FioriBaseTestTags(val identifier: String? = null)

The class FioriBaseTestTags serves as the parent for all subclasses that encapsulate test tags within various Fiori Compose UI components.

Those test tags were especially useful for UI tests with frameworks like Jetpack Compose Testing. However, if you need any test framework to treat the test tags as resource IDs, you must locate the root composable function in your Test App UI and enable test tags by setting the 'testTagsAsResourceId' property. By default, the Fiori Components will not set this option. For example:

// The onCreate method of MainActivity in your test App
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
YourTheme {
Surface(
modifier = Modifier.fillMaxSize().semantics {
testTagsAsResourceId = true
}
) {
TestAppScreen()
}
}
}
}

Essentially, each Fiori composable UI control should have its own concrete class derived from FioriBaseTestTags.

The concrete class of FioriBaseTestTags should have a private constructor, and all properties should be immutable and of either string-type or FioriBaseTestTags type if there are nested Fiori Compose UI components.

The concrete class of FioriTestTagsBuilder in the concrete class of FioriBaseTestTags take the responsibility to build an instance of FioriBaseTestTags.

There is an optional string-type property called identifier in FioriBaseTestTags. This property is used to identify all test tags within the FioriBaseTestTags. When the identifier is non-empty, it is prefixed to all test tags, followed by an underscore, except for the FioriBaseTestTags-type property values.

The concrete class of FioriBaseTestTags can have an immutable property of the FioriBaseTestTags type. However, the identifier value in the parent FioriBaseTestTags will not affect the child FioriBaseTestTags.

In the special case where your Fiori Compose UI component uses dynamic test tags, such as displaying an icon whose resource ID is provided by the consumer, you may use the resource ID as the test tag for the icon. In that case, you can prepend the identifier set by the consumer using the method FioriBaseTestTags.prependIdentifier. This is helpful if the consumer displays multiple Fiori Compose UI components and wants to distinguish all UI elements by their identified test tags.

Example usage:

class FooTestTags private constructor(
identifier: String?,
val labelTag: String
): FioriBaseTestTags(identifier = identifier) {

companion object {
const val TAG_LABEL = "foo_label" // Define default test tag for label
}

class Builder: FioriTestTagsBuilder<FooTestTags>() {
override fun build(): FioriFooTableTestTags {
// any property which was the FioriBaseTestTags-type, You can try to retrieve the possible customized value via method 'getTestTags'
// Fo example, Your FooTestTags has a property, childTestTags, was a FioriBaseTestTags-type
// val childTestTags = getTestTags(FooTestTags::childTestTags)

return FooTestTags(
identifier = getIdentifier(),
labelTag = prependValue(FooTestTags::labelTag, TAG_LABEL)
// Assume the childTestTags property was another concrete class of FioriBaseTestTags, ChildFooTestTags
// childTestTags = fooTestTags?.let {
// it as ChildFooTestTags
// } ?: ChildFooTestTags.Builder().build()
)
}
}
}

Inheritors

Constructors

Link copied to clipboard
constructor(identifier: String? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val identifier: String?

An optional identifier used as a prefix, followed by an underscore, to be added to each property value to ensure uniqueness across instances. The default value is null.