Skip to content

Commit

Permalink
Merge branch 'trunk' into sadik-feature-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
sadik312 authored Nov 25, 2024
2 parents f16bf24 + 5b50534 commit a2865f9
Show file tree
Hide file tree
Showing 42 changed files with 367 additions and 134 deletions.
27 changes: 22 additions & 5 deletions .github/workflows/python-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,25 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu, windows, macos ]
release: [ stable, nightly ]
include:
- os: ubuntu
release: stable
python: '3.8'
- os: ubuntu
release: nightly
python: '3.11'
- os: windows
release: stable
python: '3.9'
- os: windows
release: nightly
python: '3.12'
- os: macos
release: stable
python: '3.10'
- os: macos
release: nightly
python: '3.13'
runs-on: ${{ format('{0}-latest', matrix.os) }}
steps:
- name: Checkout GitHub repo
Expand All @@ -47,7 +64,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: ${{ matrix.python }}
- name: Install dependencies nightly non-Windows
if: matrix.release == 'nightly' && matrix.os != 'windows'
run: |
Expand Down Expand Up @@ -80,8 +97,8 @@ jobs:
- name: Run tests
uses: nick-invision/[email protected]
with:
timeout_minutes: 40
timeout_minutes: 60
max_attempts: 3
command: |
cd examples/python
pytest
pytest --reruns 3
2 changes: 1 addition & 1 deletion examples/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
4 changes: 2 additions & 2 deletions examples/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<properties>
<surefire.parallel>1</surefire.parallel>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<selenium.version>4.26.0</selenium.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import org.openqa.selenium.chromium.ChromiumNetworkConditions;
import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.service.DriverFinder;


