There is an open source framework built on top of appium that does this out of the box. Have a look at it here