Skip to content

Commit 9d36b6a

Browse files
authored
Merge branch 'trunk' into petesong/add-practice-example
2 parents 7986a5c + 208e584 commit 9d36b6a

Some content is hidden

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

41 files changed

+437
-92
lines changed
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/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/spec/bidi/logging_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
RSpec.describe 'Logging' do

examples/ruby/spec/browsers/chrome_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@
131131
'offline' => false,
132132
'latency' => 100,
133133
'download_throughput' => 200,
134-
'upload_throughput' => 200)
134+
'upload_throughput' => 200
135+
)
135136
end
136137

137138
it 'gets the browser logs' do

examples/ruby/spec/browsers/edge_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@
131131
'offline' => false,
132132
'latency' => 100,
133133
'download_throughput' => 200,
134-
'upload_throughput' => 200)
134+
'upload_throughput' => 200
135+
)
135136
end
136137

137138
it 'gets the browser logs' do
@@ -164,6 +165,6 @@ def driver_finder
164165

165166
def permission(name)
166167
@driver.execute_async_script('callback = arguments[arguments.length - 1];' \
167-
'callback(navigator.permissions.query({name: arguments[0]}));', name)['state']
168+
'callback(navigator.permissions.query({name: arguments[0]}));', name)['state']
168169
end
169170
end

0 commit comments

Comments
 (0)