androidandroid-emulatorandroid-espressoandroid-uiautomatorui-testing

How can I change emulator virtual scene in real time?


I'm making UI tests for an application that scans barcodes. I've successfully found a way of inserting a barcode image in the emulator virtual scene to test scanning following this post.

I've made it following this answer since it was exactly what I needed: The problem is that I want to test different barcode images for each test case, and I'm trying to find a way of doing it.

An approach I've thought is replacing the image in real time, but I think you need to restart the emulator plus it looks dirty and I don't know how to implement it in kaspresso. Another way is injecting a fake result in the scanner, but then the purpose of end-to-end UI tests is lost so...

What would be the best approach to do this and implement it (if possible). I'm looking for answers but it seems no one has done it yet.

I've also sen there are macros in the resource folders in emulator folder, this may be useful but I don't know how to use them:

enter image description here


Solution

  • In the end, I made a .jar file done in Java 8, that used sockets to manipulate the file I used as barcode using the .posters solution. It launched with a Gradle task when running the UI tests and in the android emulator, I used a client to communicate which barcode to place in the virtual scene. When the last test is run, the emulator closes the server. We can implement this in a pipeline.