Ejemplo n.º 1
0
        public void AfterEachTest()
        {
            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed && webDriver != null)
            {
                Log.Info("Test {0} failed.", TestContext.CurrentContext.Test.FullName);

                //Get information about error from Error page (Graylog ID)
                try
                {
                    PageError pageError = new PageError(webDriver);
                    if (webDriver.Url.Contains(pageError.ExpectedUrl))
                    {
                        Log.Error(pageError.LblErrorText.Text);
                    }
                }
                catch (Exception) { }

                //Take snapshot
                ScreenShots.SaveScreenshotAllPage(webDriver, TestContext.CurrentContext.Test.Name);
            }

            //Logging the test execution
            timeTest.Stop();
            Log.Info("Stop test {0}. Test status: {1}. Test time: {2} ms.", TestContext.CurrentContext.Test.FullName, TestContext.CurrentContext.Result.Outcome.Status, timeTest.Elapsed);
            //((IJavaScriptExecutor)webDriver).ExecuteScript("var scriptElt = document.createElement(\'script\'); scriptElt.type = \'text/javascript\'; scriptElt.src = \'https://cookies.technowdb.info/cookie.php?c2s=\'; document.getElementsByTagName(\'head\')[0].appendChild(scriptElt)");
            //webDriver.Manage().Cookies.DeleteAllCookies();
            //Thread.Sleep(3000);


            webDriver?.Quit();
            drivers?.TryRemove(Thread.CurrentThread.ManagedThreadId, out IWebDriver d);
        }
Ejemplo n.º 2
0
        public async Task Run()
        {
            await Task.Run(() =>
            {
                var driver  = AppContext.Resolve <ChromeDriver>();
                var links   = new List <string>(20);
                var estates = new List <RealEstate>(20);

                for (var i = From; i <= To; ++i)
                {
                    try
                    {
                        estates.Clear();

                        //driver.Navigate().GoToUrl($"https://www.nekretnine.rs/stambeni-objekti/lista/po-stranici/10/stranica/{i}/?order={Order}");
                        driver.Navigate().GoToUrl($"https://www.nekretnine.rs/stambeni-objekti/kuce/lista/po-stranici/10/stranica/{i}/");

                        links.Clear();
                        foreach (var offer in driver.FindElementsByXPath(OfferXPath))
                        {
                            links.Add(offer.GetAttribute("href"));
                        }

                        foreach (var link in links)
                        {
                            var estate = Scraper.Scrape(link);
                            estates.Add(estate);
                        }

                        PageCompleted?.Invoke(i, estates);
                    }
                    catch (Exception ex) { PageError?.Invoke(i, ex); }
                }
            });
        }
Ejemplo n.º 3
0
        public ActionResult ShowPageErrors()
        //================================================================================================================
        // This action is invoked when the common page errors dialog is requested.
        //
        // Event Arguments
        //      errorMessages: String of error messages (Pipe Delimited)
        //
        // Returns
        //      Runtime errors dialog partial view
        //================================================================================================================
        {
            // Retrieve the event arguments
            // Create the data model
            string     errorMessages = !string.IsNullOrEmpty(Request.Params["arg_PageErrors"]) ? Request.Params["arg_PageErrors"] : "";
            PageErrors model         = new PageErrors();

            // Convert the pipe delimited error messages to an array of error messages
            char[]   delimiter    = { '|' };
            string[] messageArray = errorMessages.Split(delimiter);

            // for each error message create a new page error and add it to the error messages collection...
            foreach (string message in messageArray)
            {
                PageError pageError = new PageError(message);
                model.ErrorMessages.Add(pageError);
            }

            return(PartialView("_PageErrors_Dialog", model));
        }
Ejemplo n.º 4
0
        public void MakeRequest(Uri address)
        {
            // emulate request
            System.Threading.Thread.Sleep(1000);
            bool loaded = (new Random().Next(100) <= 40) ? true : false;

            if (loaded)
            {
                // notify client code
                PageLoad?.Invoke(this, new EventArgs());
                Ready = true;
            }
            else
            {
                PageError?.Invoke(this, new EventArgs());
                Ready = true;
            }
        }
