Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated python docs/examples for browsers section #1854

Draft
wants to merge 11 commits into
base: trunk
Choose a base branch
from
48 changes: 48 additions & 0 deletions examples/python/tests/browsers/test_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,51 @@ def test_build_checks(capfd):
assert expected in err

driver.quit()

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

driver.set_network_conditions(offline=False, latency=250, throughput=500*1024)
driver.get('http://selenium.dev')

driver.quit()

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

driver.get('https://www.selenium.dev/webs')
browser_logs = driver.get_log('browser')

assert 'Failed to load' in browser_logs[0]['message']

driver.quit()

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

driver.get('https://www.selenium.dev')

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

geolocation_permissions = driver.execute_script('return await navigator.permissions.query({name: \'geolocation\'})')
assert geolocation_permissions['state'] == 'denied'

driver.quit()

def test_casting():

driver = webdriver.Chrome()

try:
sinks = driver.get_sinks()
if len(sinks) > 0:
device_name = sinks[0]['name']
driver.start_tab_mirroring(device_name)
driver.stop_casting(device_name)
except:
assert False, 'Exception when starting or stopping casting'

driver.get('http://selenium.dev')

driver.quit()

44 changes: 44 additions & 0 deletions examples/python/tests/browsers/test_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,47 @@ def test_build_checks(log_path):

driver.quit()

def test_network_conditions():
driver = webdriver.Edge()

driver.set_network_conditions(offline=False, latency=250, throughput=500*1024)
driver.get('http://selenium.dev')

driver.quit()

def test_logs():
driver = webdriver.Edge()

driver.get('https://www.selenium.dev/webs')
browser_logs = driver.get_log('browser')

assert 'Failed to load' in browser_logs[0]['message']
driver.quit()

def test_permissions():
driver = webdriver.Edge()

driver.get('https://www.selenium.dev')
driver.set_permissions('geolocation', 'denied')

geolocation_permissions = driver.execute_script('return await navigator.permissions.query({name: \'geolocation\'})')
assert geolocation_permissions['state'] == 'denied'

driver.quit()

def test_casting():

driver = webdriver.Edge()

try:
sinks = driver.get_sinks()
if len(sinks) > 0:
device_name = sinks[0]['name']
driver.start_tab_mirroring(device_name)
driver.stop_casting(device_name)
except:
assert False, 'Exception when starting or stopping casting'

driver.get('http://selenium.dev')

driver.quit()
32 changes: 30 additions & 2 deletions examples/python/tests/browsers/test_firefox.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import subprocess
import sys
import pathlib

import pytest
from selenium import webdriver



