Example #1
0
        public static string formatJsCode(this WatiN_IE ie, string codeToFormat)
        {
            if (ie.url().not_Equal("about:blank"))
            {
                "opening ABOUT:Blank".info();
                ie.open("about:blank");
            }
            else
            {
                "already in ABOUT:Blank".info();
            }

            if (ie.js_FunctionExists("js_beautify").isFalse())
            {
                var jsBeautify = @"beautify.js".local();
                ie.eval(jsBeautify.fileContents());
                if (ie.js_FunctionExists("js_beautify"))
                {
                    "Injected beautify.js into about:blank".info();
                }
                else
                {
                    "Failed to Inject js_beautify code".error();
                }
            }
            "formating Javascript with size: {0}".info(codeToFormat.size());
            ie.setJsObject(codeToFormat);
            ie.eval("window.external.setJsObject(js_beautify(_jsObject))");
            var result = ie.getJsObject().str().fix_CRLF();

//			"formated Javascript has size: {0}".info(result.size());
            return(result);
        }
Example #2
0
        public static WatiN_IE view_JavaScriptVariable_AsTreeView(this WatiN_IE ie, string rootVariableName)
        {
            var treeView = "Javascript variable: {0}".format(rootVariableName).popupWindow(500, 400).add_TreeView();

            Action <TreeNode, string> add_Object =
                (treeNode, objRef) => {
                var _jsObject = ie.getJsObject(objRef);
                if (_jsObject is IEnumerable)
                {
                    foreach (var item in _jsObject as IEnumerable)
                    {
                        treeNode.add_Node(item.comObject_TypeName(), item, true);
                    }
                }
                else
                {
                    treeNode.add_Node(_jsObject);
                }
            };

            treeView.beforeExpand <object>(
                (treeNode, _object) => {
                if (_object is IEnumerable)
                {
                    foreach (var item in _object as IEnumerable)
                    {
                        treeNode.add_Node(item.comObject_TypeName(), item, true);
                    }
                }
                else
                {
                    ie.setJsObject(_object);
                    foreach (var variableName in ie.javascript_ObjectItems("_jsObject"))
                    {
                        var variableValue = ie.javascript_VariableValue("_jsObject.{0}".format(variableName));
                        if (variableValue.typeFullName() == "System.__ComObject")
                        {
                            treeNode.add_Node(variableName, variableValue, true);
                        }
                        else
                        {
                            var nodeText = "{0}: {1}".format(variableName, variableValue);
                            //add_Object(treeNode, "_jsObject.{0}".format(item));
                            treeNode.add_Node(nodeText);
                        }
                    }
                }
            });

            add_Object(treeView.rootNode(), rootVariableName);
            return(ie);
        }
Example #3
0
 public static object waitForJsVariable(this WatiN_IE watinIe, string jsCommand, int sleepMiliseconds, int maxSleepTimes)
 {
     "[WatiN_IE][waitForJsVariable] trying to find jsObject called '{0}' for {1} x {2} ms".info(jsCommand, maxSleepTimes, sleepMiliseconds);
     watinIe.setJsObject(null);
     for (var i = 0; i < maxSleepTimes; i++)
     {
         if (watinIe.doesJsObjectExists(jsCommand))
         {
             var jsObject = watinIe.getJsObject(jsCommand);
             "[watinIe][waitForJsVariable] got value: {0} ({1} tries)".info(jsObject, i);
             return(jsObject);
         }
         watinIe.sleep(500, false);
     }
     "[WatiN_IE][waitForJsVariable] didn't find jsObject called '{0}' after {1} sleeps of {2} ms".error(jsCommand, maxSleepTimes, sleepMiliseconds);
     return(null);
 }
Example #4
0
        public static object waitForJsObject(this WatiN_IE watinIe, int sleepMiliseconds, int maxSleepTimes)
        {
            "[WatiN_IE][waitForJsObject] trying to find jsObject for {0} x {1} ms".info(maxSleepTimes, sleepMiliseconds);
            watinIe.setJsObject(null);
            for (var i = 0; i < maxSleepTimes; i++)
            {
                var jsObject = watinIe.getJsObject();
                if (jsObject.notNull())
                {
                    "[watinIe][waitForJsObject] got value: {0} (n tries)".info(jsObject, i);
                    return(jsObject);
                }

                watinIe.sleep(500, false);
            }
            "[WatiN_IE][waitForJsObject] didn't find jsObject after {0} sleeps of {1} ms".error(maxSleepTimes, sleepMiliseconds);
            return(null);
        }