Seeding an Android Device with Test Photos
As promised, this week & # x27; s edition is an Android-flavored follow-up to final week & # x27; s tip on. The problem we & # x27; re trying to solve is how to get pictures with known content onto the device for use in our App Under Test. This is a requirement for any eccentric of app that employ or processes persona. How do you essay that your app does the correct thing to a user-provided image? What these steps do is provide a gold-standard before-and-after which you can use as a test fixture. In an machine-driven fashion now, we can provide the app with the same initial picture, run the desired map, and then regain the modified image. We can verify this modified icon is byte-for-byte eq to our gold standard to ensure the app functionality withal work as expected. SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. In this edition we focus on the problem of getting our initial picture onto the twist. How make one do this for Android? Happily, we use the like function as for iOS:pushFile. Under the hoodlum,pushFile uses a serial ofADB commands to shuffle the picture to the gimmick and then broadcast a scheme intent to refresh the medium library. Since different twist manufacturers put painting in different places, you do need to know the path on your device that stores media. For emulators and at least some real devices, the path on the device is/mnt/sdcard/Pictures, so this is an important constant to your remember. As an exemplar: As you can see, the inaugural argument is the removed route on the device where we need the picture to end up. This is where you may need to relate to documentation on your particular twist or Android OS look to ensure you have the right itinerary. The second disputation is the path to the file on your local machine, where your test is running. When the tryout executes, the Appium client will encode this file as a twine and send it over to the Appium host, which will so do the job of getting it on the device. This architecture is nice because it means thatpushFile works whether you & # x27; re running locally, or on a cloud provider. Let & # x27; s direct a aspect at a complete act example. In this example, we automate the built-in Google Photos app. First of all, we set up our craved capabilities to just use a built-in app: Once the app is exposed, we have to sail through some UI boilerplate and other things Google require us to do to use their cloud. Of trend we are robots and not interested in their cloud! I & # x27; ve put this app state setup into its own method, along with setting up some locator constants, and logic that withdraw any existing pictures to create our verification easier subsequently on: Finally we can get to the meat of our test, which relies upon the appropriate device media itinerary constant: As you can see, the literal bit we care some is as mere as callingpushFile. For the sake of this test, we are just verifying that our picture be at the end. In a real-world scenario, we & # x27; d then run our app functionality on the icon, and retrieve it from the device to perform some local confirmation on it. Bringing it all together, the entire test class looks like the following: As always, you can check out the code in the context of all its dependencieson 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 marketing collateral across various manufacture. She excels in collaborating with cross-functional teams to evolve innovative content scheme and deliver compelling, veritable, and impactful message that vibrate with target audiences and enhances brand authenticity. 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)



