Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ on:
required: false
type: boolean
default: true
cache-key:
description: Bazel disk cache key
required: false
type: string
default: ''
dotnet-version:
description: Custom DotNet version to install
required: false
Expand Down Expand Up @@ -137,13 +132,17 @@ jobs:
# Workaround for long path issues: https://github.com/bazelbuild/bazel/pull/22532
output-base: ${{ inputs.os == 'windows' && 'D://b' || '' }}
cache-version: 2
disk-cache: ${{ inputs.cache-key }}
disk-cache: false
external-cache: |
name: ${{ inputs.cache-key }}
manifest:
crates: rust/Cargo.Bazel.lock
rules_ruby++ruby+ruby: ${{ inputs.os == 'windows' && 'false' || 'rb/.ruby-version' }}
repository-cache: true
rules_ruby++ruby+ruby: 'rb/.ruby-version'
"pin_browsers_extension+mac_edge": false
"pin_browsers_extension+mac_firefox": false
"pin_browsers_extension+linux_edge": false
"pin_browsers_extension+linux_chrome": false
"pin_browsers_extension+linux_firefox": false
repository-cache: false
- name: Setup Bazel without caching
if: inputs.caching == false
uses: bazel-contrib/[email protected]
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Build
cache-key: false
os: windows
run: bazel build //dotnet:all

Expand All @@ -22,7 +21,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Browser Tests
cache-key: false
java-version: 17
os: windows
run: |
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
name: Browser Tests (chrome, ${{ matrix.os }})
os: ${{ matrix.os }}
browser: chrome
cache-key: java-${{ matrix.os }}-tests
# rules_jvm_external is not fully hermetic
# https://github.com/bazelbuild/rules_jvm_external/issues/1046
java-version: 17
Expand All @@ -45,7 +44,6 @@ jobs:
name: Browser Tests (chrome, ${{ matrix.os }})
os: ${{ matrix.os }}
browser: chrome
cache-key: java-${{ matrix.os }}-tests
# rules_jvm_external is not fully hermetic
# https://github.com/bazelbuild/rules_jvm_external/issues/1046
java-version: 17
Expand All @@ -69,7 +67,6 @@ jobs:
name: Remote Tests (chrome, ${{ matrix.os }})
os: ${{ matrix.os }}
browser: chrome
cache-key: java-${{ matrix.os }}-remote-tests
# rules_jvm_external is not fully hermetic
# https://github.com/bazelbuild/rules_jvm_external/issues/1046
java-version: 17
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Build
cache-key: py-build
run: |
bazel build //py:selenium-wheel //py:selenium-sdist

Expand Down Expand Up @@ -70,7 +69,6 @@ jobs:
name: Unit Tests (${{ matrix.python-version }}, ${{ matrix.os }})
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
cache-key: python-unit-test-${{ matrix.python-version }}
run: bazel test --local_test_jobs 1 //py:unit

remote-tests:
Expand All @@ -80,7 +78,6 @@ jobs:
with:
name: Integration Tests Remote
browser: yes
cache-key: py-remote
run: |
bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-remote

Expand All @@ -100,6 +97,5 @@ jobs:
name: Integration Tests (${{ matrix.browser }})
browser: ${{ matrix.browser }}
os: ${{ matrix.os }}
cache-key: py-${{ matrix.browser }}
run: |
bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-${{ matrix.browser }}
5 changes: 0 additions & 5 deletions .github/workflows/ci-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Build
cache-key: rb-build
run: bazel build //rb:selenium-devtools //rb:selenium-webdriver

docs:
Expand All @@ -22,7 +21,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Documentation
cache-key: rb-docs
run: bazel run //rb:docs

steep-check:
Expand Down Expand Up @@ -73,7 +71,6 @@ jobs:
os: ubuntu
with:
name: Unit Tests (${{ matrix.ruby-version }}, ${{ matrix.os }})
cache-key: rb-unit-test-${{ matrix.ruby-version }}-${{ matrix.os }}
os: ${{ matrix.os }}
ruby-version: ${{ matrix.ruby-version }}
run: >
Expand Down Expand Up @@ -103,7 +100,6 @@ jobs:
with:
name: Local Tests (${{ matrix.browser }}, ${{ matrix.os }})
browser: ${{ matrix.browser }}
cache-key: rb-${{ matrix.browser }}-${{ matrix.os }}-test
os: ${{ matrix.os }}
run: >
bazel test
Expand All @@ -128,7 +124,6 @@ jobs:
with:
name: Remote Tests (${{ matrix.browser }}, ${{ matrix.os }})
browser: ${{ matrix.browser }}
cache-key: rb-remote-${{ matrix.browser }}-${{ matrix.os }}-test
os: ${{ matrix.os }}
java-version: 17
run: >
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Build
cache-key: rust-build
run: bazel build //rust:selenium-manager

