Skip to content

Commit dd79a7d

Browse files
committed
Merge branch 'trunk' into petesong/add-practice-example
2 parents 6120c3a + 208e584 commit dd79a7d

File tree

54 files changed

+517
-131
lines changed

Some content is hidden

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

54 files changed

+517
-131
lines changed

.github/workflows/ruby-examples.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: |
4343
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
4444
- name: Setup Fluxbox and Xvfb
45-
if: inputs.os == 'ubuntu'
45+
if: matrix.os == 'ubuntu'
4646
run: |
4747
sudo apt-get -y install fluxbox libxss1 libappindicator3-1 libindicator7
4848
Xvfb :99 &
@@ -97,7 +97,7 @@ jobs:
9797
cd examples/ruby
9898
bundle exec rspec
9999
new_command_on_retry: |
100-
cd examples/ruby; $env:DEBUG="true"; bundle exec rspec --only-failures
100+
cd examples/ruby; $env:DEBUG="true"; bundle exec rspec --only-failures --backtrace
101101
- name: Run tests on ${{ matrix.os }}
102102
if: matrix.os != 'windows'
103103
uses: nick-invision/[email protected]
@@ -109,4 +109,21 @@ jobs:
109109
bundle exec rspec
110110
new_command_on_retry: |
111111
cd examples/ruby
112-
DEBUG=true bundle exec rspec --only-failures
112+
DEBUG=true bundle exec rspec --only-failures --backtrace
113+
114+
lint:
115+
runs-on: ubuntu-latest
116+
steps:
117+
- name: Checkout GitHub repo
118+
uses: actions/checkout@v4
119+
- name: Set up Ruby
120+
uses: ruby/setup-ruby@v1
121+
with:
122+
ruby-version: 3.1
123+
bundler-cache: true
124+
- name: Install dependencies
125+
working-directory: ./examples/ruby
126+
run: bundle install
127+
- name: Run RuboCop
128+
working-directory: ./examples/ruby
129+
run: bundle exec rubocop
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using OpenQA.Selenium.Chrome;
3+
4+
namespace SeleniumDocs.SeleniumManagerTest
5+
{
6+
[TestClass]
7+
public class UsageTest
8+
{
9+
[TestMethod]
10+
public void TestWithSeleniumManager()
11+
{
12+
// Before
13+
// using var driver = new ChromeDriver("path/to/chromedriver");
14+
15+
// Now
16+
using var driver = new ChromeDriver();
17+
driver.Navigate().GoToUrl("https://www.selenium.dev/documentation/selenium_manager/");
18+
}
19+
}
20+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const Chrome = require('selenium-webdriver/chrome');
2+
const {Browser, Builder} = require("selenium-webdriver");
3+
const options = new Chrome.Options();
4+
5+
describe('Usage Test', function () {
6+
it('Creates driver wit Selenium Manager', async function () {
7+
8+
let driver = new Builder()
9+
.forBrowser(Browser.CHROME)
10+
.build();
11+
12+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
13+
await driver.quit();
14+
});
15+
16+
// it('Creates driver with Selenium Manager', async function () {
17+
// let driverPath = '/path/to/chromedriver';
18+
// let browserPath = '/path/to/chrome';
19+
20+
// options.setChromeBinaryPath(browserPath)
21+
22+
// let service = new Chrome.ServiceBuilder().setPath(driverPath)
23+
24+
// let driver = new Builder()
25+
// .forBrowser(Browser.CHROME)
26+
// .setChromeService(service)
27+
// .build();
28+
29+
// await driver.get('https://www.selenium.dev/selenium/web/blank.html');
30+
// await driver.quit();
31+
// });
32+
});

examples/kotlin/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
<version>1.0.0</version>
1010

1111
<properties>
12-
<kotlin.version>2.1.0</kotlin.version>
12+
<kotlin.version>2.1.20</kotlin.version>
1313

1414
<slf4j.version>2.0.17</slf4j.version>
1515
<logback.version>1.5.18</logback.version>
1616

1717
<junit5.version>5.12.1</junit5.version>
18-
<wdm.version>5.2.3</wdm.version>
1918

2019
<maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
2120

22-
<java.version>1.8</java.version>
21+
<java.version>11</java.version>
2322
<selenium.version>4.31.0</selenium.version>
2423

2524
<maven.compiler.target>${java.version}</maven.compiler.target>

examples/python/README.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,61 @@
1-
# Running all tests from Selenium python example
1+
# Running tests from Selenium Python examples
22

3-
Follow these steps to run all test example from selenium python
4-
5-
1. Clone this repository
3+
#### 1. Clone this repository
64

75
```
86
git clone https://github.com/SeleniumHQ/seleniumhq.github.io.git
97
```
108

11-
2. Navigate to `python` directory
9+
#### 2. Navigate to `python` directory
1210

1311
```
1412
cd seleniumhq.github.io/examples/python
1513
```
1614

17-
3. Install dependencies using pip
15+
#### 3. Create a virtual environment
16+
17+
- On Windows:
18+
19+
```
20+
py -m venv venv
21+
venv\Scripts\activate
22+
```
23+
24+
- On Linux/Mac:
25+
26+
```
27+
python3 -m venv venv
28+
source venv/bin/activate
29+
```
30+
31+
#### 4. Install dependencies:
1832

1933
```
2034
pip install -r requirements.txt
2135
```
22-
> if you are on a different python version, for example python3.x you may have to replace `pip` with `pip3`
2336

24-
4. Run all tests
37+
> for help, see: https://packaging.python.org/en/latest/tutorials/installing-packages
38+
39+
#### 5. Run tests
40+
41+
- Run all tests with the default Python interpreter:
2542

2643
```
2744
pytest
2845
```
2946

30-
> 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
47+
- Run all tests with every installed/supported Python interpreter:
3148

32-
## Execute a specific example
33-
To run a specific Selenium Python example, use the following command:
34-
```bash
49+
```
50+
tox
51+
```
52+
53+
> Please have some patience - If you are doing it for the first time, it will take a little while to download the browser drivers
54+
55+
- Run a specific example:
56+
57+
```
3558
pytest path/to/test_script.py
3659
```
3760

38-
Make sure to replace `path/to/test_script.py` with the path and name of the example you want to run.
61+
> Make sure to replace `path/to/test_script.py` with the path and name of the example you want to run

examples/python/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
selenium==4.31.0
22
pytest==8.3.5
3-
trio==0.29.0
3+
trio==0.30.0
44
pytest-trio==0.8.0
55
pytest-rerunfailures==15.0
66
flake8==7.2.0
77
requests==2.32.3
8+
tox==4.25.0

examples/python/tests/interactions/test_cookies.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from selenium import webdriver
22

33

4-
def add_cookie():
4+
def test_add_cookie():
55
driver = webdriver.Chrome()
66
driver.get("http://www.example.com")
77

88
# Adds the cookie into current browser context
99
driver.add_cookie({"name": "key", "value": "value"})
1010

1111

12-
def get_named_cookie():
12+
def test_get_named_cookie():
1313
driver = webdriver.Chrome()
1414
driver.get("http://www.example.com")
1515

@@ -20,7 +20,7 @@ def get_named_cookie():
2020
print(driver.get_cookie("foo"))
2121

2222

23-
def get_all_cookies():
23+
def test_get_all_cookies():
2424
driver = webdriver.Chrome()
2525

2626
driver.get("http://www.example.com")
@@ -31,7 +31,7 @@ def get_all_cookies():
3131
# Get all available cookies
3232
print(driver.get_cookies())
3333

34-
def delete_cookie():
34+
def test_delete_cookie():
3535
driver = webdriver.Chrome()
3636

3737
driver.get("http://www.example.com")
@@ -43,7 +43,7 @@ def delete_cookie():
4343
driver.delete_cookie("test1")
4444

4545

46-
def delete_all_cookies():
46+
def test_delete_all_cookies():
4747
driver = webdriver.Chrome()
4848

4949
driver.get("http://www.example.com")
@@ -55,7 +55,7 @@ def delete_all_cookies():
5555
driver.delete_all_cookies()
5656

5757

58-
def same_side_cookie_attr():
58+
def test_same_side_cookie_attr():
5959
driver = webdriver.Chrome()
6060

6161
driver.get("http://www.example.com")
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
from selenium import webdriver
1+
from selenium.webdriver.common.by import By
2+
from selenium.webdriver.support import expected_conditions as EC
3+
from selenium.webdriver.support.wait import WebDriverWait
24

5+
# Expected Conditions API Documentation:
6+
# https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html
7+
8+
9+
def test_expected_condition(driver):
10+
driver.get("https://www.selenium.dev/selenium/web/dynamic.html")
11+
revealed = driver.find_element(By.ID, "revealed")
12+
driver.find_element(By.ID, "reveal").click()
13+
14+
wait = WebDriverWait(driver, timeout=2)
15+
wait.until(EC.visibility_of_element_located((By.ID, "revealed")))
16+
17+
revealed.send_keys("Displayed")
18+
assert revealed.get_property("value") == "Displayed"

examples/python/tox.ini

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Tox (https://tox.wiki/) is a tool for running tests in multiple
2+
# virtualenvs. This configuration file will run the test suite on all
3+
# supported python versions. To use it, run "tox" from this directory.
4+
#
5+
# For a specific environment, run: "tox -e <env>" (i.e.: "tox -e py313")
6+
#
7+
# This tox configuration will skip any Python interpreters that can't be found.
8+
# To manage multiple Python interpreters for covering all versions, you can use
9+
# pyenv: https://github.com/pyenv/pyenv
10+
11+
12+
[tox]
13+
env_list =
14+
py39
15+
py310
16+
py311
17+
py312
18+
py313
19+
skip_missing_interpreters = True
20+
21+
[testenv]
22+
description = run tests
23+
passenv = *
24+
deps =
25+
-r requirements.txt
26+
commands =
27+
# "-vv" means extra verbose
28+
# "-r fEsxXp" means show extra test summary info as specified by:
29+
# (f)ailed, (E)rror, (s)kipped, (x)failed, (X)passed, (p)assed
30+
pytest -vv -r fEsxXp {posargs:.}

examples/ruby/.rubocop.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
inherit_from: .rubocop_todo.yml
22

3-
require: rubocop-rspec
3+
plugins:
4+
- rubocop-rspec
45

56
AllCops:
6-
TargetRubyVersion: 3.0
7+
TargetRubyVersion: 3.1
78
NewCops: enable
89
SuggestExtensions:
910
rubocop-rake: false

0 commit comments

Comments
 (0)