Robotium - Write to file in eclipse workspace or computer file system
- by Flavio Capaccio
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"));
    }