Seeding an Android Device with Test Photos
AI-Powered Key Takeaways
Test your Android apps on real outside devices seamlessly..
driver.pushFile (`` /mnt/sdcard/Pictures/myPhoto.jpg '', `` /path/to/photo/locally/myPhoto.jpg '');DesiredCapabilities capability = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` Android ''); capabilities.setCapability (`` deviceName '', `` Android Emulator ''); capabilities.setCapability (`` automationName '', `` UiAutomator2 ''); capabilities.setCapability (`` appPackage '', `` com.google.android.apps.photos ''); capabilities.setCapability (`` appActivity '', `` .home.HomeActivity ''); // Open the app. AndroidDriver driver = new AndroidDriver < > (new URL (`` http: //localhost:4723/wd/hub ''), capabilities);private electrostatic By backupSwitch = By.id (`` com.google.android.apps.photos: id/auto_backup_switch ''); private inactive By touchOutside = By.id (`` com.google.android.apps.photos: id/touch_outside ''); individual motionless By keepOff = By.xpath (`` // * [@ text='KEEP OFF '] ''); private static By exposure = By.xpath (`` //android.view.ViewGroup [contains (@ content-desc, 'Photo taken ')] ''); private inactive By trash = By.id (`` com.google.android.apps.photos: id/trash ''); individual static By moveToTrash = By.xpath (`` // * [@ text='MOVE TO TRASH '] ''); public void setupAppState (AndroidDriver driver) {// navigate through the google junk to get to the app WebDriverWait wait = new WebDriverWait (driver, 10); WebDriverWait shortWait = new WebDriverWait (driver, 3); wait.until (ExpectedConditions.presenceOfElementLocated (backupSwitch)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (touchOutside)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (keepOff)) .click (); // delete any live icon using an unnumbered loop break when we ca n't find any // more pictures try {while (true) {shortWait.until (ExpectedConditions.presenceOfElementLocated (photo)) .click (); shortWait.until (ExpectedConditions.presenceOfElementLocated (trash)) .click (); shortWait.until (ExpectedConditions.presenceOfElementLocated (moveToTrash)) .click ();}} catch (TimeoutException ignore) {}}setupAppState (driver); // set up the file we desire to advertise to the phone 's library File assetDir = new File (classpathRoot, `` .. /assets ''); File img = new File (assetDir.getCanonicalPath (), `` cloudgrey.png ''); // actually push the file driver.pushFile (ANDROID_PHOTO_PATH + `` / '' + img.getName (), img); // waiting for the system to notice the new photo, and use the WebDriverWait to verify // that the new photo is there WebDriverWait wait = new WebDriverWait (driver, 10); ExpectedCondition condition = ExpectedConditions.numberOfElementsToBe (photo,1); wait.until (status);import io.appium.java_client.android.AndroidDriver; import java.io.File; import java.io.IOException; import java.net.URL; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.remote.DesiredCapabilities; signification org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; // Note that to run correctly, this tryout must be run against a edition of Appium which includes // the appium-android-driver bundle at version 1.38 or high, since it contain relevant bugfixes public family Edition002_Android_Photos {private static String ANDROID_PHOTO_PATH = `` /mnt/sdcard/Pictures ''; private static By backupSwitch = By.id (`` com.google.android.apps.photos: id/auto_backup_switch ''); private static By touchOutside = By.id (`` com.google.android.apps.photos: id/touch_outside ''); private static By keepOff = By.xpath (`` // * [@ text='KEEP OFF '] ''); private static By photo = By.xpath (`` //android.view.ViewGroup [contains (@ content-desc, 'Photo taken ')] ''); private static By trash = By.id (`` com.google.android.apps.photos: id/trash ''); private static By moveToTrash = By.xpath (`` // * [@ text='MOVE TO TRASH '] ''); @ Test public void testSeedPhotoPicker () throws IOException {DesiredCapabilities capabilities = new DesiredCapabilities (); File classpathRoot = new File (System.getProperty (`` user.dir '')); capabilities.setCapability (`` platformName '', `` Android ''); capabilities.setCapability (`` deviceName '', `` Android Emulator ''); capabilities.setCapability (`` automationName '', `` UiAutomator2 ''); capabilities.setCapability (`` appPackage '', `` com.google.android.apps.photos ''); capabilities.setCapability (`` appActivity '', `` .home.HomeActivity ''); // Open the app. AndroidDriver driver = new AndroidDriver < > (new URL (`` http: //localhost:4723/wd/hub ''), capabilities); try {// there 's some screens we need to navigate through and ensure there are no existing photos setupAppState (driver); // set up the file we want to push to the telephone 's library File assetDir = new File (classpathRoot, `` .. /assets ''); File img = new File (assetDir.getCanonicalPath (), `` cloudgrey.png ''); // really push the file driver.pushFile (ANDROID_PHOTO_PATH + `` / '' + img.getName (), img); // wait for the system to acknowledge the new photo, and use the WebDriverWait to control // that the new photo is thither WebDriverWait wait = new WebDriverWait (driver, 10); ExpectedCondition condition = ExpectedConditions.numberOfElementsToBe (photo,1); wait.until (precondition);} finally {driver.quit ();}} public void setupAppState (AndroidDriver driver) {// navigate through the google junk to get to the app WebDriverWait wait = new WebDriverWait (driver, 10); WebDriverWait shortWait = new WebDriverWait (driver, 3); wait.until (ExpectedConditions.presenceOfElementLocated (backupSwitch)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (touchOutside)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (keepOff)) .click (); // delete any survive pictures using an myriad grommet broken when we ca n't find any // more pictures try {while (true) {shortWait.until (ExpectedConditions.presenceOfElementLocated (photo)) .click (); shortWait.until (ExpectedConditions.presenceOfElementLocated (trash)) .click (); shortWait.until (ExpectedConditions.presenceOfElementLocated (moveToTrash)) .click ();}} catch (TimeoutException ignore) {}}}Piali Mazumdar
Seeding an Android Device with Test Photos
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for advanced users (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 capabilities







Discover how HeadSpin can empower 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)












