6

I am following Testing in Jetpack Compose Codelab but I am unable to print the Semantics tree using the printToLog function on a node. I am using this code inside the androidTest package.

import androidx.compose.ui.test.printToLog 

...

    //testing function
    @Test
    fun rallyTopAppBarTest() {
    
        val allScreen = RallyScreen.values().toList()
        testRule.setContent {
            //the component be tested in isolation goes here
            RallyTopAppBar(
                allScreens = allScreen,
                onTabSelected = {},
                currentScreen = RallyScreen.Accounts
            )
        }
        
        testRule.onRoot().printToLog("currentLabelExists")
        
            ....
    }

I have checked my LogCat with both Debug and Verbose filtering using "currentLabelExists" tag but the Semantics Tree is not printing on the log.

Any ideas on what I might be missing out.

Tonnie
  • 4,865
  • 3
  • 34
  • 50

2 Answers2

9

I can see the semantics tree.
Check if Android Studio Logcat has "No Filters"

Filter options

Edit
It seems to be a bug as I can sometimes see the logs even if I select "Show only selected application".

Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
  • Hi Abhimanyu, Thx very much for pointing me to the right way. Why do u think the log is only shown when you don't have filters? – Tonnie Oct 09 '21 at 20:03
  • 1
    It seems to be a bug to me as I can sometimes see the logs even if I select "Show only selected application". There are some inconsistencies. – Abhimanyu Oct 10 '21 at 03:22
  • Thx man, you are a legend. – Tonnie Oct 10 '21 at 04:01
1

Since I just ran into the same problem: The SemanticsTree seems to appear only when you run your tests in Debug Mode

Robert Schröder
  • 169
  • 2
  • 11