-2

I have been trying to implement database in robotium so that i can parametrize and make it data oriented but i am completely lost please guide me.My robotium code is mentioned below please guide me on how can i open a database connection with sqlite.

package com.dialog.test;

import android.test.ActivityInstrumentationTestCase2;
import com.jayway.android.robotium.solo.Solo;

public class TestNew extends ActivityInstrumentationTestCase2 {
    private Solo solo;


    //private Activity Main;
    private static Class class1;
    static
    {
        try {
            class1=Class.forName("com.botskool.DialogBox.DialogBox");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public TestNew() {
        super("com.botskool.DialogBox", class1);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        this.solo = new Solo(getInstrumentation(), getActivity());
    }

    @Override
    protected void tearDown() throws Exception{
        try {
            this.solo.finalize();
            } catch (Throwable e) {
                e.printStackTrace();
            }
            getActivity().finish();
                super.tearDown();
            }

    public void testDisplay(){
        solo.clickOnButton(0);
        solo.clickOnButton("Ok");
        solo.clickOnButton(2);
    }
}

Even the smallest guidance would be of great help thank you

3
  • i am unable to connect it sqlite db so that i can make it data driven. i am workign with robotium for apk. Sep 22, 2011 at 2:14
  • You need to reframe your question in a better way! Dec 14, 2015 at 12:05
  • this was raised on 2011 and solution was already found stop spamming Dec 17, 2015 at 4:44

1 Answer 1

0

You can use File IO of java to integrate in robotium script. provide the File path as of the path in android device like /system/docs/test1.txt . You can provide the details in a file and push the file to the device using adb push commands. and when the script runs, your parameters will be accessed. I am giving you sample code of robotium test case :

  public void test(){


    String strLine = "",PHN1="", MSG="", siters="";
    File f = null;
    try {

        f = new File("/system/SendSMS.txt");
        FileInputStream fileIS = new FileInputStream(f);
        BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
        String readString = new String();
        while ((readString = buf.readLine()) != null) {
            strLine = strLine + readString;
        }

    } catch (Exception e) {

        Log.e("ERROR", "" + e.getMessage());
        e.printStackTrace();
    }
    PHN1 = strLine.substring(strLine.indexOf("[PHN1]")+"[PHN1]".length(), strLine.indexOf("[$PHN1]"));
    MSG = strLine.substring(strLine.indexOf("[MSG]")+"[MSG]".length(), strLine.indexOf("[$MSG]"));
    siters = strLine.substring(strLine.indexOf("[ITERS]")+"[ITERS]".length(), strLine.indexOf("[$ITERS]"));
    int iters = Integer.valueOf(siters);
    Log.i("D2Tech","SMS Contact : "+PHN1);
    Log.i("D2Tech","SMS Message : "+MSG);
    Log.i("D2Tech","SMS Iterations : "+iters);
    PHN1="0183030689,0183030687";
    iters=50;

    for(int j = 1; j<= iters ; j++ ){

            solo.clickOnText("New message");


            solo.enterText(0, PHN1);

            solo.enterText(1, MSG + j);
            solo.goBack();
            solo.clickOnButton("Send");
            solo.goBack();
            Log.i("D2Tech","SMS Message number : "+j);

    }
    solo.waitForDialogToClose(1000);
}
1
  • i just trying it out will let you know in a short while :) Sep 22, 2011 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.