-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1902 from emanlove/add-service-class
Add service class
- Loading branch information
Showing
17 changed files
with
662 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
*** Settings *** | ||
Suite Teardown Close All Browsers | ||
Library ../resources/testlibs/get_driver_path.py | ||
Resource resource.robot | ||
# Force Tags Known Issue Firefox Known Issue Safari Known Issue Internet Explorer | ||
Documentation Creating test which would work on all browser is not possible. | ||
... These tests are for Chrome only. | ||
*** Test Cases *** | ||
Chrome Browser With Chrome Service As String | ||
[Documentation] | ||
... LOG 2:2 DEBUG STARTS: Started executable: | ||
... LOG 2:3 DEBUG GLOB: POST*/session* | ||
${driver_path}= Get Driver Path Chrome | ||
Open Browser ${FRONT PAGE} Chrome remote_url=${REMOTE_URL} | ||
... service=executable_path='${driver_path}' | ||
|
||
Chrome Browser With Chrome Service As String With service_args As List | ||
Open Browser ${FRONT PAGE} Chrome remote_url=${REMOTE_URL} | ||
... service=service_args=['--append-log', '--readable-timestamp']; log_output='${OUTPUT_DIR}/chromedriverlog.txt' | ||
File Should Exist ${OUTPUT_DIR}/chromedriverlog.txt | ||
# ... service=service_args=['--append-log', '--readable-timestamp']; log_output='./' | ||
# ... service=service_args=['--append-log', '--readable-timestamp'] | ||
|
||
Firefox Browser With Firefox Service As String | ||
[Documentation] | ||
... LOG 2:2 DEBUG STARTS: Started executable: | ||
... LOG 2:3 DEBUG GLOB: POST*/session* | ||
${driver_path}= Get Driver Path Firefox | ||
Open Browser ${FRONT PAGE} Firefox remote_url=${REMOTE_URL} | ||
... service=executable_path='${driver_path}' | ||
|
||
#Chrome Browser With Selenium Options Invalid Method | ||
# Run Keyword And Expect Error AttributeError: 'Options' object has no attribute 'not_here_method' | ||
# ... Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL} | ||
# ... desired_capabilities=${DESIRED_CAPABILITIES} options=not_here_method("arg1") | ||
# | ||
# | ||
#Chrome Browser With Selenium Options Argument With Semicolon | ||
# [Documentation] | ||
# ... LOG 1:14 DEBUG GLOB: *"goog:chromeOptions"* | ||
# ... LOG 1:14 DEBUG GLOB: *["has;semicolon"* | ||
# Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL} | ||
# ... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument("has;semicolon") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
>>> from selenium.webdriver.common import driver_finder | ||
>>> drfind = driver_finder.DriverFinder() | ||
>>> from selenium.webdriver.chrome.service import Service | ||
>>> from selenium.webdriver.chrome.options import Options | ||
>>> drfind.get_path(Service(),Options()) | ||
def _import_service(self, browser): | ||
browser = browser.replace("headless_", "", 1) | ||
# Throw error is used with remote .. "They cannot be used with a Remote WebDriver session." [ref doc] | ||
service = importlib.import_module(f"selenium.webdriver.{browser}.service") | ||
return service.Service | ||
def _import_options(self, browser): | ||
browser = browser.replace("headless_", "", 1) | ||
options = importlib.import_module(f"selenium.webdriver.{browser}.options") | ||
return options.Options | ||
""" | ||
from selenium import webdriver | ||
from selenium.webdriver.common import driver_finder | ||
import importlib | ||
|
||
|
||
def get_driver_path(browser): | ||
browser = browser.lower().replace("headless_", "", 1) | ||
service = importlib.import_module(f"selenium.webdriver.{browser}.service") | ||
options = importlib.import_module(f"selenium.webdriver.{browser}.options") | ||
# finder = driver_finder.DriverFinder() | ||
|
||
# Selenium v4.19.0 and prior | ||
try: | ||
finder = driver_finder.DriverFinder() | ||
func = getattr(finder, 'get_path') | ||
return finder.get_path(service.Service(), options.Options()) | ||
except (AttributeError, TypeError): | ||
pass | ||
|
||
# Selenium V4.20.0 | ||
try: | ||
finder = driver_finder.DriverFinder(service.Service(), options.Options()) | ||
return finder.get_driver_drivepath() | ||
except: | ||
pass | ||
|
||
raise Exception('Unable to determine driver path') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.