public class ChromeTest extends BaseTest {
@AfterEach
public void clearProperties() {
Expand Down Expand Up @@ -180,4 +180,46 @@ private File getChromeLocation() {
DriverFinder finder = new DriverFinder(ChromeDriverService.createDefaultService(), options);
return new File(finder.getBrowserPath());
}

@Test
public void setPermission() {
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.selenium.dev");

driver.setPermission("camera", "denied");

// Verify the permission state is 'denied'
String script = "return navigator.permissions.query({ name: 'camera' })" +
" .then(permissionStatus => permissionStatus.state);";
String permissionState = (String) driver.executeScript(script);

Assertions.assertEquals("denied", permissionState);
driver.quit();
}

@Test
public void setNetworkConditions() {
driver = new ChromeDriver();

ChromiumNetworkConditions networkConditions = new ChromiumNetworkConditions();
networkConditions.setOffline(false);
networkConditions.setLatency(java.time.Duration.ofMillis(20)); // 20 ms of latency
networkConditions.setDownloadThroughput(2000 * 1024 / 8); // 2000 kbps
networkConditions.setUploadThroughput(2000 * 1024 / 8); // 2000 kbps

((ChromeDriver) driver).setNetworkConditions(networkConditions);

driver.get("https://www.selenium.dev");

// Assert the network conditions are set as expected
ChromiumNetworkConditions actualConditions = ((ChromeDriver) driver).getNetworkConditions();
Assertions.assertAll(
() -> Assertions.assertEquals(networkConditions.getOffline(), actualConditions.getOffline()),
() -> Assertions.assertEquals(networkConditions.getLatency(), actualConditions.getLatency()),
() -> Assertions.assertEquals(networkConditions.getDownloadThroughput(), actualConditions.getDownloadThroughput()),
() -> Assertions.assertEquals(networkConditions.getUploadThroughput(), actualConditions.getUploadThroughput())
);
((ChromeDriver) driver).deleteNetworkConditions();
driver.quit();
}
}
45 changes: 44 additions & 1 deletion examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import org.openqa.selenium.chromium.ChromiumNetworkConditions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeDriverService;
import org.openqa.selenium.edge.EdgeOptions;
Expand All @@ -24,7 +26,6 @@
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.service.DriverFinder;


public class EdgeTest extends BaseTest {
@AfterEach
public void clearProperties() {
Expand Down Expand Up @@ -174,4 +175,46 @@ private File getEdgeLocation() {
DriverFinder finder = new DriverFinder(EdgeDriverService.createDefaultService(), options);
return new File(finder.getBrowserPath());
}

@Test
public void setPermissions() {
EdgeDriver driver = new EdgeDriver();
driver.get("https://www.selenium.dev");

driver.setPermission("camera", "denied");

// Verify the permission state is 'denied'
String script = "return navigator.permissions.query({ name: 'camera' })" +
" .then(permissionStatus => permissionStatus.state);";
String permissionState = (String) driver.executeScript(script);

Assertions.assertEquals("denied", permissionState);
driver.quit();
}

@Test
public void setNetworkConditions() {
driver = new EdgeDriver();

ChromiumNetworkConditions networkConditions = new ChromiumNetworkConditions();
networkConditions.setOffline(false);
networkConditions.setLatency(java.time.Duration.ofMillis(20)); // 20 ms of latency
networkConditions.setDownloadThroughput(2000 * 1024 / 8); // 2000 kbps
networkConditions.setUploadThroughput(2000 * 1024 / 8); // 2000 kbps

((EdgeDriver) driver).setNetworkConditions(networkConditions);

driver.get("https://www.selenium.dev");

// Assert the network conditions are set as expected
ChromiumNetworkConditions actualConditions = ((EdgeDriver) driver).getNetworkConditions();
Assertions.assertAll(
() -> Assertions.assertEquals(networkConditions.getOffline(), actualConditions.getOffline()),
() -> Assertions.assertEquals(networkConditions.getLatency(), actualConditions.getLatency()),
() -> Assertions.assertEquals(networkConditions.getDownloadThroughput(), actualConditions.getDownloadThroughput()),
() -> Assertions.assertEquals(networkConditions.getUploadThroughput(), actualConditions.getUploadThroughput())
);
((EdgeDriver) driver).deleteNetworkConditions();
driver.quit();
}
}
52 changes: 43 additions & 9 deletions examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxDriverService;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.GeckoDriverService;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.remote.service.DriverFinder;
import org.junit.jupiter.api.Disabled;





public class FirefoxTest extends BaseTest {
private FirefoxDriver driver;
Expand Down Expand Up @@ -124,8 +124,8 @@ public void setProfileLocation() {
Assertions.assertTrue(location.contains(profileDirectory.getAbsolutePath()));
}


@Test
@Disabled("Skipping tests until Firefox 127 is released")
public void installAddon() {
driver = startFirefoxDriver();
Path xpiPath = Paths.get("src/test/resources/extensions/selenium-example.xpi");
Expand All @@ -138,8 +138,8 @@ public void installAddon() {
"Content injected by webextensions-selenium-example", injected.getText());
}


@Test
@Disabled("Skipping tests until Firefox 127 is released")
public void uninstallAddon() {
driver = startFirefoxDriver();
Path xpiPath = Paths.get("src/test/resources/extensions/selenium-example.xpi");
Expand All @@ -151,8 +151,8 @@ public void uninstallAddon() {
Assertions.assertEquals(driver.findElements(By.id("webextensions-selenium-example")).size(), 0);
}


@Test
@Disabled("Skipping tests until Firefox 127 is released")
public void installUnsignedAddonPath() {
driver = startFirefoxDriver();
Path path = Paths.get("src/test/resources/extensions/selenium-example");
Expand All @@ -171,4 +171,38 @@ private Path getFirefoxLocation() {
DriverFinder finder = new DriverFinder(GeckoDriverService.createDefaultService(), options);
return Path.of(finder.getBrowserPath());
}

@Test
public void fullPageScreenshot() throws Exception {
driver = startFirefoxDriver();

driver.get("https://www.selenium.dev");

File screenshot = driver.getFullPageScreenshotAs(OutputType.FILE);

File targetFile = new File("full_page_screenshot.png");
Files.move(screenshot.toPath(), targetFile.toPath());

// Verify the screenshot file exists
Assertions.assertTrue(targetFile.exists(), "The full page screenshot file should exist");
Files.deleteIfExists(targetFile.toPath());

driver.quit();
}

@Test
public void setContext() {
driver = startFirefoxDriver();

((HasContext) driver).setContext(FirefoxCommandContext.CHROME);
driver.executeScript("console.log('Inside Chrome context');");

// Verify the context is back to "content"
Assertions.assertEquals(
FirefoxCommandContext.CHROME, ((HasContext) driver).getContext(),
"The context should be 'chrome'"
);

driver.quit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public void enableLogs() {

driver = new SafariDriver(service);
}

public void safariTechnologyPreview() {
SafariOptions options = new SafariOptions();
options.setUseTechnologyPreview(true);
driver = new SafariDriver(options);
}
}
2 changes: 2 additions & 0 deletions examples/javascript/test/browser/chromeSpecificCaps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const Chrome = require('selenium-webdriver/chrome');
const { Browser, Builder } = require("selenium-webdriver");
const options = new Chrome.Options();



describe('Should be able to Test Command line arguments', function () {
it('headless', async function () {
let driver = new Builder()
Expand Down
1 change: 1 addition & 0 deletions examples/javascript/test/browser/edgeSpecificCaps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const options = new edge.Options();
const assert = require("assert");



describe('Should be able to Test Command line arguments', function () {
it('headless', async function () {
let driver = new Builder()
Expand Down
2 changes: 2 additions & 0 deletions examples/javascript/test/getting_started/openEdgeTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const edge = require('selenium-webdriver/edge');
describe('Open Edge', function () {
let driver;



before(async function () {
let options = new edge.Options();
driver = new Builder()
Expand Down
1 change: 1 addition & 0 deletions examples/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ selenium==4.26.1
pytest
trio
pytest-trio
pytest-rerunfailures
flake8
requests
38 changes: 37 additions & 1 deletion examples/python/tests/browsers/test_chrome.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re
import subprocess

import pytest
from selenium import webdriver


Expand Down Expand Up @@ -140,3 +140,39 @@ def test_set_network_conditions():
assert driver.get_network_conditions() == network_conditions

driver.quit()


def test_set_permissions():
driver = webdriver.Chrome()
driver.get('https://www.selenium.dev')

driver.set_permissions('camera', 'denied')

assert get_permission_state(driver, 'camera') == 'denied'
driver.quit()


def get_permission_state(driver, name):
"""Helper function to query the permission state."""
script = """
const callback = arguments[arguments.length - 1];
navigator.permissions.query({name: arguments[0]}).then(permissionStatus => {
callback(permissionStatus.state);
});
"""
return driver.execute_async_script(script, name)


def test_cast_features():
driver = webdriver.Chrome()

try:
sinks = driver.get_sinks()
if sinks:
sink_name = sinks[0]['name']
driver.start_tab_mirroring(sink_name)
driver.stop_casting(sink_name)
else:
pytest.skip("No available Cast sinks to test with.")
finally:
driver.quit()
Loading

0 comments on commit a2865f9

Please sign in to comment.