moving to scripts

This commit is contained in:
eneller
2021-11-16 23:55:48 +01:00
parent f591ca2077
commit 14bfb7f96f
2575 changed files with 465862 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

View File

@@ -0,0 +1,374 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from enum import Enum
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.options import ArgOptions
class ElementScrollBehavior(Enum):
TOP = 0
BOTTOM = 1
class Options(ArgOptions):
KEY = 'se:ieOptions'
SWITCHES = 'ie.browserCommandLineSwitches'
BROWSER_ATTACH_TIMEOUT = 'browserAttachTimeout'
ELEMENT_SCROLL_BEHAVIOR = 'elementScrollBehavior'
ENSURE_CLEAN_SESSION = 'ie.ensureCleanSession'
FILE_UPLOAD_DIALOG_TIMEOUT = 'ie.fileUploadDialogTimeout'
FORCE_CREATE_PROCESS_API = 'ie.forceCreateProcessApi'
FORCE_SHELL_WINDOWS_API = 'ie.forceShellWindowsApi'
FULL_PAGE_SCREENSHOT = 'ie.enableFullPageScreenshot'
IGNORE_PROTECTED_MODE_SETTINGS = 'ignoreProtectedModeSettings'
IGNORE_ZOOM_LEVEL = 'ignoreZoomSetting'
INITIAL_BROWSER_URL = 'initialBrowserUrl'
NATIVE_EVENTS = 'nativeEvents'
PERSISTENT_HOVER = 'enablePersistentHover'
REQUIRE_WINDOW_FOCUS = 'requireWindowFocus'
USE_PER_PROCESS_PROXY = 'ie.usePerProcessProxy'
USE_LEGACY_FILE_UPLOAD_DIALOG_HANDLING = 'ie.useLegacyFileUploadDialogHandling'
ATTACH_TO_EDGE_CHROME = 'ie.edgechromium'
EDGE_EXECUTABLE_PATH = 'ie.edgepath'
def __init__(self):
super(Options, self).__init__()
self._options = {}
self._additional = {}
@property
def options(self) -> dict:
""":Returns: A dictionary of browser options """
return self._options
@property
def browser_attach_timeout(self) -> int:
"""
:Returns: The options Browser Attach Timeout in milliseconds
"""
return self._options.get(self.BROWSER_ATTACH_TIMEOUT)
@browser_attach_timeout.setter
def browser_attach_timeout(self, value: int):
"""
Sets the options Browser Attach Timeout
:Args:
- value: Timeout in milliseconds
"""
if not isinstance(value, int):
raise ValueError('Browser Attach Timeout must be an integer.')
self._options[self.BROWSER_ATTACH_TIMEOUT] = value
@property
def element_scroll_behavior(self) -> ElementScrollBehavior:
""":Returns: The options Element Scroll Behavior value """
return self._options.get(self.ELEMENT_SCROLL_BEHAVIOR)
@element_scroll_behavior.setter
def element_scroll_behavior(self, value: ElementScrollBehavior):
"""
Sets the options Element Scroll Behavior
:Args:
- value: 0 - Top, 1 - Bottom
"""
if value not in [ElementScrollBehavior.TOP, ElementScrollBehavior.BOTTOM]:
raise ValueError('Element Scroll Behavior out of range.')
self._options[self.ELEMENT_SCROLL_BEHAVIOR] = value
@property
def ensure_clean_session(self) -> bool:
""":Returns: The options Ensure Clean Session value """
return self._options.get(self.ENSURE_CLEAN_SESSION)
@ensure_clean_session.setter
def ensure_clean_session(self, value: bool):
"""
Sets the options Ensure Clean Session value
:Args:
- value: boolean value
"""
self._options[self.ENSURE_CLEAN_SESSION] = value
@property
def file_upload_dialog_timeout(self) -> int:
""":Returns: The options File Upload Dialog Timeout in milliseconds """
return self._options.get(self.FILE_UPLOAD_DIALOG_TIMEOUT)
@file_upload_dialog_timeout.setter
def file_upload_dialog_timeout(self, value: int):
"""
Sets the options File Upload Dialog Timeout value
:Args:
- value: Timeout in milliseconds
"""
if not isinstance(value, int):
raise ValueError('File Upload Dialog Timeout must be an integer.')
self._options[self.FILE_UPLOAD_DIALOG_TIMEOUT] = value
@property
def force_create_process_api(self) -> bool:
""":Returns: The options Force Create Process Api value """
return self._options.get(self.FORCE_CREATE_PROCESS_API)
@force_create_process_api.setter
def force_create_process_api(self, value: bool):
"""
Sets the options Force Create Process Api value
:Args:
- value: boolean value
"""
self._options[self.FORCE_CREATE_PROCESS_API] = value
@property
def force_shell_windows_api(self) -> bool:
""":Returns: The options Force Shell Windows Api value """
return self._options.get(self.FORCE_SHELL_WINDOWS_API)
@force_shell_windows_api.setter
def force_shell_windows_api(self, value: bool):
"""
Sets the options Force Shell Windows Api value
:Args:
- value: boolean value
"""
self._options[self.FORCE_SHELL_WINDOWS_API] = value
@property
def full_page_screenshot(self) -> bool:
""":Returns: The options Full Page Screenshot value """
return self._options.get(self.FULL_PAGE_SCREENSHOT)
@full_page_screenshot.setter
def full_page_screenshot(self, value: bool):
"""
Sets the options Full Page Screenshot value
:Args:
- value: boolean value
"""
self._options[self.FULL_PAGE_SCREENSHOT] = value
@property
def ignore_protected_mode_settings(self) -> bool:
""":Returns: The options Ignore Protected Mode Settings value """
return self._options.get(self.IGNORE_PROTECTED_MODE_SETTINGS)
@ignore_protected_mode_settings.setter
def ignore_protected_mode_settings(self, value: bool):
"""
Sets the options Ignore Protected Mode Settings value
:Args:
- value: boolean value
"""
self._options[self.IGNORE_PROTECTED_MODE_SETTINGS] = value
@property
def ignore_zoom_level(self) -> bool:
""":Returns: The options Ignore Zoom Level value """
return self._options.get(self.IGNORE_ZOOM_LEVEL)
@ignore_zoom_level.setter
def ignore_zoom_level(self, value: bool):
"""
Sets the options Ignore Zoom Level value
:Args:
- value: boolean value
"""
self._options[self.IGNORE_ZOOM_LEVEL] = value
@property
def initial_browser_url(self) -> str:
""":Returns: The options Initial Browser Url value """
return self._options.get(self.INITIAL_BROWSER_URL)
@initial_browser_url.setter
def initial_browser_url(self, value: str):
"""
Sets the options Initial Browser Url value
:Args:
- value: URL string
"""
self._options[self.INITIAL_BROWSER_URL] = value
@property
def native_events(self) -> bool:
""":Returns: The options Native Events value """
return self._options.get(self.NATIVE_EVENTS)
@native_events.setter
def native_events(self, value: bool):
"""
Sets the options Native Events value
:Args:
- value: boolean value
"""
self._options[self.NATIVE_EVENTS] = value
@property
def persistent_hover(self) -> bool:
""":Returns: The options Persistent Hover value """
return self._options.get(self.PERSISTENT_HOVER)
@persistent_hover.setter
def persistent_hover(self, value: bool):
"""
Sets the options Persistent Hover value
:Args:
- value: boolean value
"""
self._options[self.PERSISTENT_HOVER] = value
@property
def require_window_focus(self: bool):
""":Returns: The options Require Window Focus value """
return self._options.get(self.REQUIRE_WINDOW_FOCUS)
@require_window_focus.setter
def require_window_focus(self, value: bool):
"""
Sets the options Require Window Focus value
:Args:
- value: boolean value
"""
self._options[self.REQUIRE_WINDOW_FOCUS] = value
@property
def use_per_process_proxy(self) -> bool:
""":Returns: The options User Per Process Proxy value """
return self._options.get(self.USE_PER_PROCESS_PROXY)
@use_per_process_proxy.setter
def use_per_process_proxy(self, value: bool):
"""
Sets the options User Per Process Proxy value
:Args:
- value: boolean value
"""
self._options[self.USE_PER_PROCESS_PROXY] = value
@property
def use_legacy_file_upload_dialog_handling(self) -> bool:
""":Returns: The options Use Legacy File Upload Dialog Handling value """
return self._options.get(self.USE_LEGACY_FILE_UPLOAD_DIALOG_HANDLING)
@use_legacy_file_upload_dialog_handling.setter
def use_legacy_file_upload_dialog_handling(self, value: bool):
"""
Sets the options Use Legacy File Upload Dialog Handling value
:Args:
- value: boolean value
"""
self._options[self.USE_LEGACY_FILE_UPLOAD_DIALOG_HANDLING] = value
@property
def attach_to_edge_chrome(self) -> bool:
""":Returns: The options Attach to Edge Chrome value """
return self._options.get(self.ATTACH_TO_EDGE_CHROME)
@attach_to_edge_chrome.setter
def attach_to_edge_chrome(self, value: bool):
"""
Sets the options Attach to Edge Chrome value
:Args:
- value: boolean value
"""
self._options[self.ATTACH_TO_EDGE_CHROME] = value
@property
def edge_executable_path(self) -> str:
""":Returns: The options Edge Executable Path value """
return self._options.get(self.EDGE_EXECUTABLE_PATH)
@edge_executable_path.setter
def edge_executable_path(self, value: str):
"""
Sets the options Initial Browser Url value
:Args:
- value: Path string
"""
self._options[self.EDGE_EXECUTABLE_PATH] = value
@property
def additional_options(self) -> dict:
""":Returns: The additional options """
return self._additional
def add_additional_option(self, name: str, value):
"""
Adds an additional option not yet added as a safe option for IE
:Args:
- name: name of the option to add
- value: value of the option to add
"""
self._additional[name] = value
def to_capabilities(self) -> dict:
"""Marshals the IE options to the correct object."""
caps = self._caps
opts = self._options.copy()
if len(self._arguments) > 0:
opts[self.SWITCHES] = ' '.join(self._arguments)
if len(self._additional) > 0:
opts.update(self._additional)
if len(opts) > 0:
caps[Options.KEY] = opts
return caps
@property
def default_capabilities(self) -> dict:
return DesiredCapabilities.INTERNETEXPLORER.copy()

