Skip to content

Commit 4efd49d

Browse files
committed
update code examples
1 parent bd868a3 commit 4efd49d

File tree

15 files changed

+53
-33
lines changed

15 files changed

+53
-33
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using OpenQA.Selenium;
4+
using OpenQA.Selenium.Chrome;
5+
6+
namespace SeleniumDocs.BiDi.CDP
7+
{
8+
[TestClass]
9+
public class CDPTest : BaseChromeTest
10+
{
11+
[TestMethod]
12+
public void SetCookie()
13+
{
14+
var cookie = new Dictionary<string, object>
15+
{
16+
{ "name", "cheese" },
17+
{ "value", "gouda" },
18+
{ "domain", "www.selenium.dev" },
19+
{ "secure", true }
20+
};
21+
((ChromeDriver)driver).ExecuteCdpCommand("Network.setCookie", cookie);
22+
23+
driver.Url = "https://www.selenium.dev";
24+
Cookie cheese = driver.Manage().Cookies.GetCookieNamed("cheese");
25+
Assert.AreEqual("gouda", cheese.Value);
26+
27+
}
28+
}
29+
}

examples/dotnet/SeleniumDocs/BiDi/ChromeDevtools/LoggingTest.cs renamed to examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using OpenQA.Selenium;
88
using OpenQA.Selenium.Support.UI;
99

10-
namespace SeleniumDocs.Bidirectional.ChromeDevTools
10+
namespace SeleniumDocs.BiDi.CDP
1111
{
1212
[TestClass]
1313
public class LoggingTest : BaseChromeTest

examples/dotnet/SeleniumDocs/BiDi/ChromeDevtools/NetworkTest.cs renamed to examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using OpenQA.Selenium.DevTools.V126.Performance;
99

1010

11-
namespace SeleniumDocs.BiDi.ChromeDevTools
11+
namespace SeleniumDocs.BiDi.CDP
1212
{
1313
[TestClass]
1414
public class NetworkTest : BaseTest

examples/dotnet/SeleniumDocs/BiDi/ChromeDevtools/ScriptTest.cs renamed to examples/dotnet/SeleniumDocs/BiDi/CDP/ScriptTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using OpenQA.Selenium;
88
using OpenQA.Selenium.Support.UI;
99

10-
namespace SeleniumDocs.Bidirectional.ChromeDevTools
10+
namespace SeleniumDocs.BiDi.CDP
1111
{
1212
[TestClass]
1313
public class ScriptTest : BaseChromeTest

examples/dotnet/SeleniumDocs/SeleniumDocs.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.6.0" />
1111
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
1212
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
13-
<PackageReference Include="Selenium.Support" Version="4.21.0" />
14-
<PackageReference Include="Selenium.WebDriver" Version="4.21.0" />
13+
<PackageReference Include="Selenium.Support" Version="4.22.0" />
14+
<PackageReference Include="Selenium.WebDriver" Version="4.22.0" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

examples/java/src/test/java/dev/selenium/bidi/webdriver_bidi/LogTest.java renamed to examples/java/src/test/java/dev/selenium/bidi/LoggingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.selenium.bidirectional.webdriver_bidi;
1+
package dev.selenium.bidi;
22

33
import dev.selenium.BaseTest;
44

@@ -18,7 +18,7 @@
1818
import org.openqa.selenium.firefox.FirefoxOptions;
1919
import org.openqa.selenium.support.ui.WebDriverWait;
2020

21-
class LogTest extends BaseTest {
21+
class LoggingTest extends BaseTest {
2222

2323
@BeforeEach
2424
public void setup() {

examples/python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
selenium==4.21.0
1+
selenium==4.22.0
22
pytest
33
trio
44
pytest-trio

examples/python/tests/bidi/cdp/test_logging.py renamed to examples/python/tests/bidi/cdp/test_logs.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ async def test_console_log(driver):
99
driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
1010

1111
async with driver.bidi_connection() as session:
12-
log = Log(driver, session)
13-
14-
async with log.add_listener(Console.ALL) as messages:
12+
async with Log(driver, session).add_listener(Console.ALL) as messages:
1513
driver.find_element(by=By.ID, value='consoleLog').click()
1614

1715
assert messages["message"] == "Hello, world!"
@@ -22,9 +20,7 @@ async def test_js_error(driver):
2220
driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
2321

2422
async with driver.bidi_connection() as session:
25-
log = Log(driver, session)
26-
27-
async with log.add_js_error_listener() as messages:
23+
async with Log(driver, session).add_js_error_listener() as messages:
2824
driver.find_element(by=By.ID, value='jsException').click()
2925

3026
assert "Error: Not working" in messages.exception_details.exception.description

examples/python/tests/bidi/cdp/test_network.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,26 @@ async def test_basic_auth(driver):
1212

1313
credentials = base64.b64encode("admin:admin".encode()).decode()
1414
auth = {'authorization': 'Basic ' + credentials}
15-
1615
await connection.session.execute(connection.devtools.network.set_extra_http_headers(Headers(auth)))
1716

1817
driver.get('https://the-internet.herokuapp.com/basic_auth')
1918

2019
success = driver.find_element(by=By.TAG_NAME, value='p')
2120
assert success.text == 'Congratulations! You must have the proper credentials.'
2221

22+
@pytest.mark.trio
23+
async def test_performance(driver):
24+
driver.get('https://www.selenium.dev/selenium/web/frameset.html')
25+
26+
async with driver.bidi_connection() as connection:
27+
await connection.session.execute(connection.devtools.performance.enable())
28+
metric_list = await connection.session.execute(connection.devtools.performance.get_metrics())
29+
30+
metrics = {metric.name: metric.value for metric in metric_list}
31+
32+
assert metrics["DevToolsCommandDuration"] > 0
33+
assert metrics["Frames"] == 12
34+
2335
@pytest.mark.trio
2436
async def test_set_cookie(driver):
2537
async with driver.bidi_connection() as connection:
@@ -29,24 +41,9 @@ async def test_set_cookie(driver):
2941
domain="www.selenium.dev",
3042
secure=True
3143
)
32-
3344
await connection.session.execute(execution)
3445

3546
driver.get("https://www.selenium.dev")
3647
cheese = driver.get_cookie("cheese")
3748

3849
assert cheese["value"] == "gouda"
39-
40-
@pytest.mark.trio
41-
async def test_performance(driver):
42-
driver.get('https://www.selenium.dev/selenium/web/frameset.html')
43-
44-
async with driver.bidi_connection() as connection:
45-
await connection.session.execute(connection.devtools.performance.enable())
46-
47-
metric_list = await connection.session.execute(connection.devtools.performance.get_metrics())
48-
49-
metrics = {metric.name: metric.value for metric in metric_list}
50-
51-
assert metrics["DevToolsCommandDuration"] > 0
52-
assert metrics["Frames"] == 12

examples/python/tests/bidi/cdp/test_script.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
@pytest.mark.trio
77
async def test_mutation(driver):
88
async with driver.bidi_connection() as session:
9-
log = Log(driver, session)
10-
11-
async with log.mutation_events() as event:
9+
async with Log(driver, session).mutation_events() as event:
1210
driver.get('https://www.selenium.dev/selenium/web/dynamic.html')
1311
driver.find_element(By.ID, "reveal").click()
1412

0 commit comments

Comments
 (0)