Skip to content
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

Feature request: Make Kaspresso robolectric-compatible (Project Nitrogen) #242

Closed
sergio-sastre opened this issue May 2, 2021 · 1 comment

Comments

@sergio-sastre
Copy link
Contributor

sergio-sastre commented May 2, 2021

Hi there!
I was trying to write Kaspresso tests that run on the JVM with Robolectric, as stated by Google in this video

However, I was getting the following error:

java.lang.NullPointerException
	at androidx.test.uiautomator.QueryController.<init>(QueryController.java:95)
	at androidx.test.uiautomator.UiDevice.<init>(UiDevice.java:109)
	at androidx.test.uiautomator.UiDevice.getInstance(UiDevice.java:261)
	at com.kaspersky.kaspresso.kaspresso.Kaspresso$Builder.<init>(Kaspresso.kt:297)
	at com.kaspersky.kaspresso.kaspresso.Kaspresso$Builder$Companion.simple(Kaspresso.kt:215)
	...

That is because Robolectric is just compatible with Espresso and not with uiAutomator, and the TestCase class initialize both, Espresso through Kaspresso and UiAutomator through Kautomator.

Therefore I forked Kaspresso and created a NitrogenTestCase() that only initializes Kaspresso, leaving Kautomator aside. This also means, no adb-server possible either, as well as some other interceptors e.g. the "Close System Dialog interceptor"
I successfully made the error disappear and the tests I wrote ran green as JVM tests as well as Instrumentation tests :)
It enables to make tests that inherit from NitrogenTestCase() to run on both, JVM and emulators/devices.

Moreover, the Autoscroll and flakySafety interceptors still work on the JVM: running with pure Kakao, one test failed because the button was not visible and needed to scroll to find it, and another one also failed because the view appears after 7-seconds delay, while both succeeded when running with Kasspreso.NitrogenTestCase()

However, there are some issues on the Robolectric-Espresso side to keep in mind, that would also not work with NitrogenTestCase() while running on the JVM:

  1. Robolectric-Espresso does not support Idling resources yet
  2. Robolectric-Espresso will not support tests that start new activities (i.e. activity jumping). It means, such integration tests will successfully run on devices/emulators and fail on the JVM.

If would gladly create a pull request and add the docu to the wiki if you find this feature (as me) interesting!

@artkoenig
Copy link

@sergio-sastre can you please fix the "Roboelectric" to "Robolectric" for matching the keyword search results?

@sergio-sastre sergio-sastre changed the title Feature request: Make Kaspresso roboelectric-compatible (Project Nitrogen) Feature request: Make Kaspresso robolectric-compatible (Project Nitrogen) May 19, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 5, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 5, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 5, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 5, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 5, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 7, 2021
… 4.6.1 causes some unexpected crashes in Reflection.
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 8, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 8, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 8, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 8, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 8, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 8, 2021
matzuk added a commit to matzuk/Kaspresso-1 that referenced this issue Oct 8, 2021
@matzuk matzuk closed this as completed Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants