@@ -1,13 +1,18 @@
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.V137.Browser;
using OpenQA.Selenium.DevTools.V137.Network;
using OpenQA.Selenium.DevTools.V137.Performance;
namespace SeleniumDocs.BiDi.CDP
{
[TestClass]
Expand Down
Expand Up
@@ -44,7 +49,7 @@
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
@@ -147,5 +152,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 172
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 172
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 172
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.
Check warning
on line 172
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.
Check warning
on line 172
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 172
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 172
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 172
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 172
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 172
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 172
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 172
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.
bool downloaded = false;
session.DevToolsEventReceived += (sender, args) =>
{
var downloadState = args.EventData["state"]?.ToString();
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 176
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, nightly)
Argument 1: cannot convert from 'string' to 'int'
if (args.EventName == "downloadProgress" &&
(string.Equals(downloadState, "completed") ||
string.Equals(downloadState, "canceled")))
{
downloadId = args.EventData["guid"].ToString();
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (macos, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (ubuntu, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, stable)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, nightly)
Argument 1: cannot convert from 'string' to 'int'
Check failure
on line 181
in examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
View workflow job for this annotation
GitHub Actions / tests (windows, nightly)
Argument 1: cannot convert from 'string' to 'int'
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);
}
}
}