-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [java] update dependencies * reorganize bidi tests * update all the docs to match examples including for all translations [deploy site]
- Loading branch information
1 parent
0243b1b
commit 70802b6
Showing
83 changed files
with
4,227 additions
and
4,441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
189 changes: 189 additions & 0 deletions
189
examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
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.Bidirectional.ChromeDevTools | ||
{ | ||
[TestClass] | ||
public class BidiApiTest : BaseChromeTest | ||
{ | ||
[TestMethod] | ||
public async Task BasicAuthentication() | ||
{ | ||
var handler = new NetworkAuthenticationHandler() | ||
{ | ||
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() | ||
{ | ||
var contentType = new List<string>(); | ||
|
||
INetwork networkInterceptor = driver.Manage().Network; | ||
networkInterceptor.NetworkResponseReceived += (_, e) => | ||
{ | ||
contentType.Add(e.ResponseHeaders["content-type"]); | ||
}; | ||
|
||
await networkInterceptor.StartMonitoring(); | ||
driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/blank.html"); | ||
await networkInterceptor.StopMonitoring(); | ||
|
||
Assert.AreEqual("text/html; charset=utf-8", contentType[0]); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TransformNetworkResponse() | ||
{ | ||
var handler = new NetworkResponseHandler() | ||
{ | ||
ResponseMatcher = _ => true, | ||
ResponseTransformer = _ => new HttpResponseData | ||
{ | ||
StatusCode = 200, | ||
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(); | ||
|
||
var body = driver.FindElement(By.TagName("body")); | ||
Assert.AreEqual("Creamy, delicious cheese!", body.Text); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TransformNetworkRequest() | ||
{ | ||
var handler = new NetworkRequestHandler | ||
{ | ||
RequestMatcher = request => request.Url.Contains("one.js"), | ||
RequestTransformer = request => | ||
{ | ||
request.Url = request.Url.Replace("one", "two"); | ||
|
||
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); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.DevTools; | ||
using OpenQA.Selenium.DevTools.V118.Network; | ||
using OpenQA.Selenium.DevTools.V118.Performance; | ||
|
||
namespace SeleniumDocs.Bidirectional.ChromeDevtools | ||
{ | ||
[TestClass] | ||
public class CdpApiTest : BaseTest | ||
{ | ||
[TestInitialize] | ||
public void Startup() | ||
{ | ||
StartDriver("118"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SetCookie() | ||
{ | ||
var session = ((IDevTools)driver).GetDevToolsSession(); | ||
var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V118.DevToolsSessionDomains>(); | ||
await domains.Network.Enable(new OpenQA.Selenium.DevTools.V118.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); | ||
} | ||
|
||
[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.V118.DevToolsSessionDomains>(); | ||
await domains.Performance.Enable(new OpenQA.Selenium.DevTools.V118.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 BasicAuth() | ||
{ | ||
var session = ((IDevTools)driver).GetDevToolsSession(); | ||
var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V118.DevToolsSessionDomains>(); | ||
await domains.Network.Enable(new OpenQA.Selenium.DevTools.V118.Network.EnableCommandSettings()); | ||
|
||
var encodedAuth = Convert.ToBase64String(Encoding.Default.GetBytes("admin:admin")); | ||
var headerSettings = new SetExtraHTTPHeadersCommandSettings | ||
{ | ||
Headers = new Headers() | ||
{ | ||
{ "authorization", "Basic " + encodedAuth } | ||
} | ||
}; | ||
|
||
await domains.Network.SetExtraHTTPHeaders(headerSettings); | ||
|
||
driver.Url = "https://the-internet.herokuapp.com/basic_auth"; | ||
|
||
var element = driver.FindElement(By.TagName("p")); | ||
Assert.AreEqual("Congratulations! You must have the proper credentials.", element.Text); | ||
} | ||
} | ||
} |
Oops, something went wrong.