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

Release 4.22 Updates #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
diemol merged 13 commits into trunk from 4_22
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
6c99615
Blog post - still needs examples links
titusfortner Jun 21, 2024
603cb0c
update version and links in downloads
titusfortner Jun 24, 2024
f068e27
[examples] reorganize code examples for BiDi
titusfortner Jun 24, 2024
15060fb
[examples] update Ruby BiDi code
titusfortner Jun 24, 2024
bd868a3
[examples] update Python examples
titusfortner Jun 24, 2024
4efd49d
update code examples
titusfortner Jun 24, 2024
b68d0b8
more example updates
titusfortner Jun 24, 2024
b130f8e
update all BiDi documentation
titusfortner Jun 25, 2024
fbaabc6
update links to bidi documentation
titusfortner Jun 25, 2024
b769019
wrong github reference
titusfortner Jun 25, 2024
738629d
restore java and javascript low level bidi examples
titusfortner Jun 25, 2024
bd7f5d0
Merge branch 'trunk' into 4_22
pujagani Jun 26, 2024
02b3af6
Merge branch 'trunk' into 4_22
diemol Jul 10, 2024
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
29 changes: 29 additions & 0 deletions examples/dotnet/SeleniumDocs/BiDi/CDP/CDPTest.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumDocs.BiDi.CDP
{
[TestClass]
public class CDPTest : BaseChromeTest
{
[TestMethod]
public void SetCookie()
{
var cookie = new Dictionary<string, object>
{
{ "name", "cheese" },
{ "value", "gouda" },
{ "domain", "www.selenium.dev" },
{ "secure", true }
};
((ChromeDriver)driver).ExecuteCdpCommand("Network.setCookie", cookie);

driver.Url = "https://www.selenium.dev";
Cookie cheese = driver.Manage().Cookies.GetCookieNamed("cheese");
Assert.AreEqual("gouda", cheese.Value);

}
}
}
56 changes: 56 additions & 0 deletions examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,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"));
}
}
}
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
using System;
using System.Collections;
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;
using OpenQA.Selenium.DevTools;
using System.Linq;
using OpenQA.Selenium.DevTools.V126.Network;
using OpenQA.Selenium.DevTools.V126.Performance;

namespace SeleniumDocs.Bidirectional.ChromeDevTools

namespace SeleniumDocs.BiDi.CDP
{
[TestClass]
public class BidiApiTest : BaseChromeTest
public class NetworkTest : BaseTest
{
[TestInitialize]
public void Startup()
{
StartDriver("126");
}

[TestMethod]
public async Task BasicAuthentication()
{
Expand All @@ -20,104 +27,16 @@ public async Task BasicAuthentication()
UriMatcher = uri => uri.AbsoluteUri.Contains("herokuapp"),
Credentials = new PasswordCredentials("admin", "admin")
};

var networkInterceptor = driver.Manage().Network;
networkInterceptor.AddAuthenticationHandler(handler);

await networkInterceptor.StartMonitoring();

driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/basic_auth");
await networkInterceptor.StopMonitoring();

Assert.AreEqual("Congratulations! You must have the proper credentials.",
driver.FindElement(By.TagName("p")).Text);
}

[TestMethod]
public async Task PinScript()
{
driver.Url = "https://www.selenium.dev/selenium/web/xhtmlTest.html";
var element = driver.FindElement(By.Id("id1"));

var key = await new JavaScriptEngine(driver).PinScript("return arguments;");

var arguments = ((WebDriver)driver).ExecuteScript(key, 1, true, element);

var expected = new List<object>
{
1L,
true,
element
};
CollectionAssert.AreEqual(expected, (ICollection)arguments);
}

[TestMethod]
public async Task MutatedElements()
{
driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html";

var mutations = new List<IWebElement>();
using IJavaScriptEngine monitor = new JavaScriptEngine(driver);
monitor.DomMutated += (_, e) =>
{
var locator = By.CssSelector($"*[data-__webdriver_id='{e.AttributeData.TargetId}']");
mutations.Add(driver.FindElement(locator));
};

await monitor.StartEventMonitoring();
await monitor.EnableDomMutationMonitoring();

driver.FindElement(By.Id("reveal")).Click();

new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => !mutations.IsNullOrEmpty());
await monitor.DisableDomMutationMonitoring();
monitor.StopEventMonitoring();

var revealed = driver.FindElement(By.Id("revealed"));
Assert.AreEqual(revealed, mutations[0]);
}

