-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathNetworkTest.cs
More file actions
108 lines (87 loc) · 3.71 KB
/
Copy pathNetworkTest.cs
File metadata and controls
108 lines (87 loc) · 3.71 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.BiDi;
using OpenQA.Selenium.Support.UI;
namespace SeleniumDocs.BiDi.W3C
{
[TestClass]
public class NetworkTest : BaseFirefoxTest
{
[TestMethod]
public void InterceptNetworkRequest()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
// Network interception would require BiDi module subscription
// This demonstrates the concept
var requestsIntercepted = 0;
// Simulate network request
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";
Assert.IsTrue(requestsIntercepted >= 0);
}
[TestMethod]
public void InterceptNetworkResponse()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
var responsesCaptured = new List<string>();
// Navigate to trigger responses
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";
// Verify navigation occurred
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
Assert.IsTrue(driver.Url.Contains("iframes.html"));
}
[TestMethod]
public void ContinueNetworkRequest()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
// Continue request logic would be handled by BiDi module
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";
}
[TestMethod]
public void ProvideAuthCredentials()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
// Auth handling would require BiDi module
// This is a conceptual example
var username = "user";
var password = "pass";
Assert.IsNotNull(username);
Assert.IsNotNull(password);
}
[TestMethod]
public void FailNetworkRequest()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
// Request failure handling via BiDi
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";
}
[TestMethod]
public void InterceptFetchRequests()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
var fetchCalls = 0;
((IJavaScriptExecutor)driver).ExecuteAsyncScript(@"
var callback = arguments[arguments.length - 1];
fetch('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
.then(() => callback(1))
.catch(() => callback(0));
");
Assert.IsTrue(fetchCalls >= 0);
}
[TestMethod]
public void InterceptXhrRequests()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
((IJavaScriptExecutor)driver).ExecuteAsyncScript(@"
var callback = arguments[arguments.length - 1];
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html');
xhr.onload = function() { callback(1); };
xhr.onerror = function() { callback(0); };
xhr.send();
");
}
}
}