tests:
Expand All @@ -41,7 +40,6 @@ jobs:
- os: windows
with:
name: Tests (${{ matrix.os }})
cache-key: rust-test
os: ${{ matrix.os }}
run: bazel test --test_env=RUST_BACKTRACE=full --test_env=RUST_TEST_NOCAPTURE=1 --flaky_test_attempts=3 //rust/...

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
manifest:
crates: rust/Cargo.Bazel.lock
rules_ruby~~ruby~ruby: rb/.ruby-version
repository-cache: true
repository-cache: false
- name: Check Bazel targets
id: check-targets
run: ./scripts/github-actions/check-bazel-targets.sh
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
- selenium-webdriver
with:
name: Nightly Ruby Release
cache-key: rb-nightly-${{ matrix.gem }}
run: |
export GEM_HOST_API_KEY="Bearer $GITHUB_TOKEN"
./go rb:release[nightly]
Expand Down Expand Up @@ -72,7 +71,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Nightly Python Release
cache-key: python-nightly
run: ./go py:release[nightly]
secrets: inherit
on-python-failure:
Expand All @@ -99,7 +97,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Nightly Java Release
cache-key: java-nightly
run: ./go java:release[nightly]
secrets: inherit
on-java-failure:
Expand All @@ -126,7 +123,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Nightly DotNet Release
cache-key: dotnet-nightly
dotnet-version: '6.x'
run: ./go dotnet:release[--stamp,nightly]
secrets: inherit
Expand Down Expand Up @@ -156,7 +152,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Nightly Grid Release
cache-key: grid-nightly
run: ./go java:package[--config=release]
nightly-release-files: build/dist/*.*
on-grid-failure:
Expand All @@ -183,7 +178,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Nightly JavaScript Release
cache-key: javascript-nightly
node-version: '22.x'
run: |
sed -i 's|https://registry.npmjs.org/|https://npm.pkg.github.com|g' javascript/selenium-webdriver/package.json
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pin-browsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Pin Browsers
cache-key: pin-browsers
run: bazel run //scripts:pinned_browsers
artifact-name: pinned-browsers

Expand Down
38 changes: 38 additions & 0 deletions py/selenium/webdriver/common/bidi/emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,41 @@ def set_user_agent_override(
params["userContexts"] = user_contexts

self.conn.execute(command_builder("emulation.setUserAgentOverride", params))

def set_network_conditions(
self,
offline: bool = False,
contexts: list[str] | None = None,
user_contexts: list[str] | None = None,
) -> None:
"""Set network conditions for the given contexts or user contexts.

Args:
offline: True to emulate offline network conditions, False to clear the override.
contexts: List of browsing context IDs to apply the conditions to.
user_contexts: List of user context IDs to apply the conditions to.

Raises:
ValueError: If both contexts and user_contexts are provided, or if neither
contexts nor user_contexts are provided.
"""
if contexts is not None and user_contexts is not None:
raise ValueError("Cannot specify both contexts and user_contexts")

if contexts is None and user_contexts is None:
raise ValueError("Must specify either contexts or user_contexts")

params: dict[str, Any] = {}

if offline:
params["networkConditions"] = {"type": "offline"}
else:
# if offline is False or None, then clear the override
params["networkConditions"] = None

if contexts is not None:
params["contexts"] = contexts
elif user_contexts is not None:
params["userContexts"] = user_contexts

self.conn.execute(command_builder("emulation.setNetworkConditions", params))
45 changes: 45 additions & 0 deletions py/test/selenium/webdriver/common/bidi_emulation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def get_browser_user_agent(driver):
return result.result["value"]


def is_online(driver, context_id):
result = driver.script._evaluate("navigator.onLine", {"context": context_id}, await_promise=False)
return result.result["value"]


def test_emulation_initialized(driver):
assert driver.emulation is not None
assert isinstance(driver.emulation, Emulation)
Expand Down Expand Up @@ -574,3 +579,43 @@ def test_set_user_agent_override_with_user_contexts(driver, pages):
driver.browsing_context.close(context_id)
finally:
driver.browser.remove_user_context(user_context)


@pytest.mark.xfail_firefox
def test_set_network_conditions_offline_with_context(driver, pages):
context_id = driver.current_window_handle
driver.browsing_context.navigate(context_id, pages.url("formPage.html"), wait="complete")

assert is_online(driver, context_id) is True

try:
# Set offline
driver.emulation.set_network_conditions(offline=True, contexts=[context_id])
assert is_online(driver, context_id) is False
finally:
# Reset
driver.emulation.set_network_conditions(offline=False, contexts=[context_id])
assert is_online(driver, context_id) is True


@pytest.mark.xfail_firefox
def test_set_network_conditions_offline_with_user_context(driver, pages):
user_context = driver.browser.create_user_context()
try:
context_id = driver.browsing_context.create(
type=WindowTypes.TAB,
user_context=user_context,
)
try:
driver.switch_to.window(context_id)
driver.browsing_context.navigate(context_id, pages.url("formPage.html"), wait="complete")

assert is_online(driver, context_id) is True

driver.emulation.set_network_conditions(offline=True, user_contexts=[user_context])
assert is_online(driver, context_id) is False
finally:
driver.emulation.set_network_conditions(offline=False, user_contexts=[user_context])
driver.browsing_context.close(context_id)
finally:
driver.browser.remove_user_context(user_context)
Loading