def test_basic_options():
options = webdriver.FirefoxOptions()
driver = webdriver.Firefox(options=options)
Expand Down Expand Up @@ -129,3 +129,31 @@ def test_install_unsigned_addon_directory_slash(firefox_driver, addon_path_dir_s
injected = driver.find_element(webdriver.common.by.By.ID, "webextensions-selenium-example")

assert injected.text == "Content injected by webextensions-selenium-example"

def test_full_page_screenshots():
driver = webdriver.Firefox()

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

path_for_screenshot = str(pathlib.Path().absolute()) + 'screenshot.png'
driver.save_full_page_screenshot(path_for_screenshot)

driver.quit()

def test_context():
driver = webdriver.Firefox()

driver.context = 'content'
driver.get("https://www.selenium.dev/")

driver.quit()

def test_profiles():
options = webdriver.FirefoxOptions()
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("javascript.enabled", False)
options.profile = firefox_profile

driver = webdriver.Firefox(options)

driver.quit()
68 changes: 68 additions & 0 deletions examples/python/tests/browsers/test_internet_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,71 @@ def test_supporting_files(temp_dir):
driver = webdriver.Ie(service=service)

driver.quit()

@pytest.mark.skipif(sys.platform != "win32", reason="requires Windows")
def test_file_upload_dialog_timeout():
options = webdriver.IeOptions()

options.file_upload_dialog_timeout = 2000

driver = webdriver.Ie(options=options)
driver.get('https://www.selenium.dev/')

driver.quit()

@pytest.mark.skipif(sys.platform != "win32", reason="requires Windows")
def test_ensure_clean_session():
options = webdriver.IeOptions()

options.ensure_clean_session = True

driver = webdriver.Ie(options=options)
driver.get('https://www.selenium.dev/')

driver.quit()

@pytest.mark.skipif(sys.platform != "win32", reason="requires Windows")
def test_ignore_zoom_setting():
options = webdriver.IeOptions()

options.ignore_zoom_level = True

driver = webdriver.Ie(options=options)
driver.get('https://www.selenium.dev/')

driver.quit()

@pytest.mark.skipif(sys.platform != "win32", reason="requires Windows")
def test_ignore_protected_mode_settings():
options = webdriver.IeOptions()

options.ignore_protected_mode_settings = True

driver = webdriver.Ie(options=options)
driver.get('https://www.selenium.dev/')

driver.quit()

@pytest.mark.skipif(sys.platform != "win32", reason="requires Windows")
def test_silent_capability():
options = webdriver.IeOptions()

options.add_argument('-silent')

driver = webdriver.Ie(options=options)
driver.get('https://www.selenium.dev/')

driver.quit()

@pytest.mark.skip(reason="TabProcGrowth is required to be set to 0 value")
def test_command_line_options():
options = webdriver.IeOptions()

options.add_argument('-private')
options.force_create_process_api = True

driver = webdriver.Ie(options=options)
driver.get('https://www.selenium.dev/')

driver.quit()

1 change: 1 addition & 0 deletions examples/python/tests/browsers/test_safari.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_technology_preview():
executable_path='/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver'
)
driver = webdriver.Safari(options=options, service=service)
driver.get('http://selenium.dev')

driver.quit()

Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ You can drive Chrome Cast devices, including sharing tabs
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
pmartinez1 marked this conversation as resolved.
Show resolved Hide resolved
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L160-L164" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand All @@ -399,7 +399,7 @@ You can simulate various network conditions.
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L128" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand All @@ -422,7 +422,7 @@ You can simulate various network conditions.
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L137" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand All @@ -445,7 +445,7 @@ You can simulate various network conditions.
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L148" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Property value: `"true"` or `"false"`
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L160-L164" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Pode comandar dispositivos Chrome Cast, incluindo partilhar abas
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L160-L164" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Chromedriver 和 Chrome 浏览器版本应该匹配, 如果它们不匹配, 驱
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L160-L164" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ You can drive Chrome Cast devices with Edge, including sharing tabs
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_edge.py#L158-L162" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand All @@ -399,7 +399,7 @@ You can simulate various network conditions.
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_edge.py#L128" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand All @@ -422,7 +422,7 @@ You can simulate various network conditions.
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_edge.py#L137" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand All @@ -445,7 +445,7 @@ You can simulate various network conditions.
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_edge.py#L146" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ You can drive Chrome Cast devices with Edge, including sharing tabs
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_edge.py#L158-L162" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ You can drive Chrome Cast devices with Edge, including sharing tabs
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_edge.py#L158-L162" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ You can drive Chrome Cast devices with Edge, including sharing tabs
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_edge.py#L158-L162" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,8 @@ FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
driver = new FirefoxDriver(options);
{{< /tab >}}
{{< tab header="Python" >}}
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
options=Options()
firefox_profile = FirefoxProfile()
firefox_profile.set_preference("javascript.enabled", False)
options.profile = firefox_profile
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L152-L155" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var options = new FirefoxOptions();
Expand Down Expand Up @@ -417,7 +412,7 @@ please refer to the
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_firefox.py#L138-L139" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand All @@ -444,7 +439,7 @@ please refer to the
{{< badge-code >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/browsers/test_firefox.py#L146" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< badge-code >}}
Expand Down
Loading
Loading