protected override void Cleanup()
        {
            WebView2?.Dispose();
            WebView2 = null;

            base.Cleanup();
        }
Esempio n. 2
0
        protected async Task SetCookieAsync(
            Controls.WinForms.WebView webView,
            string cookieName,
            string cookieValue,
            DateTime?expiry = null)
        {
            string formatExpiry(DateTime?e) => e != null
                ? $"; expires={e.Value.ToUniversalTime():R}"
                : string.Empty;

            var cookie = $"{cookieName}={cookieValue}{formatExpiry(expiry)}";

            if (webView != null)
            {
                await webView.InvokeScriptAsync("eval", $"document.cookie = \"{cookie}\"").ConfigureAwait(false);
            }
        }
        protected override void Cleanup()
        {
            PrintStartEnd(
                TestContext.TestName,
                nameof(Cleanup),
                () =>
            {
                UnsubscribeWebViewEvents();
                TryAction(() =>
                {
                    if (WebView != null && !WebView.IsDisposed)
                    {
                        WriteLine("WebView is not null and has not been disposed. Calling Dispose()");
                        WebView.Dispose();
                        WebView = null;
                    }
                });
            });

            base.Cleanup();
        }
Esempio n. 4
0
 protected Task <string> GetCookiesAsync(Controls.WinForms.WebView webView)
 {
     return(webView.InvokeScriptAsync("eval", "document.cookie"));
 }
Esempio n. 5
0
 protected abstract Task SetCookieAsync(Controls.WinForms.WebView webView);
 protected override void When()
 {
     WebView2 = (Controls.WinForms.WebView)WebView.Process.CreateWebView(Form.Handle, Rectangle.Empty);
 }