I am wondering why's everyone going after testing ...
# compose-desktop
t
I am wondering why's everyone going after testing this week πŸ˜†
βž• 2
c
Released to production last week... time to start testing this week. πŸ˜‚
πŸ˜‚ 3
t
Just wanted to take a screenshot and it seems to be impossible outside of testing so I lookt into its implementation πŸ€·β€β™‚οΈπŸ˜‚
i
Just wanted to take a screenshot
You can use
TestComposeWindow
πŸ™‚
Copy code
val window = TestComposeWindow(width = 1024, height = 768)

window.setContent {

}

File(path).writeBytes(window.surface.makeImageSnapshot().encodeToData()!!.bytes)
πŸŽ‰ 3
It has some bugs, so it is better to use it inside
SwingUtilities.invokeLater
. We will fix this in this issue
t
Thanks @Igor Demin for this very clear example πŸ™ Would be really cool if this would find its way into the test documentation and if not I will personally create a pull request for it ^^ Additional question: Can we just create an skia surface, print our components to it and take a screenshot from that? (without creating a whole window)
i
Would be really cool if this would find its way into the test documentation
Very good idea, thanks πŸ™‚ https://github.com/JetBrains/compose-jb/issues/368#issuecomment-811166809
skia surface, print our components to it and take a screenshot from that? (without creating a whole window)
TestComposeWindow
does exactly that. It doesn't create a whole window.
t
Very cool πŸ‘ ok sorry for misinterpreting the class name I will try it asap. Thanks 😁
i
SwingUtilities.invokeLater
is needed because we don't properly handle
mutableStateOf
observations in other threads than Swing thread.