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

Commit 247ac2e

Browse files
Merge branch 'trunk' into update-python-browsers-docs
2 parents f730fe6 + 65c0f38 commit 247ac2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1887
-277
lines changed

‎.github/workflows/java-examples.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
command: |
6868
pip install yq
6969
xml_content=$(curl -sf https://oss.sonatype.org/service/local/repositories/snapshots/content/org/seleniumhq/selenium/selenium-java/)
70-
latest_snapshot=$(echo $xml_content | xq '.content.data."content-item"' | jq -r 'sort_by(.lastModified) | reverse | .[0] | .text')
70+
latest_snapshot=$(echo $xml_content | xq '.content.data."content-item"' | jq -r .text)
7171
echo $latest_snapshot
7272
cd examples/java
7373
mvn -B -U test -Dselenium.version="$latest_snapshot"
@@ -81,7 +81,7 @@ jobs:
8181
command: |
8282
pip install yq
8383
$xml_content = Invoke-WebRequest -Uri "https://oss.sonatype.org/service/local/repositories/snapshots/content/org/seleniumhq/selenium/selenium-java/"
84-
$latest_snapshot = $xml_content.Content | xq '.content.data.\"content-item\"' | jq -r 'sort_by(.lastModified) | reverse | .[0] | .text'
84+
$latest_snapshot = $xml_content.Content | xq '.content.data.\"content-item\"' | jq -r .text
8585
Write-Output $latest_snapshot
8686
cd examples/java
8787
mvn -B -U test "-Dselenium.version=$latest_snapshot"

‎examples/java/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<plugin>
5656
<groupId>org.apache.maven.plugins</groupId>
5757
<artifactId>maven-surefire-plugin</artifactId>
58-
<version>3.3.1</version>
58+
<version>3.4.0</version>
5959
<configuration>
6060
<properties>
6161
<configurationParameters>

‎examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package dev.selenium.drivers;
22

33
import dev.selenium.BaseTest;
4+
5+
import java.time.Duration;
6+
import java.time.temporal.ChronoUnit;
7+
48
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.Assertions;
510
import org.openqa.selenium.PageLoadStrategy;
11+
import org.openqa.selenium.UnexpectedAlertBehaviour;
612
import org.openqa.selenium.WebDriver;
713
import org.openqa.selenium.chrome.ChromeOptions;
14+
import org.openqa.selenium.remote.CapabilityType;
815
import org.openqa.selenium.chrome.ChromeDriver;
916

1017
public class OptionsTest extends BaseTest {
@@ -60,5 +67,107 @@ public void setAcceptInsecureCerts() {
6067
driver.quit();
6168
}
6269
}
70+
71+
@Test
72+
public void getBrowserName() {
73+
ChromeOptions chromeOptions = new ChromeOptions();
74+
String name = chromeOptions.getBrowserName();
75+
Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
76+
}
77+
78+
@Test
79+
public void setBrowserVersion() {
80+
ChromeOptions chromeOptions = new ChromeOptions();
81+
String version = "latest";
82+
chromeOptions.setBrowserVersion(version);
83+
Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
84+
}
85+
86+
@Test
87+
public void setPlatformName() {
88+
ChromeOptions chromeOptions = new ChromeOptions();
89+
String platform = "OS X 10.6";
90+
chromeOptions.setPlatformName(platform);
91+
Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
92+
}
93+
94+
@Test
95+
public void setScriptTimeout() {
96+
ChromeOptions chromeOptions = new ChromeOptions();
97+
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
98+
chromeOptions.setScriptTimeout(duration);
99+
100+
WebDriver driver = new ChromeDriver(chromeOptions);
101+
try {
102+
Duration timeout = driver.manage().timeouts().getScriptTimeout();
103+
Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
104+
} finally {
105+
driver.quit();
106+
}
107+
}
108+
109+
@Test
110+
public void setPageLoadTimeout() {
111+
ChromeOptions chromeOptions = new ChromeOptions();
112+
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
113+
chromeOptions.setPageLoadTimeout(duration);
114+
115+
WebDriver driver = new ChromeDriver(chromeOptions);
116+
try {
117+
Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
118+
Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
119+
} finally {
120+
driver.quit();
121+
}
122+
}
123+
124+
@Test
125+
public void setImplicitWaitTimeout() {
126+
ChromeOptions chromeOptions = new ChromeOptions();
127+
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
128+
chromeOptions.setImplicitWaitTimeout(duration);
129+
130+
WebDriver driver = new ChromeDriver(chromeOptions);
131+
try {
132+
Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
133+
Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
134+
} finally {
135+
driver.quit();
136+
}
137+
}
138+
139+
@Test
140+
public void setUnhandledPromptBehaviour() {
141+
ChromeOptions chromeOptions = new ChromeOptions();
142+
chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
143+
//verify the capability object is not null
144+
Object capabilityObject = chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR);
145+
Assertions.assertNotNull(capabilityObject, "Capability UNHANDLED_PROMPT_BEHAVIOUR should not be null.");
146+
Assertions.assertEquals(capabilityObject.toString(), UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY.toString());
147+
}
148+
149+
@Test
150+
public void setWindowRect() {
151+
ChromeOptions chromeOptions = new ChromeOptions();
152+
chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
153+
//verify the capability object is not null
154+
Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
155+
Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");
156+
157+
Boolean capability = (Boolean) capabilityObject;
158+
Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
159+
}
160+
161+
@Test
162+
public void setStrictFileInteractability() {
163+
ChromeOptions chromeOptions = new ChromeOptions();
164+
chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
165+
//verify the capability object is not null
166+
Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
167+
Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");
168+
169+
Boolean capability = (Boolean) capabilityObject;
170+
Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
171+
}
63172
}
64173

