Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 724105d

Browse files
nvborisenkotitusfortner
andauthored
[dotnet] Simplify and add examples for bidi network intercepring (#1467)
* Simplify and add examples for bidi network intercepring * Insert examples as reference to original source * move network interceptor examples to bidi file and update docs references --------- Co-authored-by: titusfortner <titus.fortner@gmail.com>
1 parent f1e6da8 commit 724105d

File tree

6 files changed

+182
-119
lines changed

6 files changed

+182
-119
lines changed
Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,76 @@
1+
using System.Threading.Tasks;
12
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using OpenQA.Selenium;
24

35
namespace SeleniumDocs.Bidirectional
46
{
57
[TestClass]
6-
public class BidiApiTest : BaseTest
8+
public class BidiApiTest : BaseChromeTest
79
{
10+
[TestMethod]
11+
public async Task InterceptNetworkForAuthentication()
12+
{
13+
var handler = new NetworkAuthenticationHandler()
14+
{
15+
UriMatcher = _ => true,
16+
Credentials = new PasswordCredentials("admin", "admin")
17+
};
818

19+
INetwork networkInterceptor = driver.Manage().Network;
20+
networkInterceptor.AddAuthenticationHandler(handler);
21+
22+
await networkInterceptor.StartMonitoring();
23+
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/basic_auth");
24+
await networkInterceptor.StopMonitoring();
25+
26+
Assert.AreEqual("Congratulations! You must have the proper credentials.", driver.FindElement(By.TagName("p")).Text);
27+
28+
}
29+
30+
[TestMethod]
31+
public async Task InterceptNetworkResponse()
32+
{
33+
var handler = new NetworkResponseHandler()
34+
{
35+
ResponseMatcher = httpresponse => true,
36+
ResponseTransformer = http => new()
37+
{
38+
StatusCode = 200,
39+
Body = "Creamy, delicious cheese!"
40+
}
41+
};
42+
43+
INetwork networkInterceptor = driver.Manage().Network;
44+
networkInterceptor.AddResponseHandler(handler);
45+
46+
await networkInterceptor.StartMonitoring();
47+
driver.Navigate().GoToUrl("https://www.selenium.dev");
48+
await networkInterceptor.StopMonitoring();
49+
50+
StringAssert.Contains(driver.PageSource, "delicious cheese");
51+
}
52+
53+
[TestMethod]
54+
public async Task InterceptNetworkRequest()
55+
{
56+
var handler = new NetworkRequestHandler()
57+
{
58+
RequestMatcher = httprequest => true,
59+
ResponseSupplier = http => new()
60+
{
61+
StatusCode = 200,
62+
Body = "Creamy, delicious cheese!"
63+
}
64+
};
65+
66+
INetwork networkInterceptor = driver.Manage().Network;
67+
networkInterceptor.AddRequestHandler(handler);
68+
69+
await networkInterceptor.StartMonitoring();
70+
driver.Navigate().GoToUrl("https://www.selenium.dev");
71+
await networkInterceptor.StopMonitoring();
72+
73+
StringAssert.Contains(driver.PageSource, "delicious cheese");
74+
}
975
}
10-
}
76+
}

‎examples/dotnet/SeleniumDocs/ChromeDevTools/NetworkInterceptor.cs‎

Lines changed: 0 additions & 73 deletions
This file was deleted.

