0

I'm running some tests using Robotium on an Android application that interacts with a web-portal.

I'd like to save some information to file; for example I need to save the id of the username I created from the app and I want to make it read from Selenium to run tests on web-portal to verify a webpage for that user has been created.

Is it possible?

Could someone suggest me a solution or a work-around?

This is an example of code, but it doesn't work (I want to write to a file for example on c:\myworkspace\filename.txt a string):

public void test_write_file(){
        if(!solo.searchText("HOME")){
            signIn("39777555333", VALID_PASSWORD);
        }

        try {
            String content = "This is the content to write into file";

            File file = new File("filename.txt");

            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        assertTrue(solo.searchText("HOME"));
    }

This code should write to file on device; my goal is to write on a file on machine from which I'm launching the script; the application under test should have permission to write to memory card; but I ask how to go out from Android Environment and get my Desktop environment.

Flavio Capaccio
  • 706
  • 4
  • 15
  • 1
    of course it's possible! what have you tried so far? do you at least have a minimal understanding of the code involved? unfortunately, we only have enough time to help you, not to devise an entire solution. Provide us some code, then we can help you out. – ddavison Oct 03 '13 at 14:11
  • I added the code I used but it doesn't work. – Flavio Capaccio Oct 17 '13 at 15:52

2 Answers2

1

For tests I suppose you will need xml format to be saved: Create xml file and save it in internal storage android

And then you will need to copy saved file from your device, see this How to copy selected files from Android with adb pull

You could be not so lazy and search it yourself.

Community
  • 1
  • 1
keymusicman
  • 1,281
  • 1
  • 10
  • 20
  • As you can see in the edited version of my post I want to save on a file without using adb and writing not in the internal or external storage but on a file of machine on which I'm running eclipse. – Flavio Capaccio Oct 17 '13 at 15:53
  • 1
    The only way to do what you want (as I understand, you want your tests to create file and save it on a remote computer) is to create simple server (for example, REST server) on your computer and client in your test project. So you could save files to your computer by calling just one method which will send file to server and then server will save it. There is no easiest way to do it. – keymusicman Oct 22 '13 at 05:58
  • Ok! I thought to save these information on a db; if you know a way to go out from Android environment and get machine environment let me know. – Flavio Capaccio Oct 22 '13 at 12:03
  • Look [How to copy files from Android to PC](https://groups.google.com/forum/#!topic/android-developers/N_FieRqO7_U), [transfer files from android to computer via usb programmatically](http://stackoverflow.com/questions/15795186/transfer-files-from-android-to-computer-via-usb-programmatically). Hope it helps. – keymusicman Oct 23 '13 at 07:54
0

For reading from a file or writing to file you would have to use normal java method. There you can create a separate method to read/write, which can be called whenever needed. you can see examples here for normal text file and excel file.

kamal_prd
  • 543
  • 4
  • 16
  • Thank you for your help; this code is good when you've to write to a file but I need to write in a file on my computer from my robotium test method. – Flavio Capaccio Oct 17 '13 at 15:54