示例#1
0
        public static void Main()
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        browser.Navigation.FrameLoadFinished += delegate(object sender, FrameLoadFinishedEventArgs e)
                        {
                            Console.Out.WriteLine($"FrameLoadFinished: URL = {e.ValidatedUrl},"
                                                  + $" IsMainFrame = {e.Frame.IsMain}");
                        };

                        browser.Navigation.LoadStarted       += delegate { Console.Out.WriteLine("LoadStarted"); };
                        browser.Navigation.NavigationStarted += delegate(object sender, NavigationStartedEventArgs e)
                        {
                            Console.Out.WriteLine($"NavigationStarted: Url = {e.Url}");
                        };

                        browser.Navigation.FrameDocumentLoadFinished +=
                            delegate(object sender, FrameDocumentLoadFinishedEventArgs e)
                        {
                            Console.Out.WriteLine($"FrameDocumentLoadFinished: IsMainFrame = {e.Frame.IsMain}");
                        };

                        browser.Navigation.LoadUrl("https://www.google.com").Wait();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#2
0
        public Form1()
        {
            LoggerProvider.Instance.Level = SourceLevels.Verbose;
            LoggerProvider.Instance.FileLoggingEnabled = true;
            LoggerProvider.Instance.OutputFile         = "log.txt";
            BrowserView webView = new BrowserView {
                Dock = DockStyle.Fill
            };

            Task.Run(() =>
            {
                engine = EngineFactory
                         .Create(new EngineOptions.Builder
                {
                    RenderingMode = RenderingMode.HardwareAccelerated
                }
                                 .Build());
                browser = engine.CreateBrowser();
            }).ContinueWith(t =>
            {
                webView.InitializeFrom(browser);
                browser.ShowContextMenuHandler =
                    new AsyncHandler <ShowContextMenuParameters, ShowContextMenuResponse>(ShowMenu);

                browser
                .MainFrame
                .LoadHtml(@"<html>
                                    <head>
                                      <meta charset='UTF-8'>
                                    </head>
                                    <body>
                                    <textarea autofocus cols='30' rows='20'>Simpple mistakee</textarea>
                                    </body>
                                    </html>");
            }, TaskScheduler.FromCurrentSynchronizationContext());

            InitializeComponent();
            FormClosing += Form1_FormClosing;
            Controls.Add(webView);
        }
        public static void Main()
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");

                        browser.MainFrame.LoadHtml("<html><body><div id='root'>"
                                                   + "<p>paragraph1</p>"
                                                   + "<p>paragraph2</p>"
                                                   + "<p>paragraph3</p>"
                                                   + "</div></body></html>")
                        .Wait();
                        IDocument document        = browser.MainFrame.Document;
                        IElement  documentElement = document.DocumentElement;
                        // Get the div with id = "root".
                        INode divRoot = documentElement.GetElementByCssSelector("#root");
                        // Get all paragraphs.
                        IEnumerable <INode> paragraphs = divRoot.GetElementsByCssSelector("p");

                        foreach (INode paragraph in paragraphs)
                        {
                            Console.Out.WriteLine("paragraph.InnerText = " + (paragraph as IElement)?.InnerText);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#4
0
        public static void Main()
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");
                        engine.Network.LoadResourceHandler =
                            new Handler <LoadResourceParameters, LoadResourceResponse>(CanLoadResource);

                        browser.Navigation
                        .LoadUrl("https://www.w3schools.com/xml/tryit.asp?filename=tryajax_first")
                        .Wait();

                        IFrame demoFrame =
                            browser.AllFrames.FirstOrDefault(f => f.Document.GetElementById("demo") != null);

                        if (demoFrame != null)
                        {
                            Console.WriteLine("Demo frame found");
                            demoFrame.Document.GetElementByTagName("button").Click();
                        }

                        Thread.Sleep(5000);
                        Console.WriteLine("Demo HTML: " + demoFrame?.Document.GetElementById("demo").InnerHtml);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
        public static void Main()
        {
            using (IEngine engine = EngineFactory.Create())
            {
                using (IBrowser browser = engine.CreateBrowser())
                {
                    browser.Size = new Size(1024, 768);

                    browser.Navigation
                    .LoadUrl("https://www.teamdev.com/dotnetbrowser")
                    .Wait();

                    IDocument document = browser.MainFrame.Document;

                    string expression = "count(//div)";
                    Console.WriteLine($"Evaluating \'{expression}\'");

                    try
                    {
                        IXPathResult result = document.Evaluate(expression);

                        // Make sure that result is a number.
                        if (result.Type == XPathResultType.Number)
                        {
                            Console.WriteLine("Result: " + result.Numeric);
                        }
                    }
                    // If the expression is not a valid XPath expression or the document
                    // element is not available, we'll get an error.
                    catch (XPathException e)
                    {
                        Console.WriteLine("Error message: " + e.Message);
                        return;
                    }
                }
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
        public static void Main()
        {
            uint viewWidth   = 1024;
            uint viewHeight  = 20000;
            Size browserSize = new Size(viewWidth, viewHeight);

            using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder
            {
                RenderingMode = RenderingMode.OffScreen,
                ChromiumSwitches = { "--disable-gpu", "--max-texture-size=" + viewHeight }
            }.Build()))
            {
                using (IBrowser browser = engine.CreateBrowser())
                {
                    // #docfragment "HtmlToImage"
                    // 1. Resize browser to the required dimension.
                    browser.Size = browserSize;

                    // 2. Load the required web page and wait until it is loaded completely.
                    Console.WriteLine("Loading https://www.teamdev.com/dotnetbrowser");
                    browser.Navigation
                    .LoadUrl("https://www.teamdev.com/dotnetbrowser")
                    .Wait();

                    // 3. Take the bitmap of the currently loaded web page. Its size will be
                    // equal to the current browser's size.
                    DotNetBrowser.Ui.Bitmap image = browser.TakeImage();
                    Console.WriteLine("Browser image taken");

                    // 4. Convert the bitmap to the required format and save it.
                    Bitmap bitmap = ToBitmap(image);
                    bitmap.Save("screenshot.png", ImageFormat.Png);
                    Console.WriteLine("Browser image saved");
                    // #enddocfragment "HtmlToImage"
                }
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#7
0
        private static void Main(string[] args)
        {
            string userDataDir1 = Path.GetFullPath("user-data-dir-one");

            Directory.CreateDirectory(userDataDir1);
            IEngine engine1 = EngineFactory.Create(new EngineOptions.Builder
            {
                UserDataDirectory = userDataDir1
            }.Build());

            Console.WriteLine("Engine1 created");

            string userDataDir2 = Path.GetFullPath("user-data-dir-two");

            Directory.CreateDirectory(userDataDir2);
            IEngine engine2 = EngineFactory.Create(new EngineOptions.Builder
            {
                UserDataDirectory = userDataDir2
            }.Build());

            Console.WriteLine("Engine2 created");

            // This Browser instance will store cookies and user data files in "user-data-dir-one" dir.
            IBrowser browser1 = engine1.CreateBrowser();

            Console.WriteLine("browser1 created");

            // This Browser instance will store cookies and user data files in "user-data-dir-two" dir.
            IBrowser browser2 = engine2.CreateBrowser();

            Console.WriteLine("browser2 created");

            // The browser1 and browser2 instances will not see the cookies and cache data files of each other.

            engine2.Dispose();
            engine1.Dispose();

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
        public Form1()
        {
            InitializeComponent();
            BrowserView webView = new BrowserView {
                Dock = DockStyle.Fill
            };

            tableLayoutPanel1.Controls.Add(webView, 1, 0);
            tableLayoutPanel1.SetRowSpan(webView, 2);
            engine = EngineFactory
                     .Create(new EngineOptions.Builder
            {
                RenderingMode = RenderingMode.HardwareAccelerated
            }
                             .Build());
            browser = engine.CreateBrowser();
            webView.InitializeFrom(browser);
            browser.ConsoleMessageReceived += (sender, args) => { };
            browser
            .MainFrame
            .LoadHtml(@"<html>
                        <head>
                          <meta charset='UTF-8'>
                          <style>body{padding: 0; margin: 0; width:100%; height: 100%;}
                                textarea.fill {padding: 2; margin: 0; width:100%; height:100%;}
                                button{position: absolute; bottom: 0; padding: 2; width:100%;}</style>
                        </head>
                        <body>
                        <div>
                        <textarea id='text' class='fill' autofocus cols='30' rows='20'>Sample text</textarea>
                        <button id='updateForm' type='button' onClick='updateForm(document.getElementById(""text"").value)'>&lt; Update Form</button> 
                        </div>
                        </body>
                        </html>")
            .Wait();
            IJsObject window = browser.MainFrame.ExecuteJavaScript <IJsObject>("window").Result;

            window.Properties["updateForm"] = (Action <string>)UpdateForm;
            FormClosing += Form1_FormClosing;
        }
        public MainWindow()
        {
            engine = EngineFactory
                     .Create(new EngineOptions.Builder
            {
                RenderingMode    = RenderingMode.HardwareAccelerated,
                ChromiumSwitches = { "--enable-com-in-drag-drop" },
                SandboxDisabled  = true
            }
                             .Build());

            browser = engine.CreateBrowser();
            // #docfragment "DragAndDrop.Configuration"
            browser.DragAndDrop.EnterDragHandler =
                new Handler <EnterDragParameters>(OnDragEnter);
            browser.DragAndDrop.DropHandler = new Handler <DropParameters>(OnDrop);
            // #enddocfragment "DragAndDrop.Configuration"

            InitializeComponent();
            browserView.InitializeFrom(browser);
            browser.Navigation.LoadUrl("teamdev.com");
        }
        private static void Main(string[] args)
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");
                        browser.Size            = new Size(700, 500);
                        browser.InjectJsHandler = new Handler <InjectJsParameters>(InjectObjectForScripting);
                        browser.MainFrame.LoadHtml(@"<html>
                                     <body>
                                        <script type='text/javascript'>
                                            var SetTitle = function () 
                                            {
                                                 document.title = window.external.GetTitle();
                                            };
                                        </script>
                                     </body>
                                   </html>")
                        .Wait();

                        browser.MainFrame.ExecuteJavaScript <IJsObject>("window.SetTitle();").Wait();

                        Console.WriteLine($"\tBrowser title: {browser.Title}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
        public static void Main()
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");
                        browser.Size = new Size(700, 500);
                        browser.Navigation.LoadUrl("https://www.teamdev.com").Wait();

                        PointInspection pointInspection =
                            browser.MainFrame.Inspect(new Point(50, 50));

                        Console.WriteLine("Inspection result:");
                        Console.WriteLine($"\tAbsoluteImageUrl: {pointInspection.AbsoluteImageUrl}");
                        Console.WriteLine($"\tAbsoluteLinkUrl: {pointInspection.AbsoluteLinkUrl}");
                        if (pointInspection.LocalPoint != null)
                        {
                            Console
                            .WriteLine($"\tLocalPoint: ({pointInspection.LocalPoint.X},{pointInspection.LocalPoint.Y})");
                        }

                        Console.WriteLine($"\tNode: {pointInspection.Node?.NodeName}");
                        Console.WriteLine($"\tUrlNode: {pointInspection.UrlNode?.NodeName}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#12
0
        public MainWindow()
        {
            Task.Run(() =>
                 {
                     engine = EngineFactory
                        .Create(new EngineOptions.Builder
                                    {
                                        RenderingMode = RenderingMode.OffScreen
                                    }
                                   .Build());
                     browser = engine.CreateBrowser();
                 })
                .ContinueWith(t =>
                 {
                     WebView.InitializeFrom(browser);
                     browser.ShowContextMenuHandler =
                         new AsyncHandler<ShowContextMenuParameters, ShowContextMenuResponse>(ShowContextMenu);
                     browser.Navigation.LoadUrl("https://www.google.com/");
                 }, TaskScheduler.FromCurrentSynchronizationContext());

            InitializeComponent();
        }
        public void Initialize_LogPathNotExist_NoError()
        {
            // Arrange
            string logPath = Path.Combine(Path.GetTempPath(), "YellowJacket");

            if (Directory.Exists(logPath))
            {
                Directory.Delete(logPath, true);
            }

            IEngine engine = EngineFactory.Create();

            string testAssemblyFullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "YellowJacket.Core.Test.Data.dll");

            List <string> features = new List <string> {
                "Login"
            };

            AutoResetEvent autoResetEvent = new AutoResetEvent(false);

            // Act
            Configuration configuration =
                new Configuration
            {
                TestAssemblyFullName = testAssemblyFullName,
                Features             = features
            };

            engine.ExecutionStart += (sender, e) =>
            {
                autoResetEvent.Set();
            };

            engine.Run(configuration);

            // Assert
            Assert.That(Directory.Exists(logPath), Is.True, "The log path should have been created.");
        }
        private void InitializeBrowserView()
        {
            try
            {
                engine = EngineFactory.Create(new EngineOptions.Builder
                {
                    RenderingMode              = RenderingMode.HardwareAccelerated,
                    LicenseKey                 = BROWSERVIEW_LICENSE_KEY,
                    RemoteDebuggingPort        = DEBUGGING_PORT,
                    WebSecurityDisabled        = true,
                    FileAccessFromFilesAllowed = true,
                }
                                              .Build());
                browser = engine.CreateBrowser();

#if DEBUG
                browser.ConsoleMessageReceived += Browser_ConsoleMessageReceived;
#endif
            }
            catch (Exception exception)
            {
            }
        }
        public static void Main()
        {
            using (IEngine engine = EngineFactory.Create())
            {
                using (IBrowser browser = engine.CreateBrowser())
                {
                    browser.Navigation
                    .LoadUrl("https://www.teamdev.com")
                    .Wait();

                    IDocument           document = browser.MainFrame.Document;
                    IEnumerable <INode> divs     = document.GetElementsByTagName("div");

                    foreach (INode node in divs)
                    {
                        PrintBoundingClientRect(node);
                    }
                }
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
        public static void Main()
        {
            using (IEngine engine = EngineFactory.Create())
            {
                using (IBrowser browser = engine.CreateBrowser())
                {
                    engine.Profiles.Default.Network.SendUrlRequestHandler =
                        new Handler <SendUrlRequestParameters,
                                     SendUrlRequestResponse>(OnSendUrlRequest);

                    engine.Profiles.Default.Network.StartTransactionHandler =
                        new Handler <StartTransactionParameters,
                                     StartTransactionResponse>(OnStartTransaction);

                    Console.WriteLine("Loading https://www.teamdev.com/");
                    browser.Navigation.LoadUrl("https://www.teamdev.com/").Wait();
                    Console.WriteLine($"Loaded URL: {browser.Url}");
                }
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#17
0
        public void Run_FeatureNotFound_ArgumentExceptionThrown()
        {
            // Arrange
            IEngine engine = EngineFactory.Create();

            string testAssemblyFullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "YellowJacket.Core.Test.Data.dll");

            List <string> features = new List <string> {
                "MyFeature"
            };

            // Act
            Configuration configuration =
                new Configuration
            {
                TestAssemblyFullName = testAssemblyFullName,
                Features             = features
            };

            // Assert
            Assert.Throws <ArgumentException>(()
                                              => engine.Run(configuration));
        }
 public browserContainer()
 {
     Task.Run(() =>
     {
         engine = EngineFactory.Create(new EngineOptions.Builder
         {
             RenderingMode = RenderingMode.HardwareAccelerated
         }
                                       .Build());
         browser = engine.CreateBrowser();
     })
     .ContinueWith(t =>
     {
         browserView1.InitializeFrom(browser);
         //engine.Network.VerifyCertificateHandler =
         //new Handler<VerifyCertificateParameters, VerifyCertificateResponse>(VerifyCert);
         //handlePKI(browser);
         //browser.Navigation.LoadUrl("https://developers.arcgis.com/javascript/latest/sample-code/");
         //browser.Navigation.LoadUrl("https://nustar.esri.com/portal/");
         browser.Navigation.LoadUrl("https://material.angular.io/cdk/drag-drop/examples");
     }, TaskScheduler.FromCurrentSynchronizationContext());
     InitializeComponent();
 }
        public static void Main()
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (DotNetBrowser.Browser.IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");
                        engine.Network.SendUploadDataHandler =
                            new Handler <SendUploadDataParameters, SendUploadDataResponse>(OnSendUploadData);

                        LoadUrlParameters parameters =
                            new LoadUrlParameters("https://postman-echo.com/post")
                        {
                            PostData    = "key=value",
                            HttpHeaders = new[]
                            {
                                new HttpHeader("Content-Type", "text/plain")
                            }
                        };

                        browser.Navigation.LoadUrl(parameters).Wait();
                        Console.WriteLine(browser.MainFrame.Document.DocumentElement.InnerText);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#20
0
        public MainWindow()
        {
            try
            {
                Task.Run(() =>
                {
                    engine = EngineFactory.Create(new EngineOptions.Builder
                    {
                        RenderingMode = RenderingMode.OffScreen
                    }
                                                  .Build());

                    browser = engine.CreateBrowser();
                })
                .ContinueWith(t =>
                {
                    BrowserView browserView = new BrowserView();
                    // Embed BrowserView component into main layout.
                    MainLayout.Children.Add(browserView);
                    browserView.InitializeFrom(browser);
                    browser.MainFrame
                    .LoadHtml(@"<html>
                                            <body>
                                                <input type='text' autofocus></input>
                                            </body>
                                           </html>")
                    .ContinueWith(SimulateInput);
                }, TaskScheduler.FromCurrentSynchronizationContext());

                // Initialize Wpf Application UI.
                InitializeComponent();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
        }
        public static void Main()
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");

                        // Executes the passed JavaScript code asynchronously.
                        browser
                        .MainFrame
                        .ExecuteJavaScript("document.write('<html><title>"
                                           + "My Title</title><body><h1>Hello from DotNetBrowser!</h1></body></html>');");

                        // Executes the passed JavaScript code and returns the result value.
                        string documentTitle = browser.MainFrame.ExecuteJavaScript <string>("document.title").Result;
                        Console.Out.WriteLine("Document Title = " + documentTitle);


                        string documentContent =
                            browser.MainFrame.ExecuteJavaScript <string>("document.body.innerText").Result;
                        Console.Out.WriteLine("New content: " + documentContent);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#22
0
        public MainWindow()
        {
            try
            {
                Task.Run(() =>
                {
                    engine = EngineFactory.Create(new EngineOptions.Builder
                    {
                        RenderingMode = RenderingMode.OffScreen
                    }
                                                  .Build());

                    browser = engine.CreateBrowser();
                })
                .ContinueWith(t =>
                {
                    BrowserView browserView = new BrowserView();
                    // Embed BrowserView component into main layout.
                    MainLayout.Children.Add(browserView);
                    browserView.InitializeFrom(browser);
                    byte[] htmlBytes = Encoding.UTF8.GetBytes(@"<html>
                                            <body>
                                                <input type='text' autofocus></input>
                                            </body>
                                           </html>");
                    browser.Navigation.LoadUrl("data:text/html;base64," + Convert.ToBase64String(htmlBytes))
                    .ContinueWith(SimulateInput);
                }, TaskScheduler.FromCurrentSynchronizationContext());

                // Initialize Wpf Application UI.
                InitializeComponent();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
        }
示例#23
0
        public Form1()
        {
            Task.Run(() =>
            {
                engine = EngineFactory.Create(new EngineOptions.Builder
                {
                    RenderingMode = RenderingMode.HardwareAccelerated
                }
                                              .Build());
                browser = engine.CreateBrowser();
            })
            .ContinueWith(t =>
            {
                browserView1.InitializeFrom(browser);
                browser.Navigation.LoadUrl("https://teamdev.com");
                // Set focus to browser.
                browser.Focus();

                browser.Keyboard.KeyPressed.Handler =
                    new Handler <IKeyPressedEventArgs, InputEventResponse>(HandleKeyPress);
            }, TaskScheduler.FromCurrentSynchronizationContext());
            InitializeComponent();
            FormClosing += Form1_FormClosing;
        }
示例#24
0
        public Form1()
        {
            BrowserView webView = new BrowserView {
                Dock = DockStyle.Fill
            };

            Task.Run(() =>
            {
                engine = EngineFactory.Create(new EngineOptions.Builder
                {
                    RenderingMode = RenderingMode.HardwareAccelerated
                }
                                              .Build());
                browser = engine.CreateBrowser();
            })
            .ContinueWith(t =>
            {
                webView.InitializeFrom(browser);
                browser.Navigation.LoadUrl("https://www.teamdev.com/");
            }, TaskScheduler.FromCurrentSynchronizationContext());
            InitializeComponent();
            FormClosing += Form1_FormClosing;
            Controls.Add(webView);
        }
示例#25
0
        public void Run_ValidConfigurationSingleFeature_NoError()
        {
            // Arrange
            IEngine engine = EngineFactory.Create();

            string testAssemblyFullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "YellowJacket.Core.Test.Data.dll");

            List <string> features = new List <string> {
                "Login"
            };

            // Act
            Configuration configuration =
                new Configuration
            {
                TestAssemblyFullName = testAssemblyFullName,
                Features             = features
            };

            engine.Run(configuration);

            // Assert
            Assert.That(engine.Status, Is.EqualTo(EngineStatus.Completed));
        }
示例#26
0
        private static void Main(string[] args)
        {
            try
            {
                using (IEngine engine = EngineFactory.Create())
                {
                    Console.WriteLine("Engine created");
                    // Grant a permission to display notifications
                    engine.Permissions.RequestPermissionHandler
                        = new Handler <RequestPermissionParameters, RequestPermissionResponse>(OnRequestPermission);
                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");
                        browser.Size = new Size(640, 480);

                        //Configure JavaScript injection
                        browser.InjectJsHandler = new Handler <InjectJsParameters>(OnInjectJs);
                        //Load web page for testing
                        browser.Navigation.LoadUrl(DemoUrl).Wait();

                        //Create a notification by clicking the button on the web page
                        browser.MainFrame.Document
                        .GetElementByCssSelector(".demo-wrapper > p:nth-child(5) > button:nth-child(1)")
                        ?.Click();
                        Thread.Sleep(5000);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
        private static void Main(string[] args)
        {
            using (IEngine engine = EngineFactory.Create())
            {
                using (IBrowser browser = engine.CreateBrowser())
                {
                    browser.Size            = new Size(700, 500);
                    browser.InjectJsHandler =
                        new Handler <InjectJsParameters>(InjectObjectForScripting);

                    byte[] htmlBytes = Encoding.UTF8.GetBytes(@"<html>
                                     <body>
                                        <script type='text/javascript'>
                                            var SetTitle = function () 
                                            {
                                                 document.title = window.external.GetTitle();
                                            };
                                        </script>
                                     </body>
                                   </html>");

                    browser.Navigation
                    .LoadUrl($"data:text/html;base64,{Convert.ToBase64String(htmlBytes)}")
                    .Wait();

                    browser.MainFrame
                    .ExecuteJavaScript <IJsObject>("window.SetTitle();")
                    .Wait();

                    Console.WriteLine($"\tBrowser title: {browser.Title}");
                }
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
示例#28
0
        public Form1()
        {
            Task.Run(() =>
            {
                engine = EngineFactory
                         .Create(new EngineOptions.Builder
                {
                    RenderingMode       = RenderingMode.HardwareAccelerated,
                    RemoteDebuggingPort = 9222
                }
                                 .Build());
                browser1 = engine.CreateBrowser();
                browser2 = engine.CreateBrowser();
            })
            .ContinueWith(t =>
            {
                browserView1.InitializeFrom(browser1);
                browserView2.InitializeFrom(browser2);

                browser1.Navigation.LoadUrl("https://www.teamdev.com");
                browser2.Navigation.LoadUrl(browser1.DevTools.RemoteDebuggingUrl);
            }, TaskScheduler.FromCurrentSynchronizationContext());
            InitializeComponent();
        }
示例#29
0
        public Form1()
        {
            InitializeComponent();
            browserView = new BrowserView {
                Dock = DockStyle.Fill
            };
            engine = EngineFactory
                     .Create(new EngineOptions.Builder
            {
                RenderingMode = RenderingMode.HardwareAccelerated
            }
                             .Build());
            browser = engine.CreateBrowser();
            browserView.InitializeFrom(browser);

            Controls.Add(browserView);
            Task.Run(() =>
            {
                browser.Navigation.LoadUrl(Path.GetFullPath("page.html")).Wait();

                // After the page is loaded successfully, we can configure the observer.
                ConfigureObserver();
            });
        }
示例#30
0
        public void RegisterHooks_Run_HookInstancesInitialized()
        {
            // Arrange
            IEngine engine = EngineFactory.Create();

            string testAssemblyFullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "YellowJacket.Core.Test.Data.dll");

            List <string> features = new List <string> {
                "Login"
            };

            // Act
            Configuration configuration =
                new Configuration
            {
                TestAssemblyFullName = testAssemblyFullName,
                Features             = features
            };

            engine.Run(configuration);

            // Assert
            Assert.That(ExecutionContext.Instance.Hooks.Count, Is.EqualTo(2));
        }