‎examples/kotlin/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<junit5.version>5.11.0</junit5.version>
1818
<wdm.version>5.2.3</wdm.version>
1919

20-
<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version>
20+
<maven-surefire-plugin.version>3.4.0</maven-surefire-plugin.version>
2121

2222
<java.version>1.8</java.version>
2323
<selenium.version>4.23.1</selenium.version>

‎examples/python/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ pytest
2828
```
2929

3030
> Please keep some patience - If you are doing it for the first time, it will take a little while to verify and download the browser drivers
31+
32+
## Execute a specific example
33+
To run a specific Selenium Python example, use the following command:
34+
```bash
35+
python first_script.py
36+
```
37+
38+
Make sure to replace `first_script.py` with the path and name of the example you want to run.

‎examples/python/tests/getting_started/using_selenium_tests.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ def test_eight_components():
2323
assert value == "Received!"
2424

2525
driver.quit()
26+
27+
def setup():
28+
driver = webdriver.Chrome()
29+
driver.get("https://www.selenium.dev/selenium/web/web-form.html")
30+
return driver
31+
32+
def teardown(driver):
33+
driver.quit()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from selenium import webdriver
2+
from selenium.webdriver.common.by import By
3+
from selenium.webdriver.chrome.service import Service
4+
5+
def setup_without_selenium_manager():
6+
chrome_service = Service(executable_path='path/to/chrome.exe')
7+
driver = webdriver.Chrome(chrome_service)
8+
return driver
9+
10+
def setup_with_selenium_manager():
11+
driver = webdriver.Chrome()
12+
return driver

‎examples/ruby/Gemfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ gem 'rspec', '~> 3.0'
88
gem 'rubocop', '~> 1.35'
99
gem 'rubocop-rspec', '~> 3.0'
1010
gem 'selenium-devtools', '= 0.127.0'
11-
gem 'selenium-webdriver', '= 4.23.0'
11+
gem 'selenium-webdriver', '= 4.23.0'

‎examples/ruby/Gemfile.lock‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ GEM
6262
PLATFORMS
6363
arm64-darwin-21
6464
arm64-darwin-22
65+
arm64-darwin-23
6566
x86_64-darwin-19
6667
x86_64-darwin-20
6768
x86_64-darwin-22

‎examples/ruby/spec/interactions/alerts_spec.rb‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,47 @@
44

55
RSpec.describe 'Alerts' do
66
let(:driver) { start_session }
7+
8+
before do
9+
driver.navigate.to 'https://selenium.dev'
10+
end
11+
12+
it 'interacts with an alert' do
13+
driver.execute_script 'alert("Hello, World!")'
14+
15+
# Store the alert reference in a variable
16+
alert = driver.switch_to.alert
17+
18+
# Get the text of the alert
19+
alert.text
20+
21+
# Press on Cancel button
22+
alert.dismiss
23+
end
24+
25+
it 'interacts with a confirm' do
26+
driver.execute_script 'confirm("Are you sure?")'
27+
28+
# Store the alert reference in a variable
29+
alert = driver.switch_to.alert
30+
31+
# Get the text of the alert
32+
alert.text
33+
34+
# Press on Cancel button
35+
alert.dismiss
36+
end
37+
38+
it 'interacts with a prompt' do
39+
driver.execute_script 'prompt("What is your name?")'
40+
41+
# Store the alert reference in a variable
42+
alert = driver.switch_to.alert
43+
44+
# Type a message
45+
alert.send_keys('selenium')
46+
47+
# Press on Ok button
48+
alert.accept
49+
end
750
end

0 commit comments

Comments
(0)

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