Saving Test Data to Make Debugging Easier
When we & # x27; re indite tests on our local machines, we & # x27; re usually running precisely one Appium trial at a clip, with the waiter log window to one side to facilitate us in case something proceed wrong. We & # x27; re besides usually observe the test execute on the simulator or device (unless we & # x27; ve decide to lead a java break at that moment). In this character of scenario, it & # x27; s often pretty easy to name a test failure, because we can see immediately that the exam didn & # x27; t proceed to the correct view, find the correct factor, or whatever the issue might be. This happy little scenario, however, is not typically the one we find ourselves when we actuallyneedto debug something. We never commit miscarry tests to our build (correct? right?), so when there & # x27; s a build failure because of one of our tests, it & # x27; s because something went incorrect that we didn & # x27; t expect. In this case, it & # x27; s usually not precisely one test that ran, but many, and by the time we know of the failure, the trial itself is long finished. At this point, we can & # x27; t watch the test run, and unless we did something special to save it, we no longer have admission to the Appium logs or any record of the app state at the clip of failure. So, let & # x27; s do that exceptional something to create sure that we don & # x27; t twist up in a frightful debugging situation with nil to go on! SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. The basic mind here is that we desire to shoot some codification into the exam lifecycle, specifically in between test failure and cleaning up to move on to the following exam. At this point in the test lifecycle, we know we & # x27; ve got a failed tryout, but we haven & # x27; t yet cease our Appium session, so we nonetheless have access to a driver object. This is great, because (assuming the Appium session itself is still alive and working correctly), we can use it to retrieve all kinds of helpful diagnostic information about the session, which we can then save on disk for for later review should the need arise. What do we want to save? That is of trend up to us, but I & # x27; m proposing a canonical set of 3 useful particular: These are all in addition, of line, to the client/test log itself, which is output within the CI scheme and therefore easy to save one way or another. To actually retrieve all this datum, we simply need to use the appropriate Appium commands. Then it & # x27; s up to us what to do with them. In this example, I & # x27; ll just write them to stdout, assuming that all logging from the test yield is being salvage somewhere reasonable: If you run your own instance of Appium, you can become on host log retrieval using the -- allow-insecure flag: The question remains, though: where to put the code above? Each test fabric has a different way of reckon out whether a trial has failed and perform some actions before moving on to the succeeding examination. In JUnit, this is via the TestWatcher grade. The way we use it is to make our own propagation of this class, and override particular methods of TestWatcher concern to the aspects of the lifecycle where we want to inject codification. Then we assign our new watcher class as a @ Rule in our test category itself. From a gaunt perspective, it would seem something like the following: We can, as in the example above, delineate our watcher class right in our test class itself, if we want (but we don & # x27; t get to). The crucial things are to (a) override the failed method and put all our debug handler codification in it, and (b) override the stop method to act as our tear-down function, wherein we pick up the driver and anything else we need. That & # x27; s fundamentally it! It & # x27; s up to you to get creative with where you put the debug benefactor info retrieved from Appium -- post it to an plus depot system? Build your own debug UI on top of it? Whatever you want. Make sure to occupy a look at thefull exampleon GitHub, with literal examination logic fill out, so you can see how everything act when it & # x27; s fully put together. Happy debugging (or at least, happi_er_ debugging)! Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in craft hire narratives and marketing collateral across diverse industries. She excels in collaborating with cross-functional teams to germinate innovative substance strategies and deliver compelling, unquestionable, and impactful content that resonate with target audiences and enhances brand genuineness. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Saving Test Data to Make Debugging Easier
AI-Powered Key Takeaways
Debugging in CI
Also cheque:
Capturing Debug Helpers
Read:
// mark appium logs LogEntries entries = driver.manage () .logs () .get (`` server ''); System.out.println (`` ======== APPIUM SERVER LOGS ======== ''); for (LogEntry entry: entries) {System.out.println (new Date (entry.getTimestamp ()) + `` `` + entry.getMessage ());} System.out.println (`` ================ ''); // print source System.out.println (`` ======== APP SOURCE ======== ''); System.out.println (driver.getPageSource ()); System.out.println (`` ================ ''); // save screenshot String testName = desc.getMethodName () .replaceAll (`` [^a-zA-Z0-9-_\\.] '', `` _ ''); File screenData = driver.getScreenshotAs (OutputType.FILE); try {File screenFile = new File (SCREEN_DIR + `` / '' + testName + `` .png ''); FileUtils.copyFile (screenData, screenFile); System.out.println (`` ======== SCREENSHOT ======== ''); System.out.println (screenFile.getAbsolutePath ()); System.out.println (`` ================ '');} match (IOException ign) {}
Once you strip away the gratuitous log printing, you & # x27; ll see that the codification above is pretty straightforward. The lonesome complexity get in retrieving the Appium server logarithm. On the client side, we use the log manager to retrieve logs of type server. Because Appium servers might probably handle sessions for multiple guest at a clip, yet, server log retrieval is not enabled by default as a potential information security risk.Also read:
appium -- allow-insecure=get_system_logs
This will place Appium not to complain if you undertake to get the scheme logs!JUnit & # x27; s TestWatcher
public class Edition088_Debugging_Aids {individual IOSDriver driver; @ Rule public DebugWatcher debugWatcher = new DebugWatcher (); @ Before public emptiness apparatus () drop MalformedURLException {/ * ... * /} @ Test public void testSomething () {/ * ... * /} public course DebugWatcher extends TestWatcher {@ Override protected void neglect (Throwable e, Description desc) {// -- - > this is where our debug print line go!<---
}
@Override
protected void finished(Description desc) {
if (driver != null) {
driver.quit();
}
}
}
}
Check out:
Piali Mazumdar
Saving Test Data to Make Debugging Easier
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical usher for forward-looking users (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence virtual guide for modern users (Part 4)
Discover how HeadSpin can empower your business with superior testing capabilities







Discover how HeadSpin can empower your business with superior testing capabilities
Discover how HeadSpin can invest your business with superior try capabilities
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












