⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parameter.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                str += " X=" + element[i].getAttribute("valueX")                       +" Y=" + element[i].getAttribute("valueY");                        if (element[i].hasAttribute("disabled"))                str += " disabled";                        str += ">";                            if (i == selected)               str += " active";            str += "\n";        }                // strip off the last \n and return        return str.substring(0, str.length() - 1);    }        public void setValue(String value)throws InvalidParameterValueException    {        // need to verify value is a valid submit button        int indx = value.indexOf('=');                if (indx == -1 )             throw new InvalidParameterValueException(value);                String n = value.substring(0,indx);        String v = value.substring(indx+1);                for (int i = 0; i < element.length; i++)        {            if (element[i].getType().equalsIgnoreCase("SUBMIT"))            {                // select the submit button                if ( v.equals(element[i].getAttribute("value"))                      && n.equals(element[i].getAttribute("name"))                      && !element[i].hasAttribute("disabled") )                {                    if (selected != -1)                        element[selected].removeAttribute(ACTIVE);                        selected = i;                    element[selected].setAttribute(ACTIVE,"");                                        return;                }            }            else            {                // IMAGE - set the coord for the image and select it                if ( n.equals(element[i].getAttribute("name"))                      && !element[i].hasAttribute("disabled") )                {                    if (v.indexOf(',') == -1)                        throw new InvalidParameterValueException(v);                    if (v.substring(0,v.indexOf(',')).                         equals(element[i].getAttribute("value")))                    {                        String coord = v.substring(v.indexOf(',') + 1);                                                if (coord.indexOf(',') == -1)                            throw new InvalidParameterValueException(v);                                                    String x = coord.substring(0,coord.indexOf(','));                        String y = coord.substring(coord.indexOf(',') + 1);                            if (selected != -1)                            element[selected].removeAttribute(ACTIVE);                            selected = i;                        element[selected].setAttribute(ACTIVE,"");                        element[i].setAttribute("valueX", x);                        element[i].setAttribute("valueY", y);                                        return;                    }                }            }        }        throw new InvalidParameterValueException(value + ". unknown option");    }    public String getValue()    {        if (element.length == 0)            return "No submit inputs";            if (selected == -1)            return "";                        String coord = "";                if (element[selected].getType().equalsIgnoreCase("image"))            coord = "," + element[selected].getAttribute("valueX")                   + "," + element[selected].getAttribute("valueY");                    return element[selected].getAttribute("name") + "="                 + element[selected].getAttribute("value") + coord;    }        public void reset()    {        if (selected == -1)            return;                selected = -1;                for (int i = 0; (selected == -1) && (i < element.length); i++)        {            String value = element[i].getAttribute("value");                            // if it is an IMAGE element set a default location            if (element[i].getType().equalsIgnoreCase("IMAGE"))            {                element[i].setAttribute("valueX","<valueX>");                element[i].setAttribute("valueY","<valueY>");                value = value +",<valueX>,<valueY>";            }                            try            {                    setValue(element[i].getAttribute("name") + "="                         + value);            }            catch (InvalidParameterValueException e)            {/* Ignore this and try again on the next loop */}        }    }    public HashMap getSummary()    {        HashMap map = new HashMap();                map.put(NAME, name);        map.put(TYPE, getType());        map.put(VALUE, getValue());                if (selected == -1)        {            map.put(DISABLED, "");            map.put(READONLY, "");        }        else        {            map.put(DISABLED, "No");            map.put(READONLY, "No");        }        List possibleValuesList = new ArrayList();        for (int i = 0; i < element.length; i++)        {            String coord = "";            if (element[i].getType().equalsIgnoreCase("image"))            {                coord = "," + "<valueX>" + "," + "<valueY>";            }            String str = element[i].getAttribute("name") + "=" +                         element[i].getAttribute("value") + coord;            possibleValuesList.add(str);        }        map.put(POSSIBLEVALUES, possibleValuesList);        return map;        }        public Vector[] paramString()    {        if (element.length == 0 || !use ||            // the selected element has no name or value            ( element[selected].getAttribute("name").equals("") &&               element[selected].getAttribute("value").equals("")))            // there is no valid parameter to submit            return new Vector[0];                Vector[] params;                    String value = element[selected].getAttribute("value");                if (element[selected].getType().equalsIgnoreCase("image"))        {                int i = 3;            if (value.equals(""))                 i--;            // deal with image                    params = new Vector [i];                                        params[0] = new Vector();            params[0].addElement(element[selected].getAttribute("name") + ".x");            params[0].addElement(element[selected].getAttribute("valueX"));                        params[1] = new Vector();            params[1].addElement(element[selected].getAttribute("name") + ".y");            params[1].addElement(element[selected].getAttribute("valueY"));                        if (i == 3)            {                params[2] = new Vector();                params[2].addElement(element[selected].getAttribute("name"));                params[2].addElement(value);            }        } else        {            // deal with button            params = new Vector [1];                        params[0] = new Vector();            params[0].addElement(element[selected].getAttribute("name"));            params[0].addElement(value);        }        return params;    }    } // end class SubmitGroup/*****************************************************************************//*                                                                           *//* Class: MultipleSelect                                                     *//* Description: This class provides the handle to manipulate html form       *//*              select controls.                                             *//*                                                                           *//*****************************************************************************/class MultipleSelect extends Parameter{    HTMLOptionElementImpl [] options;    HTMLSelectElement element;    boolean multiple;    int numSelected;    /*****************************************************************************//*                                                                           *//* Method: Constructor                                                       *//* Description: Constructor method                                           *//* Parameter: element - HTMLSelectElement that will be wrapped by this class *//*                      to manipulate the control                            *//*                                                                           *//*****************************************************************************/            public MultipleSelect (HTMLSelectElement element)    {        name = element.getName();        type = "select";        this.element = element;            use = ! element.getDisabled();                HTMLCollection theOptions = element.getOptions();        numSelected = 0;        int size = theOptions.getLength();                options = new HTMLOptionElementImpl[size];        for (int i = 0; i < size; i++)         {                options[i] = (HTMLOptionElementImpl) theOptions.item(i);                                    if (options[i].getSelected() && !options[i].getDisabled())            {                numSelected ++;                                if (! element.getForm().hasAttribute(WebForm.VISITED))                    options[i].setDefaultSelected(true);            }        }                multiple = element.getMultiple();    }    public String toString()    {        String str = "<select name=" + name;                if (multiple)            str += " multiple";                str +=">\n";                for (int i = 0; i < options.length; i++)        {            str += "<option value = " + options[i].getValue();                        if (options[i].getSelected())               str += " selected";                           if (options[i].getDisabled())                str += " disabled";                        str += " />\n";        }                str += "</select>";                return str;    }            public void setValue(String value) throws InvalidParameterValueException    {        // need to verify value is a valid select option            // need to verify multiple        for (int i = 0; i < options.length; i++)        {            if (value.equals(options[i].getValue()))                    if(! options[i].getReadOnly())                    if(! options[i].getDisabled())                    {                        if (options[i].getSelected())                        {                            options[i].setSelected(false);                            numSelected --;                        }                        else if (multiple || numSelected == 0)                        {                            options[i].setSelected(true);                            numSelected ++;                        }else                        {                            throw new InvalidParameterValueException                            (value +". Deselect " + getValue() +                              " before setting a new value");                        }                        return;                    }                    else                        throw new InvalidParameterValueException                                   (value + ". disabled");                else                    throw new InvalidParameterValueException                               (value + ". readonly");                    }        throw new InvalidParameterValueException(value + ". unknown option");    }// multiple values are \n delimited    public String getValue()    {        String str = "";        int i=0;        int j=0;                if (numSelected == 0)            return str;                for ( ; (i < numSelected) && (j < options.length); j++)        {            if (options[j].getSelected())            {                str += options[j].getValue() + "\n";            }        }        return str.substring(0,str.length() - 1);    }        public void reset()    {        for (int i = 0; i < options.length; i++)         {                options[i].setSelected(options[i].getDefaultSelected());        }    }    public HashMap getSummary()    {        HashMap map = new HashMap();                map.put(NAME, name);        if (multiple)            type += " multiple";        map.put(TYPE, type);        map.put(VALUE, getValue());        if (element.getDisabled())            map.put(DISABLED, "Yes");        else            map.put(DISABLED, "No");        if (element.hasAttribute("readonly"))            map.put(READONLY, "Yes");        else            map.put(READONLY, "No");                List possibleValuesList = new ArrayList();        for (int i = 0; i < options.length; i++)        {            if (!options[i].getSelected())            {                String str = options[i].getValue();                                            possibleValuesList.add(str);            }        }        map.put(POSSIBLEVALUES, possibleValuesList);                return map;        }        public Vector[] paramString()    {        if (!use)            return new Vector[0];                    Vector[] params = new Vector [numSelected];                int i=0;        int j=0;        for ( ; (i < numSelected) && (j < options.length); j++)        {            if (options[j].getSelected() &&                !options[j].getDisabled() )            {                params[i] = new Vector();                params[i].addElement(name);                params[i].addElement(options[j].getValue());                i++;            }        }        return params;    }}// end class MultipleSelect

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -