For testing purposes in an app we use `semantics` ...
# compose
t
For testing purposes in an app we use
semantics
on our
Composables
. Now for a custom component we had to use
Canvas
te draw it. Does anyone know of a way to access the contents of the
Canvas
in testing? e.g.: a
drawText
is used and we would like to validate the value displayed. Can this be done by reading it directly from the
Canvas
in testing or must we attempt to validate this value in our testing before getting to the point of drawing it on the
Canvas
a
You’ll need to either validate the semantics property or validate the snapshot. Btw if you draw text manually, you should properly set the semantics property (namely
text
) anyway for accessibility (so that the screen reader can read the text).
t
But you can't add a semantics modifier, or any modifier for that matter to a
drawText
so is there an alternative?
a
Apply the semantics modifier to the canvas.
t
Yea but in the
DrawScope
how can I access the value of the
drawText
that can't be done with the
semantics
on the Canvas itself
a
You can’t.
z
How are you getting the text inside the draw function? Just pass that same text to the semantics modifier
t
Oh yea like that is possible I guess. Unfortunately we have decided to globally use contentDescription on each component and since I have multiple texts this won't work for our specific use case but it is a good idea nonetheless