‎website_and_docs/content/documentation/webdriver/bidirectional/bidi_api.en.md‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,8 @@ driver.get("https://your-domain.com/login");
2525
{{< tab header="Python" text=true >}}
2626
{{< badge-code >}}
2727
{{< /tab >}}
28-
{{< tab header="CSharp" >}}
29-
NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
30-
{
31-
UriMatcher = (d) => d.Host.Contains("your-domain.com"),
32-
Credentials = new PasswordCredentials("admin", "password")
33-
};
34-
35-
INetwork networkInterceptor = driver.Manage().Network;
36-
networkInterceptor.AddAuthenticationHandler(handler);
37-
await networkInterceptor.StartMonitoring();
28+
{{< tab header="CSharp" text=true >}}
29+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L13-L24" >}}
3830
{{< /tab >}}
3931
{{< tab header="Ruby" >}}
4032
require 'selenium-webdriver'
@@ -447,6 +439,8 @@ fun kotlinJsErrorListener() {
447439
If you want to capture network events coming into the browser and you want manipulate them you are able to do
448440
it with the following examples.
449441

442+
### Intercept Responses
443+
450444
{{< tabpane langEqualsHeader=true >}}
451445
{{< badge-examples >}}
452446
{{< tab header="Java" >}}
@@ -476,7 +470,7 @@ it with the following examples.
476470
Currently unavailable in python due the inability to mix certain async and sync commands
477471
{{< /tab >}}
478472
{{< tab header="CSharp" text=true >}}
479-
{{< badge-code >}}
473+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L33-L48" >}}
480474
{{< /tab >}}
481475
{{< tab header="Ruby" >}}
482476
require 'selenium-webdriver'
@@ -522,3 +516,26 @@ val interceptor = new NetworkInterceptor(
522516
String source = driver.getPageSource()
523517
{{< /tab >}}
524518
{{< /tabpane >}}
519+
520+
### Intercept Requests
521+
522+
{{< tabpane text=true langEqualsHeader=true >}}
523+
{{< tab header="Java" >}}
524+
{{< badge-code >}}
525+
{{< /tab >}}
526+
{{< tab header="Python" >}}
527+
{{< badge-code >}}
528+
{{< /tab >}}
529+
{{< tab header="CSharp" >}}
530+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L56-L71" >}}
531+
{{< /tab >}}
532+
{{< tab header="Ruby" >}}
533+
{{< badge-code >}}
534+
{{< /tab >}}
535+
{{< tab header="JavaScript" >}}
536+
{{< badge-code >}}
537+
{{< /tab >}}
538+
{{< tab header="Kotlin" >}}
539+
{{< badge-code >}}
540+
{{< /tab >}}
541+
{{< /tabpane >}}

‎website_and_docs/content/documentation/webdriver/bidirectional/bidi_api.ja.md‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,8 @@ driver.get("https://your-domain.com/login");
3333
{{< tab header="Python" text=true >}}
3434
{{< badge-code >}}
3535
{{< /tab >}}
36-
{{< tab header="CSharp" >}}
37-
NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
38-
{
39-
UriMatcher = (d) => d.Host.Contains("your-domain.com"),
40-
Credentials = new PasswordCredentials("admin", "password")
41-
};
42-
43-
INetwork networkInterceptor = driver.Manage().Network;
44-
networkInterceptor.AddAuthenticationHandler(handler);
45-
await networkInterceptor.StartMonitoring();
36+
{{< tab header="CSharp" text=true >}}
37+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L13-L24" >}}
4638
{{< /tab >}}
4739
{{< tab header="Ruby" >}}
4840
require 'selenium-webdriver'
@@ -452,6 +444,8 @@ fun kotlinJsErrorListener() {
452444
If you want to capture network events coming into the browser and you want manipulate them you are able to do
453445
it with the following examples.
454446

447+
### Intercept Responses
448+
455449
{{< tabpane langEqualsHeader=true >}}
456450
{{< tab header="Java" >}}
457451
import org.openqa.selenium.WebDriver;
@@ -480,7 +474,7 @@ it with the following examples.
480474
Currently unavailable in python due the inability to mix certain async and sync commands
481475
{{< /tab >}}
482476
{{< tab header="CSharp" text=true >}}
483-
{{< badge-code >}}
477+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L33-L48" >}}
484478
{{< /tab >}}
485479
{{< tab header="Ruby" >}}
486480
require 'selenium-webdriver'
@@ -526,3 +520,26 @@ val interceptor = new NetworkInterceptor(
526520
String source = driver.getPageSource()
527521
{{< /tab >}}
528522
{{< /tabpane >}}
523+
524+
### Intercept Requests
525+
526+
{{< tabpane text=true langEqualsHeader=true >}}
527+
{{< tab header="Java" >}}
528+
{{< badge-code >}}
529+
{{< /tab >}}
530+
{{< tab header="Python" >}}
531+
{{< badge-code >}}
532+
{{< /tab >}}
533+
{{< tab header="CSharp" >}}
534+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L56-L71" >}}
535+
{{< /tab >}}
536+
{{< tab header="Ruby" >}}
537+
{{< badge-code >}}
538+
{{< /tab >}}
539+
{{< tab header="JavaScript" >}}
540+
{{< badge-code >}}
541+
{{< /tab >}}
542+
{{< tab header="Kotlin" >}}
543+
{{< badge-code >}}
544+
{{< /tab >}}
545+
{{< /tabpane >}}

‎website_and_docs/content/documentation/webdriver/bidirectional/bidi_api.pt-br.md‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,8 @@ driver.get("https://your-domain.com/login");
2121
{{< tab header="Python" text=true >}}
2222
{{< badge-code >}}
2323
{{< /tab >}}
24-
{{< tab header="CSharp" >}}
25-
NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
26-
{
27-
UriMatcher = (d) => d.Host.Contains("your-domain.com"),
28-
Credentials = new PasswordCredentials("admin", "password")
29-
};
30-
31-
INetwork networkInterceptor = driver.Manage().Network;
32-
networkInterceptor.AddAuthenticationHandler(handler);
33-
await networkInterceptor.StartMonitoring();
24+
{{< tab header="CSharp" text=true >}}
25+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L13-L24" >}}
3426
{{< /tab >}}
3527
{{< tab header="Ruby" >}}
3628
require 'selenium-webdriver'
@@ -437,6 +429,8 @@ fun kotlinJsErrorListener() {
437429
Se você quer capturar eventos de rede que chegam ao navegador e deseja manipulá-los, você pode fazer
438430
com os exemplos a seguir.
439431

432+
### Intercept Responses
433+
440434
{{< tabpane langEqualsHeader=true >}}
441435
{{< tab header="Java" >}}
442436
import org.openqa.selenium.WebDriver;
@@ -465,7 +459,7 @@ com os exemplos a seguir.
465459
Currently unavailable in python due the inability to mix certain async and sync commands
466460
{{< /tab >}}
467461
{{< tab header="CSharp" text=true >}}
468-
{{< badge-code >}}
462+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L33-L48" >}}
469463
{{< /tab >}}
470464
{{< tab header="Ruby" >}}
471465
require 'selenium-webdriver'
@@ -511,3 +505,27 @@ val interceptor = new NetworkInterceptor(
511505
String source = driver.getPageSource()
512506
{{< /tab >}}
513507
{{< /tabpane >}}
508+
509+
510+
### Intercept Requests
511+
512+
{{< tabpane text=true langEqualsHeader=true >}}
513+
{{< tab header="Java" >}}
514+
{{< badge-code >}}
515+
{{< /tab >}}
516+
{{< tab header="Python" >}}
517+
{{< badge-code >}}
518+
{{< /tab >}}
519+
{{< tab header="CSharp" >}}
520+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/BidiApiTest.cs#L56-L71" >}}
521+
{{< /tab >}}
522+
{{< tab header="Ruby" >}}
523+
{{< badge-code >}}
524+
{{< /tab >}}
525+
{{< tab header="JavaScript" >}}
526+
{{< badge-code >}}
527+
{{< /tab >}}
528+
{{< tab header="Kotlin" >}}
529+
{{< badge-code >}}
530+
{{< /tab >}}
531+
{{< /tabpane >}}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /