sangmingming / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

solo.isCheckBoxChecked(String) always returns false #106

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Create a test case using robotium 2.2 check the the appropriate checkboxes in 
the new junit test case dialog box(setUp(), tearDown() and constructor)
2. Provide the approriate initialization and test cases.
3. use the solo.isCheckBoxChecked(String) at the testSettingsPrefs() testcase 
always return boolean false. which in actual this must return true.

What is the expected output? What do you see instead?
solo.isCheckBoxChecked(String) testcase always return boolean false. which in 
actual this must return true(as if it doesn't recognize the label within the 
<CheckBoxPreference> in my settings.xml).

I am currently using robotium 2.2, and have Windows 7 as my operating system.

Hello Moderators and developers, I have the problem like any other individuals 
who reported this first(I've had read all their dilemma), and AFAIK the current 
solution is to use its index:

http://groups.google.com/group/robotium-developers/browse_thread/thread/bc1f82f9
d53e65b2/701a281a1c85b3ab?#701a281a1c85b3ab
and
https://code.google.com/p/robotium/issues/detail?id=97

I am new to the android environment and tried any suitable technology with 
regards to my development. But indeed, in everything that I tried, I cannot 
imagine the use of solo.isCheckBoxChecked(String); since it always returns 
false, please see the Scenario/Code below:

    @Smoke
    public void testSettingsPrefs() throws Exception{

        solo.clickOnMenuItem("Settings");
        solo.clickOnText("Music"); 
        solo.clickOnText("Hints");
        boolean expected = true;

//returns null :(
//checkBx1_text = , checkBx2_text =
        solo.getCurrentCheckBoxes().get(0).setText("TAE");
        Log.i(TAG, "checkBx1_text = "+solo.getCurrentCheckBoxes().get(0).getText()+
                ", checkBx2_text = "+solo.getCurrentCheckBoxes().get(1).getText());

//commented this one since it gives me an error     
//      solo.getCurrentCheckBoxes().get(0).setText("Music");

//the boolean that will be use to assert if the 2 checkbox(Music, 
// Hints) are unchecked
        boolean actual = !(solo.isCheckBoxChecked("Music") && solo.isCheckBoxChecked("Hints"));

//logging with the use of isCheckBoxChecked(int index);
//this method gives me the correct status of the 2 checkbox
        Log.i(TAG, "Using_INDEX Music Checkbox State: "+ (solo.isCheckBoxChecked(0)? "Checked": "unChecked")+
                ", Hints Checkbox State: "+ (solo.isCheckBoxChecked(1)? "Checked": "unChecked") );

//logging with the use of isCheckBoxChecked(String)
//this method always give me false, which is a pain in the head
        Log.i(TAG, "Using_TEXT Music Checkbox State: "+ (solo.isCheckBoxChecked("Music")? "Checked": "unChecked")+
                ", Hints Checkbox State: "+ (solo.isCheckBoxChecked("Hints")? "Checked": "unChecked") );

//check if boolean actual does return true or false, just for checking
//purposes
        Log.i(TAG, "actual value: "+(actual?"true":"false"));
        assertEquals("Both Music and Hints ChkBox option are disabled", expected, actual);

        solo.goBackToActivity("Sudoku");

    }

I know that the default android Checkbox extends TextView, then why not use 
those label/text to know if the Checkbox/es that will be asserted contains the 
right value. :(

I any case that the isCheckBoxChecked(String) is of any use, please give me 
some sample code in order for me to know what kind of label of the checkbox it 
search for it to return something real, not an inevitable boolean false.

Regards,
Mark 

Original issue reported on code.google.com by ph3so_...@yahoo.com on 20 Apr 2011 at 12:23

Attachments:

GoogleCodeExporter commented 9 years ago
Have you tried to set the lable of the checkbox in the application that you are 
testing? In the xml file were you define them.

Original comment by renasr...@gmail.com on 20 Apr 2011 at 7:35

GoogleCodeExporter commented 9 years ago
yup, in fact, it is initially labeled through the main.xml and strings.xml

settings.xml:

    <CheckBoxPreference android:key="music"
        android:title="@string/music_title" android:summary="@string/music_summary"
        android:defaultValue="true" />
    <CheckBoxPreference android:key="hints"
        android:title="@string/hints_title" android:summary="@string/hints_summary"
        android:defaultValue="true" />

strings.xml:

<string name="music_title">Music</string>
<string name="music_summary">Play background music</string>
<string name="hints_title">Hints</string>
<string name="hints_summary">Show hints during play</string>

if I am right, android:title="@string/hints_title"  and 
android:title="@string/music_title" would be its label. so its predefined.

Original comment by ph3so_...@yahoo.com on 20 Apr 2011 at 8:01

GoogleCodeExporter commented 9 years ago
Would it be possible for you to email me your application?

Original comment by renasr...@gmail.com on 20 Apr 2011 at 8:05

GoogleCodeExporter commented 9 years ago
Mr. Renas - sensei,

the file attached above, which is the "Android Sudoku Test.zip" already 
contains the test project and the project to be tested.

I hope you will be able to show what my problem was. oh please.. :D

Regards,
Mark

Original comment by ph3so_...@yahoo.com on 20 Apr 2011 at 8:27

GoogleCodeExporter commented 9 years ago
Great. I will have a look at it as soon as I have some time over to see what 
the problem is. 

Original comment by renasr...@gmail.com on 20 Apr 2011 at 8:30

GoogleCodeExporter commented 9 years ago
Thankee thanks.

I hope you will be able to point what my problem was and also, to correct if 
there has been a misunderstanding im my part.

-Mark

Original comment by ph3so_...@yahoo.com on 20 Apr 2011 at 9:34

GoogleCodeExporter commented 9 years ago
You will need to use checkBox.setText() in your application in order for this 
method to work correctly. What Robotium sees now when doing a getText() is an 
empty string and therefore it returns false. 

Original comment by renasr...@gmail.com on 20 Apr 2011 at 10:46

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
So your saying that the one in the CheckboxPreference(title) within the 
settings.xml is not its label?

whoa.

ok, will try the one that you pointed out. 
and will reply once i tried it. thanks

-mark

Original comment by ph3so_...@yahoo.com on 20 Apr 2011 at 2:01

GoogleCodeExporter commented 9 years ago
If setText() is not used, getText() will not return any value. 

Original comment by renasr...@gmail.com on 21 Apr 2011 at 5:46