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

📄 parameter.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        use = element.getChecked();                if (! element.getForm().hasAttribute(WebForm.VISITED))            element.setDefaultChecked(use);        //System.out.println(name + " " + element.getDefaultChecked() +         //                   " " + element.getChecked());    }        public String toString()    {        String str = "<" + type + " name = " + name + " value = " +                      element.getAttribute("value");                if (use)            str += " checked";                       if (element.getDisabled())            str += " disabled";                        if (element.getReadOnly())            str += " readonly";                str += " >";                return str;    }    public void setValue(String value) throws InvalidParameterValueException    {        if (element.getReadOnly())                throw new InvalidParameterValueException                           (getKey() + ". readonly");        if (element.getDisabled())                throw new InvalidParameterValueException                           (getKey() + ". disabled");                if (value.equalsIgnoreCase("CHECKED"))            use = true;                    else if (value.equalsIgnoreCase("UNCHECKED"))            use = false;                else            throw new InvalidParameterValueException(value);                    element.setChecked(use);    }            public String getValue()    {        if (use)            return "CHECKED";                    return "UNCHECKED";        }    public String getKey()    {        return name + "=" + element.getAttribute("value");    }        public void reset()    {        element.setChecked(element.getDefaultChecked() );    }    public HashMap getSummary()    {        HashMap map = new HashMap();                map.put(NAME, getKey());        map.put(TYPE, type);        map.put(VALUE, getValue());        if (element.getDisabled())            map.put(DISABLED, "Yes");        else            map.put(DISABLED, "No");        if (element.getReadOnly())            map.put(READONLY, "Yes");        else            map.put(READONLY, "No");                return map;        }        public Vector[] paramString()    {        if (!use || element.getDisabled())            return new Vector[0];                    Vector[] params = new Vector [1];                params[0] = new Vector();        params[0].addElement(name);        params[0].addElement(element.getAttribute("value"));                return params;    }}// end class CheckBox/*****************************************************************************//*                                                                           *//* Class: RadioGroup                                                         *//* Description: This class provides the handle to manipulate html form       *//*              input type radio controls.                                   *//*                                                                           *//*****************************************************************************/class RadioGroup extends Parameter{    HTMLInputElement[] element;    int selected;    /*****************************************************************************//*                                                                           *//* Method: Constructor                                                       *//* Description: Constructor method                                           *//* Parameter: radioList - a list of HTMLInputElemets of type radio           *//*                                                                           *//*****************************************************************************/        public RadioGroup (Vector radioList)    {        name = ((HTMLInputElement) radioList.elementAt(0)).getName();        type = "input type=radio";                int size = radioList.size();                element = new HTMLInputElement[size];        selected = -1;                for (int i = 0; i < size; i++)        {            element[i] = (HTMLInputElement) radioList.elementAt(i);                                                   if (element[i].getChecked() && !element[i].getDisabled())            {                selected = i;                                if (! element[0].getForm().hasAttribute(WebForm.VISITED))                    element[i].setDefaultChecked(element[i].getChecked());            }        }                use = (selected != -1);    }        public String toString()    {        if (element.length == 0)            return "";                    String str = "";        for (int i = 0; i < element.length; i++)        {            str += "<" + type + " name = " + name + " value = "                 + element[i].getValue();                        if (i == selected)               str += " checked";                           if (element[i].getDisabled())                str += " disabled";                            if (element[i].getReadOnly())                str += " readonly";                            str += " >\n";        }                // strip off the last \n and return        return str.substring(0, str.length() - 1);    }        public void setValue(String value) throws InvalidParameterValueException    {        // verify the new value is a valid radio button            for (int i = 0; i < element.length; i++)        {            if (value.equals(element[i].getValue()))                if (!element[i].getDisabled())                    if (!element[i].getReadOnly())                    {                        if (selected != -1)                            element[selected].setChecked(false);                                                    selected = i;                        element[selected].setChecked(true);                        use = true;                            return;                    }                    else                        throw new InvalidParameterValueException(value                                                                + ". readonly");                else                    throw new InvalidParameterValueException(value                                                                + ". disabled");        }        throw new InvalidParameterValueException(value + ". unknown option");    }        public String getValue()    {        try        {            return element[selected].getValue();        }        catch (ArrayIndexOutOfBoundsException e)        {            // indicates no value selected for the radio control        }        return "";    }    public void reset()    {        selected = -1;                for (int i = 0; i < element.length; i++)        {            element[i].setChecked(element[i].getDefaultChecked());                        if (element[i].getDefaultChecked() && !element[i].getDisabled())                selected = i;        }            }    public HashMap getSummary()    {        HashMap map = new HashMap();                map.put(NAME, name);        map.put(TYPE, type);        map.put(VALUE, getValue());        if (selected == -1)        {            map.put(DISABLED, "");            map.put(READONLY, "");        }        List possibleValuesList = new ArrayList();        for (int i = 0; i < element.length; i++)        {            if (i == selected)            {                if (element[i].getDisabled())                    map.put(DISABLED, "Yes");                else                    map.put(DISABLED, "No");                if (element[i].getReadOnly())                    map.put(READONLY, "Yes");                else                    map.put(READONLY, "No");            }            else            {                String str = element[i].getValue();                if (element[i].getDisabled())                {                    str += "\n(Disabled)";                }                if (element[i].getReadOnly())                {                    str += "\n(Readonly)";                }                                            possibleValuesList.add(str);            }        }        map.put(POSSIBLEVALUES, possibleValuesList);                return map;        }        public Vector[] paramString()    {            try        {            if (!use || element[selected].getDisabled())                return new Vector[0];                    Vector[] params = new Vector [1];                        params[0] = new Vector();            params[0].addElement(name);            params[0].addElement(getValue());                        return params;        }        catch (ArrayIndexOutOfBoundsException e)        {            //  no radio buttons are selected        }                return new Vector[0];    }    }// end class RadioGroup/*****************************************************************************//*                                                                           *//* Class: SubmitGroup                                                        *//* Description: This class provides the handle to manipulate html form       *//*              input type submit controls.                                  *//*                                                                           *//* SubmitGroup contains a list of all the possible ways a form can be        *//* submitted.  Only one method of submission can be used, therefore only one *//* member of the submit group can be selected at a time.                     *//* There are two html elements that can be used to trigger a form to submit. *//* One is a <input type=submit>.  This is a standard form button that can    *//* have name and value attributes.  The other is a <input type=image>.       *//* This is a client side mapping input.  It can have name, value, and an     *//* image file as attributes.  In addition, to send the name and value        *//* attributes when this type of input is selected, the coordinates in the    *//* image where the user clicked are also sent.  This coordinate information  *//* is genereated when the form is submitted and not stored anywhere prior.   *//*                                                                           *//* Since all information regarding a SubmitGroup element is stored with      *//* the corresponding html element, attributes valueX and valueY are added to *//* an <input type=image> element when they are assigned with a SET command.  *//* Prior to this, the valueX and valueY attributes don't exist and if the    *//* attributes are queried, an empty string should be returned (i.e.          *//* name=value, instead of name=value,<valueX>,<valueY>.  Unselected image    *//* controls would benefit from placeholders, <valueX>,<valueY>, in the two   *//* coordinate location because it indicates that the coordinates are         *//* variable when using the SET command.  The current coords are meaningless  *//* since they are overwritten on the next SET and it may confuse the user    *//* indicating that only certain (0's or the previous) coords are valid.      *//* Not only should uninitialized (no valueX or valueY) IMAGE controls be in  *//* this format when queried, but also all the other possible values for      *//* submitgroup image options should be in this format. The currently         *//* selected submit option, if it is an IMAGE, will show coords in the value  *//* line but show the variable form in the options list.                      *//*                                                                           *//* For example:                                                              *//*   Name             : submit                                               *//*   Type             : Submit group                                         *//*   Disabled         : No                                                   *//*   Read Only        : No                                                   *//*   Value            : pic1=rose,2,3                                        *//*   Possible Value 1 : pic1=rose,<valueX>,<valueY>                          *//*   Possible Value 2 : button1=submit                                       *//*   Possible Value 3 : pic2=tulip,<valueX>,<valueY>                         *//*                                                                           *//*                                                                           *//* Also, in theory, the currently selected submit option should never be     *//* readonly or disabled, since it is not possible to interact with controls  *//* with either attribute.  If a readonly or disabled control becomes         *//* selected, there is a bug.                                                 *//*****************************************************************************/class SubmitGroup extends Parameter{    int selected;    HTMLInputElement[] element;    static final String ACTIVE = "active";    /*****************************************************************************//*                                                                           *//* Method: Constructor                                                       *//* Description: Constructor method                                           *//* Parameter: radioList - a list of HTMLInputElements of type submit and img *//*                                                                           *//*****************************************************************************/        public SubmitGroup (Vector submitList)    {        name = "submit";        type = "input type = ";                selected = -1;                int size = submitList.size();                element = new HTMLInputElement[size];                for (int i = 0; i < size; i++)        {            element[i] = (HTMLInputElement) submitList.elementAt(i);                        if (element[i].hasAttribute(ACTIVE))                selected = i;                            else if (selected == -1)            {                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)                {                    //System.out.println("Invalid Submit value");                }            }        }                use = (selected != -1);    }    public String getType()    {        return "Submit group";    }    public String toString()    {        String str = " ";        for (int i = 0; i < element.length; i++)        {            str += "<" + type + element[i].getAttribute("type") + " name = "                 + element[i].getAttribute("name") + " value = "                 + element[i].getAttribute("value");                        if (element[i].getType().equalsIgnoreCase("image"))

⌨️ 快捷键说明

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