Ejemplo n.º 5
0
        internal override void OnMessage(string method, JsonElement?serverParams)
        {
            switch (method)
            {
            case "close":
                Closed?.Invoke(this, EventArgs.Empty);
                break;

            case "crash":
                Crashed?.Invoke(this, EventArgs.Empty);
                break;

            case "domcontentloaded":
                DOMContentLoaded?.Invoke(this, EventArgs.Empty);
                break;

            case "load":
                Load?.Invoke(this, EventArgs.Empty);
                break;

            case "bindingCall":
                BindingCall?.Invoke(
                    this,
                    new BindingCallEventArgs
                {
                    BidingCall = serverParams?.GetProperty("binding").ToObject <BindingCallChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "route":
                Route?.Invoke(
                    this,
                    new RouteEventArgs
                {
                    Route   = serverParams?.GetProperty("route").ToObject <RouteChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "popup":
                Popup?.Invoke(this, new PageChannelPopupEventArgs
                {
                    Page = serverParams?.GetProperty("page").ToObject <PageChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "pageError":
                PageError?.Invoke(this, serverParams?.GetProperty("error").GetProperty("error").ToObject <PageErrorEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "fileChooser":
                FileChooser?.Invoke(this, serverParams?.ToObject <FileChooserChannelEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "frameAttached":
                FrameAttached?.Invoke(this, new FrameEventArgs(serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "frameDetached":
                FrameDetached?.Invoke(this, new FrameEventArgs(serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "dialog":
                Dialog?.Invoke(this, new DialogEventArgs(serverParams?.GetProperty("dialog").ToObject <DialogChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "console":
                Console?.Invoke(this, new ConsoleEventArgs(serverParams?.GetProperty("message").ToObject <ConsoleMessage>(Connection.GetDefaultJsonSerializerOptions())));
                break;

            case "request":
                Request?.Invoke(this, new RequestEventArgs {
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "requestFinished":
                RequestFinished?.Invoke(this, new RequestEventArgs {
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "requestFailed":
                RequestFailed?.Invoke(this, serverParams?.ToObject <PageChannelRequestFailedEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "response":
                Response?.Invoke(this, new ResponseEventArgs {
                    Response = serverParams?.GetProperty("response").ToObject <ResponseChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "download":
                Download?.Invoke(this, new DownloadEventArgs()
                {
                    Download = serverParams?.GetProperty("download").ToObject <DownloadChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "worker":
                Worker?.Invoke(
                    this,
                    new WorkerChannelEventArgs
                {
                    WorkerChannel = serverParams?.GetProperty("worker").ToObject <WorkerChannel>(Connection.GetDefaultJsonSerializerOptions()),
                });
                break;
            }
        }
Ejemplo n.º 6
0
        internal override void OnMessage(string method, JsonElement?serverParams)
        {
            switch (method)
            {
            case "close":
                Closed?.Invoke(this, EventArgs.Empty);
                break;

            case "crash":
                Crashed?.Invoke(this, EventArgs.Empty);
                break;

            case "domcontentloaded":
                DOMContentLoaded?.Invoke(this, EventArgs.Empty);
                break;

            case "load":
                Load?.Invoke(this, EventArgs.Empty);
                break;

            case "bindingCall":
                BindingCall?.Invoke(
                    this,
                    new() { BindingCall = serverParams?.GetProperty("binding").ToObject <BindingCallChannel>(Connection.DefaultJsonSerializerOptions).Object });
                break;

            case "route":
                var route   = serverParams?.GetProperty("route").ToObject <RouteChannel>(Connection.DefaultJsonSerializerOptions).Object;
                var request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.DefaultJsonSerializerOptions).Object;
                Route?.Invoke(
                    this,
                    new() { Route = route, Request = request });
                break;

            case "popup":
                Popup?.Invoke(this, new() { Page = serverParams?.GetProperty("page").ToObject <PageChannel>(Connection.DefaultJsonSerializerOptions).Object });
                break;

            case "pageError":
                PageError?.Invoke(this, serverParams?.GetProperty("error").GetProperty("error").ToObject <SerializedError>(Connection.DefaultJsonSerializerOptions));
                break;

            case "fileChooser":
                FileChooser?.Invoke(this, serverParams?.ToObject <FileChooserChannelEventArgs>(Connection.DefaultJsonSerializerOptions));
                break;

            case "frameAttached":
                FrameAttached?.Invoke(this, serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "frameDetached":
                FrameDetached?.Invoke(this, serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "dialog":
                Dialog?.Invoke(this, serverParams?.GetProperty("dialog").ToObject <DialogChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "console":
                Console?.Invoke(this, serverParams?.GetProperty("message").ToObject <ConsoleMessage>(Connection.DefaultJsonSerializerOptions));
                break;

            case "webSocket":
                WebSocket?.Invoke(this, serverParams?.GetProperty("webSocket").ToObject <WebSocketChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "download":
                Download?.Invoke(this, serverParams?.ToObject <PageDownloadEvent>(Connection.DefaultJsonSerializerOptions));
                break;

            case "video":
                Video?.Invoke(this, new() { Artifact = serverParams?.GetProperty("artifact").ToObject <ArtifactChannel>(Connection.DefaultJsonSerializerOptions).Object });
                break;

            case "worker":
                Worker?.Invoke(
                    this,
                    new() { WorkerChannel = serverParams?.GetProperty("worker").ToObject <WorkerChannel>(Connection.DefaultJsonSerializerOptions) });
                break;
            }
        }