Skip to content

Commit 8c38e8f

Browse files
authored
Merge branch 'trunk' into petesong/add-practice-example
2 parents b15b0a2 + 95fdcc4 commit 8c38e8f

38 files changed

+866
-303
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ on:
44
push:
55
branches:
66
- trunk
7+
workflow_dispatch:
78

89
jobs:
910
deploy:
10-
if: contains(toJson(github.event.commits), '[deploy site]') == true
11+
if: contains(toJson(github.event.commits), '[deploy site]') == true || github.event_name == 'workflow_dispatch'
1112
runs-on: ubuntu-24.04
1213
steps:
1314
- name: Checkout repo

examples/dotnet/SeleniumDocs/Elements/InformationTest.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,43 @@ public void TestInformationCommands(){
2222
bool isEmailVisible = driver.FindElement(By.Name("email_input")).Displayed;
2323
Assert.AreEqual(isEmailVisible, true);
2424

25-
//isEnabled
26-
//returns true if element is enabled else returns false
25+
// isEnabled
26+
// returns true if element is enabled else returns false
2727
bool isEnabledButton = driver.FindElement(By.Name("button_input")).Enabled;
2828
Assert.AreEqual(isEnabledButton, true);
2929

30-
//isSelected
31-
//returns true if element is checked else returns false
30+
// isSelected
31+
// returns true if element is checked else returns false
3232
bool isSelectedCheck = driver.FindElement(By.Name("checkbox_input")).Selected;
3333
Assert.AreEqual(isSelectedCheck, true);
3434

35-
//TagName
36-
//returns TagName of the element
35+
// TagName
36+
// returns TagName of the element
3737
string tagNameInp = driver.FindElement(By.Name("email_input")).TagName;
3838
Assert.AreEqual(tagNameInp, "input");
3939

40-
//Get Location and Size
41-
//Get Location
40+
// Get Location and Size
41+
// Get Location
4242
IWebElement rangeElement = driver.FindElement(By.Name("range_input"));
4343
Point point = rangeElement.Location;
4444
Assert.IsNotNull(point.X);
45-
//Get Size
45+
// Get Size
4646
int height=rangeElement.Size.Height;
4747
Assert.IsNotNull(height);
4848

4949
// Retrieves the computed style property 'font-size' of field
5050
string cssValue = driver.FindElement(By.Name("color_input")).GetCssValue("font-size");
5151
Assert.AreEqual(cssValue, "13.3333px");
5252

53-
//GetText
53+
// GetText
5454
// Retrieves the text of the element
5555
string text = driver.FindElement(By.TagName("h1")).Text;
5656
Assert.AreEqual(text, "Testing Inputs");
5757

58-
//FetchAttributes
59-
//identify the email text box
58+
// FetchAttributes
59+
// identify the email text box
6060
IWebElement emailTxt = driver.FindElement(By.Name("email_input"));
61-
//fetch the value property associated with the textbox
61+
// fetch the value property associated with the textbox
6262
string valueInfo = emailTxt.GetAttribute("value");
6363
Assert.AreEqual(valueInfo, "admin@localhost");
6464

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package dev.selenium.bidirectional.webdriver_bidi.user_context;
2+
3+
import org.junit.jupiter.api.AfterEach;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
import org.openqa.selenium.By;
8+
import org.openqa.selenium.WebDriver;
9+
import org.openqa.selenium.WebElement;
10+
import org.openqa.selenium.firefox.FirefoxDriver;
11+
import org.openqa.selenium.firefox.FirefoxOptions;
12+
13+
class MultipleInstanceParallelTest {
14+
15+
private WebDriver driver;
16+
17+
@BeforeEach
18+
public void setup() {
19+
FirefoxOptions options = new FirefoxOptions();
20+
options.setCapability("webSocketUrl", true);
21+
options.addArguments("-private");
22+
driver = new FirefoxDriver(options);
23+
}
24+
25+
@Test
26+
void canSwitchToBlue() {
27+
driver.get("https://www.selenium.dev/selenium/web/cookie-background.html");
28+
29+
WebElement body = driver.findElement(By.tagName("body"));
30+
String bgColor = body.getCssValue("background-color");
31+
32+
String expectedColor = "rgb(255, 255, 255)";
33+
// Background color is white
34+
Assertions.assertEquals(bgColor, expectedColor);
35+
36+
driver.get("https://www.selenium.dev/selenium/web/cookie-background.html");
37+
38+
driver.findElement(By.id("blue-btn")).click();
39+
body = driver.findElement(By.tagName("body"));
40+
bgColor = body.getCssValue("background-color");
41+
42+
expectedColor = "rgb(173, 216, 230)";
43+
// Background color is blue
44+
Assertions.assertEquals(bgColor, expectedColor);
45+
46+
System.out.println(
47+
Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
48+
.getMethodName() + " => executed successfully");
49+
}
50+
51+
@Test
52+
void canSwitchToGreen() {
53+
driver.get("https://www.selenium.dev/selenium/web/cookie-background.html");
54+
55+
WebElement body = driver.findElement(By.tagName("body"));
56+
String bgColor = body.getCssValue("background-color");
57+
58+
String expectedColor = "rgb(255, 255, 255)";
59+
Assertions.assertEquals(bgColor, expectedColor);
60+
61+
driver.findElement(By.id("green-btn")).click();
62+
body = driver.findElement(By.tagName("body"));
63+
bgColor = body.getCssValue("background-color");
64+
65+
expectedColor = "rgb(144, 238, 144)";
66+
Assertions.assertEquals(bgColor, expectedColor);
67+
68+
System.out.println(
69+
Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
70+
.getMethodName() + " => executed successfully");
71+
}
72+
73+
@Test
74+
void canHaveTheDefaultBackgroundColor() {
75+
driver.get("https://www.selenium.dev/selenium/web/cookie-background.html");
76+
77+
WebElement body = driver.findElement(By.tagName("body"));
78+
String bgColor = body.getCssValue("background-color");
79+
80+
String expectedColor = "rgb(255, 255, 255)";
81+
Assertions.assertEquals(bgColor, expectedColor);
82+
83+
System.out.println(
84+
Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
85+
.getMethodName() + " => executed successfully");
86+
}
87+
88+
@AfterEach
89+
public void cleanup() {
90+
driver.quit();
91+
}
92+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package dev.selenium.bidirectional.webdriver_bidi.user_context;
2+
3+
import org.junit.jupiter.api.AfterAll;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
import org.openqa.selenium.WebDriver;
9+
import org.openqa.selenium.WindowType;
10+
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
11+
import org.openqa.selenium.bidi.browsingcontext.CreateContextParameters;
12+
import org.openqa.selenium.bidi.browsingcontext.Locator;
13+
import org.openqa.selenium.bidi.browsingcontext.ReadinessState;
14+
import org.openqa.selenium.bidi.module.Browser;
15+
import org.openqa.selenium.bidi.module.Input;
16+
import org.openqa.selenium.bidi.script.NodeProperties;
17+
import org.openqa.selenium.bidi.script.RemoteValue;
18+
import org.openqa.selenium.firefox.FirefoxDriver;
19+
import org.openqa.selenium.firefox.FirefoxOptions;
20+
import org.openqa.selenium.interactions.Actions;
21+
import org.openqa.selenium.remote.RemoteWebElement;
22+
23+
class SingleInstanceCookieParallelTest {
24+
25+
private static WebDriver driver;
26+
BrowsingContext context;
27+
28+
@BeforeAll
29+
public static void beforeAll() {
30+
FirefoxOptions options = new FirefoxOptions();
31+
options.setCapability("webSocketUrl", true);
32+
driver = new FirefoxDriver(options);
33+
34+
// To use Grid uncomment the lines below
35+
36+
// driver = new RemoteWebDriver(
37+
// new URL("http://localhost:4444"),
38+
// options, false);
39+
//
40+
// Augmenter augmenter = new Augmenter();
41+
// driver = augmenter.augment(driver);
42+
}
43+
44+
@BeforeEach
45+
public void setup() {
46+
Browser browser = new Browser(driver);
47+
String userContext = browser.createUserContext();
48+
49+
CreateContextParameters parameters = new CreateContextParameters(WindowType.TAB);
50+
parameters.userContext(userContext);
51+
52+
context = new BrowsingContext(driver, parameters);
53+
}
54+
55+
@Test
56+
void canSwitchToBlue() {
57+
context.navigate("https://www.selenium.dev/selenium/web/cookie-background.html", ReadinessState.COMPLETE);
58+
59+
RemoteValue value = context.locateNode(Locator.xpath("/html/body/button[1]"));
60+
61+
Input inputModule = new Input(driver);
62+
Actions actions = new Actions(driver);
63+
64+
RemoteWebElement element = new RemoteWebElement();
65+
element.setId(value.getSharedId().get());
66+
actions.moveToElement(element).click();
67+
68+
inputModule.perform(context.getId(), actions.getSequences());
69+
70+
value = context.locateNode(Locator.xpath("/html/body"));
71+
72+
NodeProperties properties = (NodeProperties) value.getValue().get();
73+
String bgColor = properties.getAttributes().get().get("style");
74+
75+
Assertions.assertEquals(bgColor, "background-color: lightblue;");
76+
System.out.println(
77+
Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
78+
.getMethodName() + " => executed successfully");
79+
}
80+
81+
@Test
82+
void canSwitchToGreen() {
83+
context.navigate("https://www.selenium.dev/selenium/web/cookie-background.html", ReadinessState.COMPLETE);
84+
85+
RemoteValue value = context.locateNode(Locator.xpath("/html/body"));
86+
87+
NodeProperties properties = (NodeProperties) value.getValue().get();
88+
String bgColor = properties.getAttributes().get().get("style");
89+
90+
Assertions.assertEquals(bgColor, "background-color: white;");
91+
92+
value = context.locateNode(Locator.xpath("/html/body/button[2]"));
93+
94+
Input inputModule = new Input(driver);
95+
Actions actions = new Actions(driver);
96+
97+
RemoteWebElement element = new RemoteWebElement();
98+
element.setId(value.getSharedId().get());
99+
actions.moveToElement(element).click();
100+
101+
inputModule.perform(context.getId(), actions.getSequences());
102+
103+
value = context.locateNode(Locator.xpath("/html/body"));
104+
105+
properties = (NodeProperties) value.getValue().get();
106+
bgColor = properties.getAttributes().get().get("style");
107+
108+
Assertions.assertEquals(bgColor, "background-color: lightgreen;");
109+
System.out.println(
110+
Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
111+
.getMethodName() + " => executed successfully");
112+
}
113+
114+
@Test
115+
void canHaveTheDefaultBackgroundColor() {
116+
context.navigate("https://www.selenium.dev/selenium/web/cookie-background.html", ReadinessState.COMPLETE);
117+
118+
RemoteValue value = context.locateNode(Locator.xpath("/html/body"));
119+
120+
NodeProperties properties = (NodeProperties) value.getValue().get();
121+
String bgColor = properties.getAttributes().get().get("style");
122+
123+
Assertions.assertEquals(bgColor, "background-color: white;");
124+
System.out.println(
125+
Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
126+
.getMethodName() + " => executed successfully");
127+
}
128+
129+
@AfterAll
130+
public static void cleanup() {
131+
driver.quit();
132+
}
133+
}

examples/java/src/test/java/dev/selenium/elements/InformationTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ public void informationWithElements() {
1919
// Navigate to Url
2020
driver.get("https://www.selenium.dev/selenium/web/inputs.html");
2121

22-
// isDisplayed
22+
// isDisplayed
2323
// Get boolean value for is element display
2424
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
2525
assertEquals(isEmailVisible,true);
2626

27-
//isEnabled
28-
//returns true if element is enabled else returns false
27+
// isEnabled
28+
// returns true if element is enabled else returns false
2929
boolean isEnabledButton = driver.findElement(By.name("button_input")).isEnabled();
3030
assertEquals(isEnabledButton,true);
3131

32-
//isSelected
33-
//returns true if element is checked else returns false
32+
// isSelected
33+
// returns true if element is checked else returns false
3434
boolean isSelectedCheck = driver.findElement(By.name("checkbox_input")).isSelected();
3535
assertEquals(isSelectedCheck,true);
3636

37-
//TagName
38-
//returns TagName of the element
37+
// TagName
38+
// returns TagName of the element
3939
String tagNameInp = driver.findElement(By.name("email_input")).getTagName();
4040
assertEquals(tagNameInp,"input");
4141

42-
//GetRect
42+
// GetRect
4343
// Returns height, width, x and y coordinates referenced element
4444
Rectangle res = driver.findElement(By.name("range_input")).getRect();
4545
// Rectangle class provides getX,getY, getWidth, getHeight methods
@@ -51,16 +51,16 @@ public void informationWithElements() {
5151
assertEquals(cssValue, "13.3333px");
5252

5353

54-
//GetText
54+
// GetText
5555
// Retrieves the text of the element
5656
String text = driver.findElement(By.tagName("h1")).getText();
5757
assertEquals(text, "Testing Inputs");
5858

5959

60-
//FetchAttributes
61-
//identify the email text box
60+
// FetchAttributes
61+
// identify the email text box
6262
WebElement emailTxt = driver.findElement(By.name(("email_input")));
63-
//fetch the value property associated with the textbox
63+
// fetch the value property associated with the textbox
6464
String valueInfo = emailTxt.getAttribute("value");
6565
assertEquals(valueInfo,"admin@localhost");
6666

examples/kotlin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<properties>
1212
<kotlin.version>2.1.0</kotlin.version>
1313

14-
<slf4j.version>2.0.16</slf4j.version>
14+
<slf4j.version>2.0.17</slf4j.version>
1515
<logback.version>1.5.17</logback.version>
1616

1717
<junit5.version>5.12.0</junit5.version>

examples/python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
selenium==4.29.0
2-
pytest==8.3.4
2+
pytest==8.3.5
33
trio==0.29.0
44
pytest-trio==0.8.0
55
pytest-rerunfailures==14.0

0 commit comments

Comments
 (0)