Пример #1
0
 public SearchLearningService(
     JavascriptExecutor javascriptExecutor,
     ElasticRepository elasticRepository)
 {
     _javascriptExecutor = javascriptExecutor;
     _elasticRepository  = elasticRepository;
 }
        /// <summary>
        /// Wait for all AJAX calls made via jQuery to end
        /// </summary>
        public void waitForJQueryToFinish(int msTimeout)
        {
            Trace.WriteLine("Waiting for Ajax loading to finish");
            DateTime startTime      = DateTime.Now;
            bool     isAjaxFinished = false;
            DateTime endTime        = DateTime.Now.AddMilliseconds(msTimeout);

            try {
                while (isAjaxFinished == false && DateTime.Now < endTime)
                {
                    isAjaxFinished = JavascriptExecutor.Execute <bool>("return jQuery.active == 0");
                    System.Threading.Thread.Sleep(100);
                }
            } catch (WebDriverException ex) {
                // Sometimes we'll hit the exception Unexpected error. ReferenceError: jQuery is not defined
                // We may want to change this to retry since it might take time for jQuery to be defined?
                Trace.WriteLine("Recieved the following exception: " + ex.Message);
                return;
            }
            if (isAjaxFinished == false)
            {
                throw new Exception("Timeout period of " + msTimeout + "ms expired for JQuery to finish.");
            }
            Trace.WriteLine("Ajax finished executing in " + (DateTime.Now - startTime).TotalMilliseconds + "ms");
        }
        public List <string> GetSideFilterOptionsByHeader(string header)
        {
            var options = JavascriptExecutor.FindElements(string.Format(HomePageObjects.SideFilterListCssTemplate, header))
                          .Select(x => x.Split('\n')[0]).ToList();

            return(options);
        }
Пример #4
0
        public ScriptRunTest()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Url = "https://www.google.com/";

            _javascriptExecutor = JavascriptExecutor.Create(new JavascriptRuntime((IJavaScriptExecutor)driver));
        }
Пример #5
0
        static void Main(string[] args)
        {
            // we build a ChromeDriver instance
            ChromeDriver driver = new ChromeDriver();

            driver.Url = "https://www.google.com/";

            //IWebDriver driver = null;

            // then we build a JavascriptExecutor instance, where it'll manage and create the dynamic
            // object.
            var jsExecutor = JavascriptExecutor.Create(new JavascriptRuntime((IJavaScriptExecutor)driver));

            // we start a new dynamic object of js. Now we can execute javascript through C#.
            // internally, it will parse the data and execute the script.
            dynamic js = jsExecutor.GetDynamicJs();

            // outputs a message to browser's console.
            // Execute() method is defined under MethodExecutor class.
            // Execute() shall run and not return anything.
            js.console.log("Hello world").Execute();

            // simple arithmetic operations
            // arithmetic operations are done on c# side.
            // TODO: Define either the developer wants it to be run on C# (slower) or on Javascript.
            // we define these values on browser.
            js.val1 = 10;
            js.val2 = 20;

            // it does the math of (val2 / 2) + val1 on c#.
            Int64 math = js.val1 + js.val2 / 2;

            // and then send the value to browser's console log
            js.console.log(math).Execute();

            // we can also define the value directly in javascript
            js.name = "John Doe";

            // and then send to javascript.
            // js.name will never be returned to C#, it will send directly the command to javascript
            // to execute the data (as javascript already has this member set).
            js.console.log(js.name).Execute();

            // now we are using the method substring of Javascript to get a part of the string defined
            // in javascript (js.name). It shall get only "John".
            // we have defined this in a local C# variable.
            // ExecuteReturn will execute the method and return its value.
            // TODO: Make it type-safe.
            string firstName = js.name.substring(0, 4).ExecuteReturn();

            // Now we output the value to C# and output to browser's output
            Console.WriteLine(firstName);
            js.console.log(firstName).Execute();

            // Done.
            Console.ReadKey();
        }
Пример #6
0
        private void OnJavascriptUncaughException(object sender, JavascriptUncaughtExceptionEventArgs e)
        {
            if (JavascriptExecutor.IsInternalException(e.Message))
            {
                // ignore internal exceptions, they will be handled by the EvaluateScript caller
                return;
            }
            var javascriptException = new JavascriptException(e.Message, e.StackFrames);

            ForwardUnhandledAsyncException(javascriptException, e.Frame.Name);
        }
Пример #7
0
            public void OnUncaughtException(IWebBrowser browserControl, IBrowser browser, IFrame frame, CefSharp.JavascriptException exception)
            {
                if (JavascriptExecutor.IsInternalException(exception.Message))
                {
                    // ignore internal exceptions, they will be handled by the EvaluateScript caller
                    return;
                }
                var javascriptException = new JavascriptException(exception.Message, exception.StackTrace);

                OwnerWebView.ForwardUnhandledAsyncException(javascriptException, frame.Name);
            }
            public void OnUncaughtException(IWebBrowser browserControl, IBrowser browser, IFrame frame, CefSharp.JavascriptException exception)
            {
                if (JavascriptExecutor.IsInternalException(exception.Message))
                {
                    // ignore internal exceptions, they will be handled by the EvaluateScript caller
                    return;
                }
                var javascriptException = new JavascriptException(
                    exception.Message,
                    exception.StackTrace.Select(l => {
                    var location = l.SourceName + ":" + l.LineNumber + ":" + l.ColumnNumber;
                    return(JavascriptException.AtSeparator + (string.IsNullOrEmpty(l.FunctionName) ? location : l.FunctionName + " (" + location + ")"));
                }).ToArray());

                OwnerWebView.ForwardUnhandledAsyncException(javascriptException);
            }
Пример #9
0
        private void Initialize()
        {
            InitializeCef();

            if (!subscribedApplicationExit)
            {
                // subscribe exit again, first time might have failed if Application.Current was null
                Application.Current.Exit += OnApplicationExit;
                subscribedApplicationExit = true;
            }

            settings        = new BrowserSettings();
            lifeSpanHandler = new CefLifeSpanHandler(this);

            chromium = new InternalChromiumBrowser();
            chromium.BrowserSettings              = settings;
            chromium.IsBrowserInitializedChanged += OnWebViewIsBrowserInitializedChanged;
            chromium.FrameLoadEnd               += OnWebViewFrameLoadEnd;
            chromium.LoadError                  += OnWebViewLoadError;
            chromium.TitleChanged               += OnWebViewTitleChanged;
            chromium.PreviewKeyDown             += OnPreviewKeyDown;
            chromium.RequestHandler              = new CefRequestHandler(this);
            chromium.ResourceHandlerFactory      = new CefResourceHandlerFactory(this);
            chromium.LifeSpanHandler             = lifeSpanHandler;
            chromium.RenderProcessMessageHandler = new CefRenderProcessMessageHandler(this);
            chromium.MenuHandler                 = new CefMenuHandler(this);
            chromium.DialogHandler               = new CefDialogHandler(this);
            chromium.DownloadHandler             = new CefDownloadHandler(this);
            chromium.CleanupElement              = new FrameworkElement(); // prevent chromium to listen to default cleanup element unload events, this will be controlled manually

            jsExecutor = new JavascriptExecutor(this);

            RegisterJavascriptObject(Listener.EventListenerObjName, eventsListener);

            Content = chromium;

            GlobalWebViewInitialized?.Invoke(this);

            DisposableWebViews.Add(this);

            FocusManager.SetIsFocusScope(this, true);
            FocusManager.SetFocusedElement(this, FocusableElement);
        }
Пример #10
0
        /// <summary>
        /// Wait for page load.  Use if Selenium blocking API is not sufficient.
        /// </summary>
        public static void WaitForPageLoad(int msTimeout)
        {
            RetriableRunner.Run(() => {
                var isPageLoaded = false;
                var endTime      = DateTime.Now.AddMilliseconds(msTimeout);

                while (isPageLoaded == false && DateTime.Now < endTime)
                {
                    isPageLoaded = JavascriptExecutor.Execute <string>("return document.readyState").Equals("complete");
                    System.Threading.Thread.Sleep(100);
                }

                if (isPageLoaded == false)
                {
                    throw new Exception("Timeout period of " + msTimeout + "ms expired for page load to finish.");
                }

                return(string.Empty);
            });
        }
