Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/dotnet/SeleniumDocs/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected void StartDriver(string browserVersion = "stable")
{
BrowserVersion = browserVersion
};
options.AddArgument("--no-sandbox");
driver = new ChromeDriver(options);
}

Expand Down
52 changes: 49 additions & 3 deletions examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.DevTools;
using System.Linq;

using System.Threading;
using OpenQA.Selenium.DevTools.V129.Browser;
using OpenQA.Selenium.DevTools.V129.Network;
using OpenQA.Selenium.DevTools.V129.Performance;



namespace SeleniumDocs.BiDi.CDP
{
[TestClass]
Expand Down Expand Up @@ -37,14 +43,14 @@
Assert.AreEqual("Congratulations! You must have the proper credentials.",
driver.FindElement(By.TagName("p")).Text);
}

[TestMethod]
public async Task RecordNetworkResponse()
{
var contentType = new List<string>();

INetwork networkInterceptor = driver.Manage().Network;
networkInterceptor.NetworkResponseReceived += (_, e) =>
networkInterceptor.NetworkResponseReceived += (_, e) =>
{
contentType.Add(e.ResponseHeaders["content-type"]);
};
Expand Down Expand Up @@ -102,7 +108,7 @@

Assert.AreEqual("two", driver.FindElement(By.Id("result")).Text);
}

[TestMethod]
public async Task PerformanceMetrics()
{
Expand Down Expand Up @@ -147,5 +153,45 @@
Assert.AreEqual("gouda", cheese.Value);
}

[TestMethod]
public async Task WaitForDownload()
{
driver.Url = "https://www.selenium.dev/selenium/web/downloads/download.html";
var session = ((IDevTools)driver).GetDevToolsSession();

var downloadPath = Path.GetTempPath();
var downloadBehaviorCommandSettings = new SetDownloadBehaviorCommandSettings
{
Behavior = "allowAndName",
BrowserContextId = null,
DownloadPath = downloadPath,
EventsEnabled = true
};
await session.SendCommand(downloadBehaviorCommandSettings);

var downloadCompleted = new ManualResetEvent(false);
string? downloadId = null;

Check warning on line 173 in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 173 in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 173 in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 173 in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 173 in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 173 in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
bool downloaded = false;
session.DevToolsEventReceived += (sender, args) =>
{
var downloadState = args.EventData["state"]?.ToString();
if (args.EventName == "downloadProgress" &&
(string.Equals(downloadState, "completed") ||
string.Equals(downloadState, "canceled")))
{
downloadId = args.EventData["guid"].ToString();
downloaded = downloadState.Equals("completed");
downloadCompleted.Set();
}
};

driver.FindElement(By.Id("file-1")).Click();

Assert.IsTrue(downloadCompleted.WaitOne(TimeSpan.FromSeconds(10)));
Assert.IsTrue(downloaded);
var downloadedFilePath = Path.Combine(downloadPath, downloadId);
Assert.IsTrue(File.Exists(downloadedFilePath));
File.Delete(downloadedFilePath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Both requests and responses can be recorded or transformed.
{{< badge-implementation >}}
{{% /tab %}}
{{% tab header="CSharp" %}}
{{< badge-implementation >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L158-L168" >}}
{{% /tab %}}
{{% tab header="Ruby" %}}
{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L82-L88" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Both requests and responses can be recorded or transformed.
{{< badge-implementation >}}
{{% /tab %}}
{{% tab header="CSharp" %}}
{{< badge-implementation >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L158-L168" >}}
{{% /tab %}}
{{% tab header="Ruby" %}}
{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L82-L88" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Both requests and responses can be recorded or transformed.
{{< badge-implementation >}}
{{% /tab %}}
{{% tab header="CSharp" %}}
{{< badge-implementation >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L158-L168" >}}
{{% /tab %}}
{{% tab header="Ruby" %}}
{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L82-L88" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Both requests and responses can be recorded or transformed.
{{< badge-implementation >}}
{{% /tab %}}
{{% tab header="CSharp" %}}
{{< badge-implementation >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L158-L168" >}}
{{% /tab %}}
{{% tab header="Ruby" %}}
{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L82-L88" >}}
Expand Down
Loading