Xamarin.UITest Working with photo capture and images in UITest automation

Our application allows users to take a photo. I'm not that interested in testing the camera function from within the test framework. I would like to bootstrap (or load) a few images on to the emulator since the app allows you to select a photo from the camera roll. I have not found any documentation on how to achieve this, or whether it is even possible. Pre-loading pictures on to the emulated device would be much faster and allow for me to have a known set of images to pick from.

So my questions are:
1. Is it possible to programmatically load photos onto an emulated device (Android)?
2. If its possible, then can someone point me to some documentation or code snippets on how to achieve this?

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    If you want to copy image programtically then use following code:

       File sourceLocation= new File (sourcepath);
       File targetLocation= new File (targetpath);
    
       InputStream in = new FileInputStream(sourceLocation);
       OutputStream out = new FileOutputStream(targetLocation);
    
            // Copy the bits from instream to outstream
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
    
  • knudmtknudmt Member ✭✭

    @jezh So your saying that I can just write to the android device file system via a stream?

Sign In or Register to comment.