mosil / robotium

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

WebElement createWebElementAndSetLocation ArrayIndexOutOfBoundsException #504

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. While using solo.waitForText("example") in some circumstances, such as 
waiting for text with this library 
http://www.androidviews.net/2012/11/changelog-library/

What is the expected output? What do you see instead?
Will find the text, but throws ArrayIndexOutOfBoundsException at 

elements = data[9].split("\\#\\$"); 

in WebElementCreator.createWebElementAndSetLocation

What version of the product are you using? On what operating system?
Robotium 4.2.1-SNAPSHOT, Android 4.3 and Android 2.3.

Please provide any additional information below.
This problem started when I switched to the source code version 4.2.1, it was 
working fine with the prebuilt version 4.2.

My solution was to create the elemments varaible before the try - catch and put 
the elements = data[9].split("\\#\\$"); within the try - catch.

Example code: 

private WebElement createWebElementAndSetLocation(String information, WebView 
webView){
        String[] data = information.split(";,");
        int x = 0;
        int y = 0;
        int width = 0;
        int height = 0;
        Hashtable<String, String> attributes = new Hashtable<String, String>();
        String[] elements = {};
        try{
            x = Math.round(Float.valueOf(data[5]));
            y = Math.round(Float.valueOf(data[6]));
            width = Math.round(Float.valueOf(data[7]));
            height = Math.round(Float.valueOf(data[8]));    
            elements = data[9].split("\\#\\$");

        }catch(Exception ignored){}

        for (int index = 0; index < elements.length; index++){
            String[] element = elements[index].split("::");
            if (element.length > 1) {
                attributes.put(element[0], element[1]);
            } else {
                attributes.put(element[0], element[0]);
            }
        }

        WebElement webElement = null;

        try{
            webElement = new WebElement(data[0], data[1], data[2], data[3], data[4], attributes);
            setLocation(webElement, webView, x, y, width, height);
        }catch(Exception ignored) {}

        return webElement;
    }

Original issue reported on code.google.com by casey.d....@gmail.com on 25 Aug 2013 at 12:53

GoogleCodeExporter commented 9 years ago
Thanks a lot for reporting this. It will be fixed in time for the next release.

Original comment by renasr...@gmail.com on 25 Aug 2013 at 5:32

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

Original comment by renasr...@gmail.com on 9 Sep 2013 at 5:16