Speeding Up Android Screenshots With MJPEG Servers
Previously on Appium Pro, we saw how to, and moreover how to turn that picture into an MJPEG stream for any use. In this clause, we & # x27; re going to focus on the utility of MJPEG streaming for Android. The sad fact about Android is that the supported method of retrieving screenshots (adb screencap) is very dull. There are ways to fine-tune this bidding to get it faster (for example by using adb exec-out and parsing the raw data from stdout), and this is indeed what Appium does to implement the & quot; get screenshot & quot; command on Android. Still, even in this best lawsuit scenario, Android screenshots can conduct an average of 0.3 to 0.5 seconds. On my machine, an accelerated emulator was able to yield a screenshot every 0.3 sec, and I & # x27; m using pretty beefy ironware. 0.3 seconds is pretty fast, but may not be fast plenty if the reason you & # x27; re taking screenshots is to perform image analysis, or maybe use Appium & # x27; s feature. If you & # x27; re interacting with an app primarily through screenshots, then 0.3 seconds might be the window within which you need to bump an element! Luckily, there & # x27; s a faster way, leveraging the mjpegScreenshotUrl we saw antecedently. This potentiality directs Appium to avoid its normal & quot; get screenshot & quot; implementation and alternatively connect to anMJPEGhost which is providing a watercourse of the screenshots. This stream results in a buffer of screenshot images store within Appium itself, so that screenshot retrieval is basically instant, costing you only the clip it takes to make the client shout and parse the image data. Bottom line: if you care about what & # x27; s bechance on the Android screen from a timing perspective, youneedto use mjpegScreenshotUrl. The only question is, how do you get an MJPEG stream of your Android screen going? There are different methods, but the leisurely method I & # x27; ve found is to use the Screen Stream Over HTTP app. It & # x27; s a complimentary download, and is alsounfastened sourcein event you need to figure out how it works. Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Basically, this app let you turn on an MJPEG server hosted by the device itself, present image frames free-base on what & # x27; s happening on the blind. You can configure the app so that it serve this current on any port, and also direct it to serve the stream over WiFi only or besides over early interfaces. Here & # x27; s how I set it up: Once you have the URL from the streaming app, try to load it up in your browser. You should see your screen mirror there! This is unfortunately not incisively what we involve for Appium, since the Screen Stream app embeds the current itself within an iframe. To get the URL of the actual stream, add /stream.mjepg to the host URL. (You can also charge this up in your browser to verify it works). To ensure Appium uses the images render by this stream, all you have to do is make that URL the value of the mjpegScreenshotUrl capacity! Pretty simple, once the app is installed and running. (Remember, if you & # x27; re apply an emulator, the horde should be localhost, because you forwarded the port on your local machine to the port on the emulator via the adb bidding). To showcase the usefulness of this coming, I & # x27; ve reduplicate the timing codification from the previous edition of Appium Pro, so we can get a good scientific comparison between tests thatdon & # x27; tuse the MJPEG server and exam that do. The only difference between the two exam suit is the use of the mjpegScreenshotUrl. Since this is the solitary difference, we & # x27; ll run both tests exactly by calling this one helper function: Basically, it attempts to get 100 screenshots in a row, and returns the amount of time taken on average. We can either run the screenshot recovery employ the normal method or the MJPEG server method, as depicted in the examination below: On my machine, utilise the MJPEG server cut the average screenshot time by more than one-half, from ~350ms to ~150ms per screenshot. Your mileage may vary, depending on a lot of ingredient. But it & # x27; s clear that if you care about shaving off those milliseconds from your screenshot clip, using the mjpegScreenshotUrl will be a outstanding scheme. Have you done anything cool with this characteristic? Let us know! And meanwhile, you can always check out thefull codification samplefor this article on GitHub. Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in crafting pursue narratives and market collateral across diverse industries. She excels in collaborating with cross-functional squad to develop innovative message strategies and deliver compelling, authentic, and impactful content that resonates with target hearing and enhances brand legitimacy. 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)



Speeding Up Android Screenshots With MJPEG Servers
AI-Powered Key Takeaways

Setting up Screen Stream Over HTTP for a real device
Also Check:
Setting up Screen Stream Over HTTP for an emulator

Using the mjpegScreenshotUrl
Putting it all together
public long timeScreenshots (boolean useMjpeg) throws IOException {DesiredCapabilities crest = new DesiredCapabilities (); caps.setCapability (`` platformName '', `` Android ''); caps.setCapability (`` deviceName '', `` Android Emulator ''); caps.setCapability (`` automationName '', `` UiAutomator2 ''); caps.setCapability (`` app '', ANDROID_APP); if (useMjpeg) {caps.setCapability (`` mjpegScreenshotUrl '', `` http: //localhost:8080/stream.mjpeg '');} driver = new AndroidDriver (new URL (`` http: //0.0.0.0:4723/wd/hub ''), detonator); long startTime = System.nanoTime (); for (int i = 0; i< 100; i++) {
driver.getScreenshotAs(OutputType.FILE);
}
long endTime = System.nanoTime();
long msElapsed = (endTime - startTime) / 1000000;
return msElapsed;
}
@ Test public nullity timeScreenshotsWithDefaultBehavior () throws IOException {long msElapsed = timeScreenshots (false); System.out.println (`` 100 screenshots normally: `` + msElapsed + `` ms. On mean `` + msElapsed/100 + `` ms per screenshot '');} @ Test public void timeScreenshotsWithMjpegScreenshotBehavior () throws IOException {long msElapsed = timeScreenshots (true); System.out.println (`` 100 screenshots using mjpeg: `` + msElapsed + `` ms. On average `` + msElapsed/100 + `` ms per screenshot '');}Piali Mazumdar
Speeding Up Android Screenshots With MJPEG Servers
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for forward-looking exploiter (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for advanced users (Part 4)
Discover how HeadSpin can empower your business with superior testing potentiality







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


Automate This With SUSA
Test Your App Autonomously







.png)












