Example #1
0
        public static WatiN_IE.ToCSharp injectJavascriptFunctions(this WatiN_IE ie, bool resetHooks)
        {
            if (ie.WebBrowser.isNull())
            {
                "in InjectJavascriptFunctions, ie.WebBrowser was null".error();
            }
            else
            {
                if (ie.WebBrowser.ObjectForScripting.isNull() || resetHooks)
                {
                    ie.WebBrowser.ObjectForScripting = new WatiN_IE.ToCSharp();

                    "Injecting Javascript Hooks * Functions for page: {0}".debug(ie.url());
                    ie.eval("var o2Log = function(message) { window.external.write(message) };");
                    ie.invokeScript("o2Log", "Test from Javascript (via toCSharp(message) )");
                    ie.eval("$o2 = window.external");
                    "Injection complete (use o2Log(...) or $o2.write(...)  to talk back to O2".info();
                    return(ie.WebBrowser.ObjectForScripting as WatiN_IE.ToCSharp);
                }
                else
                {
                    if ((ie.WebBrowser.ObjectForScripting is WatiN_IE.ToCSharp))
                    {
                        return(ie.WebBrowser.ObjectForScripting as WatiN_IE.ToCSharp);
                    }
                    else
                    {
                        "in WatiN_IE injectJavascriptFunctions, unexpected type in ie.WebBrowser.ObjectForScripting: {0}".error(ie.WebBrowser.ObjectForScripting.typeName());
                    }
                }
            }
            return(null);
        }
Example #2
0
        public static object invokeEval(this WatiN_IE ie, string evalScript)
        {
            var evalParam = "(function() { " + evalScript + "})();";

            //"[WatiN_IE] invokeEval evalParam: {0}".debug(evalParam);
            return(ie.invokeScript("eval", evalParam));
        }
Example #3
0
        public static WatiN_IE show_Formated_Javascript(this WatiN_IE ie, WatiN_IE temp_ie, string codeToFormat)
        {
            var prettifyHtml = @"prettify.htm".local();

            if (prettifyHtml.fileExists().isFalse())
            {
                return(ie);
            }

            if (ie.url().isNull() || ie.url().contains("prettify.htm").isFalse())
            {
                ie.open(prettifyHtml);
            }
            var formatedJsCode = (temp_ie.isNull())
                                     ? ie.HostControl.formatJsCode(codeToFormat)
                                     : temp_ie.formatJsCode(codeToFormat);

            var codeDiv = ie.div("codeDiv");

            codeDiv.innerHtml("<pre id=\"code\" class=\"prettyprint\">{0}</pre>".format(formatedJsCode));
            ie.invokeScript("prettyPrint");
            return(ie);
        }
Example #4
0
 public static object invokeScript(this WatiN_IE ie, string functionName, params object[] parameters)
 {
     //"[WatiN_IE] invokeScript '{0}' with parameters:{1}".info(functionName ,parameters.size());
     return(ie.invokeScript(true, functionName, parameters));
 }
Example #5
0
 public static object invokeScript(this WatiN_IE ie, string functionName)
 {
     return(ie.invokeScript(functionName, null));
 }