namjae / robotium

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

instanceof instead of class name comparison #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Extend a base class such as EditText:

public class MyEditText extends EditText {
...
}

2. Use this class as an EditText view.

3. call solo.getCurrentEditTexts() in a test (or related methods).

What is the expected output? 
A list of MyEditText views.

What do you see instead?
A null list.

What version of the product are you using? On what operating system?
1.3.1 on mac os x / eclipse / android latest

Please provide any additional information below.
This is the result of the following check in ViewFetcher.java:

    public ArrayList<TextView> getCurrentTextViews(View parent) {
... cut ..
            if (view.getClass().getName().equals("android.widget.TextView")) {
                textViewList.add((TextView) view);
            }
... cut ..          
    }

This only allows classes with that specific class name, not classes that extend 
it. Instead, it would be better to use the runtime "instaceof" 
comparison :

    public ArrayList<TextView> getCurrentTextViews(View parent) {
... cut ..
        if (view.getClass().isInstance(android.widget.TextView.class)) {
                textViewList.add((TextView) view);
        }
... cut ..          
    }

The same applies to the other methods that look for buttons, GridViews, etc.

Original issue reported on code.google.com by jeffreys...@gmail.com on 9 Mar 2010 at 2:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The example there mixes up EditText and TextView but apparently isInstance() 
doesn't do what I thought it did so 
the above won't work. If someone can get it to work I would be very 
appreciative.

Original comment by jeffreys...@gmail.com on 9 Mar 2010 at 3:22

GoogleCodeExporter commented 9 years ago
I will have a look at this.

Original comment by renasr...@gmail.com on 10 Mar 2010 at 9:29

GoogleCodeExporter commented 9 years ago
This has been fixed in Robotium 1.4.0.

Original comment by renasr...@gmail.com on 1 Apr 2010 at 6:40