-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathLoggingTest.cs
56 lines (48 loc) · 1.91 KB
/
LoggingTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Tokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace SeleniumDocs.BiDi.CDP
{
[TestClass]
public class LoggingTest : BaseChromeTest
{
[TestMethod]
public async Task ConsoleLogs()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
using IJavaScriptEngine monitor = new JavaScriptEngine(driver);
var messages = new List<string>();
monitor.JavaScriptConsoleApiCalled += (_, e) =>
{
messages.Add(e.MessageContent);
};
await monitor.StartEventMonitoring();
driver.FindElement(By.Id("consoleLog")).Click();
driver.FindElement(By.Id("consoleError")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => messages.Count > 1);
monitor.StopEventMonitoring();
Assert.IsTrue(messages.Contains("Hello, world!"));
Assert.IsTrue(messages.Contains("I am console error"));
}
[TestMethod]
public async Task JsErrors()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
using IJavaScriptEngine monitor = new JavaScriptEngine(driver);
var messages = new List<string>();
monitor.JavaScriptExceptionThrown += (_, e) =>
{
messages.Add(e.Message);
};
await monitor.StartEventMonitoring();
driver.FindElement(By.Id("jsException")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => !messages.IsNullOrEmpty());
monitor.StopEventMonitoring();
Assert.IsTrue(messages.Contains("Uncaught"));
}
}
}