Letractively / aost

Automatically exported from code.google.com/p/aost
Other
1 stars 0 forks source link

allow Tellurium IDE to generate regular expression for text partial match #457

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
                ui.Form(uid: "Form", clocator: [tag: "form", method: "GET", action: "list"]){
                                Selector(uid: "Can", clocator: [tag: "select", direct: "true", name: "can", id: "can"])
                                InputBox(uid: "Searchq", clocator: [tag: "input", type: "text", name: "q", id: "searchq"])
                                SubmitButton(uid: "Search", clocator: [tag: "input", direct: "true", type: "submit", value: "Search"])
                        }

                ui.Container(uid: "Mt", clocator: [tag: "table", id: "mt"]){
                                UrlLink(uid: "Wiki", clocator: [tag: "a", text: "Wiki"])
                                UrlLink(uid: "ProjectHome", clocator: [tag: "a", text: "Project<A0>Home"])
                                UrlLink(uid: "Downloads", clocator: [tag: "a", text: "Downloads"])
                                UrlLink(uid: "Issues", clocator: [tag: "a", text: "Issues"])
                                UrlLink(uid: "Source", clocator: [tag: "a", text: "Source"])
                                UrlLink(uid: "Administer", clocator: [tag: "a", text: "Administer"])
                        }

                connectSeleniumServer()
                connectUrl "http://code.google.com/p/aost/downloads/list"
                select "Form.Can", "label=regexp:\sCurrent downloads"
                select "Form.Can", "label=regexp:\sFeatured downloads"
                select "Form.Can", "label=regexp:\sFeatured downloads"
                type "Form.Searchq", "test"
                click "Form.Search"
                waitForPageToLoad 30000

                click "Mt.Wiki"
                waitForPageToLoad 30000

consider the option selector function

Recorder.prototype.getOption = function(option) {
    var label = option.text.replace(/^ *(.*?) *$/, "$1");
    if (label.match(/\xA0/)) { // if the text contains &nbsp;
        return "label=regexp:" + label.replace(/[\(\)\[\]\\\^\$\*\+\?\.\|\{\}]/g, function(str) {return '\\' + str})
                                      .replace(/\s+/g, function(str) {
                if (str.match(/\xA0/)) {
                    if (str.length > 1) {
                        return "\\s+";
                    } else {
                        return "\\s";
                    }
                } else {
                    return str;
                }
            });
    } else {
        return "label=" + label;
    }
};

Original issue reported on code.google.com by John.Jian.Fang@gmail.com on 8 Aug 2010 at 5:22

GoogleCodeExporter commented 8 years ago
Builder.prototype.getText = function(node) {
    var txt = null;
    if (getNodeType(node) == constants.ELEMENT_TYPE_NODE) {
        if (node.childNodes.length > 0) {
            for (var i = 0; i < node.childNodes.length; i++) {
                if (node.childNodes[i].nodeType == Node.TEXT_NODE) {
                    txt = node.childNodes[i].nodeValue;
                    if (txt != null) {
                        //test if the regular expression includes "
                        var regexp = new RegExp(/\"/);
                        if(regexp.test(txt)){
                            //if we do have double quota " inside
                            //throw away the text attribute because if it is way too difficult to escape
                            txt = null;
                        }else{
                            txt = this.getTextReg(txt);
                        }

                    }

                    break;
                }
            }
        }
    }

    return txt;
};

Builder.prototype.getTextReg = function(txt) {
    var text = txt.replace(/^ *(.*?) *$/, "$1");
    if (text.match(/\xA0/)) { // if the text contains  
        return "regexp:" + text.replace(/[\(\)\[\]\\\^\$\*\+\?\.\|\{\}]/g, function(str) {return '\\' + str})
                                      .replace(/\s+/g, function(str) {
                if (str.match(/\xA0/)) {
                    if (str.length > 1) {
                        return "\\s+";
                    } else {
                        return "\\s";
                    }
                } else {
                    return str;
                }
            });
    } else {
        return text;
    }
};

Original comment by John.Jian.Fang@gmail.com on 14 Aug 2010 at 3:53