View File

@@ -0,0 +1,54 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import List
from selenium.webdriver.common import service
class Service(service.Service):
"""
Object that manages the starting and stopping of the IEDriver
"""
def __init__(self, executable_path: str,
port: int = 0, host: str = None,
log_level: str = None, log_file: str = None):
"""
Creates a new instance of the Service
:Args:
- executable_path : Path to the IEDriver
- port : Port the service is running on
- host : IP address the service port is bound
- log_level : Level of logging of service, may be "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE".
Default is "FATAL".
- log_file : Target of logging of service, may be "stdout", "stderr" or file path.
Default is "stdout"."""
self.service_args = []
if host:
self.service_args.append("--host=%s" % host)
if log_level:
self.service_args.append("--log-level=%s" % log_level)
if log_file:
self.service_args.append("--log-file=%s" % log_file)
service.Service.__init__(self, executable_path, port=port,
start_error_message="Please download from https://www.selenium.dev/downloads/ and read up at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver")
def command_line_args(self) -> List[str]:
return ["--port=%d" % self.port] + self.service_args

View File

@@ -0,0 +1,123 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import NoReturn
import warnings
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from .service import Service
from .options import Options
from selenium.webdriver.common import utils
DEFAULT_TIMEOUT = 30
DEFAULT_PORT = 0
DEFAULT_HOST = None
DEFAULT_LOG_LEVEL = None
DEFAULT_SERVICE_LOG_PATH = None
DEFAULT_KEEP_ALIVE = None
class WebDriver(RemoteWebDriver):
""" Controls the IEServerDriver and allows you to drive Internet Explorer """
def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
port=DEFAULT_PORT, timeout=DEFAULT_TIMEOUT, host=DEFAULT_HOST,
log_level=DEFAULT_LOG_LEVEL, service_log_path=DEFAULT_SERVICE_LOG_PATH,
options: Options = None, service: Service = None,
desired_capabilities=None, keep_alive=DEFAULT_KEEP_ALIVE):
"""
Creates a new instance of the Ie driver.
Starts the service and then creates new instance of Ie driver.
:Args:
- executable_path - Deprecated: path to the executable. If the default is used it assumes the executable is in the $PATH
- capabilities - Deprecated: capabilities Dictionary object
- port - Deprecated: port you would like the service to run, if left as 0, a free port will be found.
- timeout - Deprecated: no longer used, kept for backward compatibility
- host - Deprecated: IP address for the service
- log_level - Deprecated: log level you would like the service to run.
- service_log_path - Deprecated: target of logging of service, may be "stdout", "stderr" or file path.
- options - IE Options instance, providing additional IE options
- desired_capabilities - Deprecated: alias of capabilities; this will make the signature consistent with RemoteWebDriver.
- keep_alive - Deprecated: Whether to configure RemoteConnection to use HTTP keep-alive.
"""
if executable_path != 'IEDriverServer.exe':
warnings.warn('executable_path has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if capabilities:
warnings.warn('capabilities has been deprecated, please pass in an Options object.'
'This field will be ignored.',
DeprecationWarning, stacklevel=2)
if port != DEFAULT_PORT:
warnings.warn('port has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if timeout != DEFAULT_TIMEOUT:
warnings.warn('timeout has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if host != DEFAULT_HOST:
warnings.warn('host has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if log_level != DEFAULT_LOG_LEVEL:
warnings.warn('log_level has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if service_log_path != DEFAULT_SERVICE_LOG_PATH:
warnings.warn('service_log_path has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if desired_capabilities:
warnings.warn('desired_capabilities has been deprecated, please pass in an Options object.'
'This field will be ignored',
DeprecationWarning, stacklevel=2)
if keep_alive != DEFAULT_KEEP_ALIVE:
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
else:
keep_alive = True
self.host = host
self.port = port
if self.port == 0:
self.port = utils.free_port()
if not options:
options = self.create_options()
if service:
self.iedriver = service
else:
self.iedriver = Service(
executable_path,
port=self.port,
host=self.host,
log_level=log_level,
log_file=service_log_path)
self.iedriver.start()
RemoteWebDriver.__init__(
self,
command_executor=self.iedriver.service_url,
options=options,
keep_alive=keep_alive)
self._is_remote = False
def quit(self) -> NoReturn:
RemoteWebDriver.quit(self)
self.iedriver.stop()
def create_options(self) -> Options:
return Options()