[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"));
}

[TestMethod]
public async Task RecordNetworkResponse()
Expand All @@ -129,8 +48,8 @@ public async Task RecordNetworkResponse()
{
contentType.Add(e.ResponseHeaders["content-type"]);
};

await networkInterceptor.StartMonitoring();

driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/blank.html");
await networkInterceptor.StopMonitoring();

Expand All @@ -149,11 +68,10 @@ public async Task TransformNetworkResponse()
Body = "Creamy, delicious cheese!"
}
};

INetwork networkInterceptor = driver.Manage().Network;
networkInterceptor.AddResponseHandler(handler);

await networkInterceptor.StartMonitoring();

driver.Navigate().GoToUrl("https://www.selenium.dev");
await networkInterceptor.StopMonitoring();

Expand All @@ -174,16 +92,60 @@ public async Task TransformNetworkRequest()
return request;
}
};

INetwork networkInterceptor = driver.Manage().Network;
networkInterceptor.AddRequestHandler(handler);

await networkInterceptor.StartMonitoring();

driver.Url = "https://www.selenium.dev/selenium/web/devToolsRequestInterceptionTest.html";
driver.FindElement(By.TagName("button")).Click();
await networkInterceptor.StopMonitoring();

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

[TestMethod]
public async Task PerformanceMetrics()
{
driver.Url = "https://www.selenium.dev/selenium/web/frameset.html";

var session = ((IDevTools)driver).GetDevToolsSession();
var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V126.DevToolsSessionDomains>();

await domains.Performance.Enable(new OpenQA.Selenium.DevTools.V126.Performance.EnableCommandSettings());
var metricsResponse =
await session.SendCommand<GetMetricsCommandSettings, GetMetricsCommandResponse>(
new GetMetricsCommandSettings()
);

var metrics = metricsResponse.Metrics.ToDictionary(
dict => dict.Name,
dict => dict.Value
);

Assert.IsTrue(metrics["DevToolsCommandDuration"] > 0);
Assert.AreEqual(12, metrics["Frames"]);
}

[TestMethod]
public async Task SetCookie()
{
var session = ((IDevTools)driver).GetDevToolsSession();
var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V126.DevToolsSessionDomains>();
await domains.Network.Enable(new OpenQA.Selenium.DevTools.V126.Network.EnableCommandSettings());

var cookieCommandSettings = new SetCookieCommandSettings
{
Name = "cheese",
Value = "gouda",
Domain = "www.selenium.dev",
Secure = true
};
await domains.Network.SetCookie(cookieCommandSettings);

driver.Url = "https://www.selenium.dev";
OpenQA.Selenium.Cookie cheese = driver.Manage().Cookies.GetCookieNamed("cheese");
Assert.AreEqual("gouda", cheese.Value);
}

}
}
58 changes: 58 additions & 0 deletions examples/dotnet/SeleniumDocs/BiDi/CDP/ScriptTest.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections;
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 ScriptTest : BaseChromeTest
{
[TestMethod]
public async Task PinScript()
{
driver.Url = "https://www.selenium.dev/selenium/web/xhtmlTest.html";
var element = driver.FindElement(By.Id("id1"));

var key = await new JavaScriptEngine(driver).PinScript("return arguments;");
var arguments = ((WebDriver)driver).ExecuteScript(key, 1, true, element);

var expected = new List<object>
{
1L,
true,
element
};
CollectionAssert.AreEqual(expected, (ICollection)arguments);
}

[TestMethod]
public async Task MutatedElements()
{
driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html";
var mutations = new List<IWebElement>();

using IJavaScriptEngine monitor = new JavaScriptEngine(driver);
monitor.DomMutated += (_, e) =>
{
var locator = By.CssSelector($"*[data-__webdriver_id='{e.AttributeData.TargetId}']");
mutations.Add(driver.FindElement(locator));
};
await monitor.StartEventMonitoring();
await monitor.EnableDomMutationMonitoring();

driver.FindElement(By.Id("reveal")).Click();

new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => !mutations.IsNullOrEmpty());
await monitor.DisableDomMutationMonitoring();
monitor.StopEventMonitoring();

var revealed = driver.FindElement(By.Id("revealed"));
Assert.AreEqual(revealed, mutations[0]);
}
}
}
Loading

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