Пример #11
0
        private JavascriptExecutor GetJavascriptExecutor(string frameName)
        {
            if (isDisposing)
            {
                return(null);
            }

            lock (JsExecutors) {
                if (isDisposing)
                {
                    return(null);
                }

                var frameNameForIndex = frameName ?? "";
                if (!JsExecutors.TryGetValue(frameNameForIndex, out var jsExecutor))
                {
                    jsExecutor = new JavascriptExecutor(this, this.GetFrame(frameName));
                    JsExecutors.Add(frameNameForIndex, jsExecutor);
                }
                return(jsExecutor);
            }
        }
        /// <summary>
        /// Wait for page load.  Use if Selenium blocking API is not sufficient.
        /// </summary>
        public void WaitForPageLoad(int msTimeout = 5000)
        {
            Trace.WriteLine("Waiting for page load.");
            DateTime startTime    = DateTime.Now;
            Boolean  isPageLoaded = false;
            DateTime endTime      = DateTime.Now.AddMilliseconds(msTimeout);

            try {
                while (isPageLoaded == false && DateTime.Now < endTime)
                {
                    isPageLoaded = JavascriptExecutor.Execute <string>("return document.readyState").Equals("complete");
                    System.Threading.Thread.Sleep(100);
                }
            } catch (WebDriverException ex) {
                Trace.WriteLine("Recieved the following exception: " + ex.Message);
                return;
            }
            if (isPageLoaded == false)
            {
                throw new Exception("Timeout period of " + msTimeout + "ms expired for page load to finish.");
            }
            Trace.WriteLine("Page load finished executing in " + (DateTime.Now - startTime).TotalMilliseconds + "ms");
        }
 public bool IsEmailAddressOfContactPresent() =>
 JavascriptExecutor.FindElement(ProductDetailPageObject.EmailCssSelector).Text.Contains("*****@*****.**");
 public bool ISContactLocationPresent() =>
 JavascriptExecutor.IsElementPresent(ProductDetailPageObject.ContactLocationCssSelector);
 public bool IsMailIconPresentInContact() =>
 JavascriptExecutor.IsElementPresent(ProductDetailPageObject.ContactEmailIconCssSelector);
 //footer
 public bool IsFooterHeaderPresentByFooterName(string name) =>
 JavascriptExecutor.IsElementPresent(string.Format(ProductDetailPageObject.FooterHeaderCssTemplate, name));
 public List <string> GetQuickLinks() =>
 JavascriptExecutor.FindElements(ProductDetailPageObject.QuickLinksListCssSelector);
 /// <summary>
 /// Javascript business rules bridge ctor
 /// </summary>
 internal JavascriptEngineBridge(JavascriptExecutor owner)
 {
     this.m_owner      = owner;
     this.m_adhocCache = ApplicationServiceContext.Current.GetService <IAdhocCacheService>();
 }
 public bool IsAccountWishlistIconPresentByIconName(string icon) =>
 JavascriptExecutor.IsElementPresent(string.Format(HomePageObjects.AccountWishlistCssTemplate, icon));
Пример #20
0
 public string GetEmailAddressOfContact() =>
 JavascriptExecutor.FindElement(ProductDetailPageObject.EmailCssSelector).Text;
 public bool IsAddtionalLinksPresentByLinkName(string name) =>
 JavascriptExecutor.IsElementPresent(string.Format(ProductDetailPageObject.AdditionalLinkCssTemplate, name));
Пример #22
0
 public void ClickSideFilterByHeader(string header) => JavascriptExecutor
 .FindElement(string.Format(HomePageObjects.SideFilterCssTemplate, header)).Click();
 public IActionResult Get([FromServices] JavascriptExecutor javascriptExecutor)
 {
     return(Ok(javascriptExecutor.Execute(new { parameter = "asd" })));
 }
Пример #24
0
 public bool IsSideFilterOpenedByHeader(string header) => JavascriptExecutor
 .FindElement(string.Format(HomePageObjects.SideFilterCssTemplate, header))
 .GetAttribute("class").Contains("opened");
Пример #25
0
 public void ClickOnFilterOptionByHeaderAndOption(string header, string option) => JavascriptExecutor
 .FindElement(string.Format(HomePageObjects.SideFilterOptionCssTemplate, header, option))
 .Click();
Пример #26
0
 public string GetQuantityOfFilterOptionByHeaderAndOption(string header, string option)
 => JavascriptExecutor
 .FindElement(string.Format(HomePageObjects.SideFilterOptionQuantityCssTemplate, header, option)).Text;
Пример #27
0
 public string GetOldPriceList(string id) => JavascriptExecutor
 .FindElement(string.Format(HomePageObjects.OldPriceCssTemplate, id)).Text;
 public bool IsMainHeaderPresent(string header) =>
 JavascriptExecutor.IsElementPresent(string.Format(HomePageObjects.MainMenuHeaderCssTemplate, header));
 public void SelectBlackColor() =>
 JavascriptExecutor.FindElement(HomePageObjects.BlackColorFilterCssSelector).Click();
Пример #30
0
 public ScriptParseTest()
 {
     _javascriptExecutor = JavascriptExecutor.Create(new JavascriptRawRuntime());
 }