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

New Feature: Upgrade Peekbot #966

Merged
merged 10 commits into from
Dec 21, 2021
Prev Previous commit
Next Next commit
Add ability to customize port number
  • Loading branch information
Thomas-Boi committed Dec 14, 2021
commit d1aea435bb28dcbc597713f555c26d43a9e8a241
19 changes: 16 additions & 3 deletions .github/scripts/build_assets/selenium_runner/SeleniumRunner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from selenium.webdriver.common import service

from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
Expand Down Expand Up @@ -131,6 +133,7 @@ def set_browser_options(self, download_path: str, geckodriver_path: str,
:raises AssertionError: if the page title does not contain
"IcoMoon App".
"""
# customize the download options
options = Options()
allowed_mime_types = "application/zip, application/gzip, application/octet-stream"
# disable prompt to download from Firefox
Expand All @@ -152,23 +155,33 @@ def set_browser_options(self, download_path: str, geckodriver_path: str,
)
print("Accessed icomoon.io")

def create_driver_instance(self, options, geckodriver_path):
def create_driver_instance(self, options: Options, geckodriver_path: str):
"""
Create a WebDriver instance. Isolate retrying code here to address
"no connection can be made" error.
:param options: the FirefoxOptions for the browser.
:param geckodriver_path: the path to the firefox executable.
the icomoon.zip to.
"""

retries = SeleniumRunner.MAX_RETRY
finished = False
driver = None
err_msg = [] # keep for logging purposes
while not finished and retries > 0:
try:
# order matters, don't change the 2 lines below
# order matters, don't change the lines below
finished = True # signal we are done in case we are actually done
driver = WebDriver(options=options, executable_path=geckodriver_path)

# customize the local server
service = None
# first retry: use 8080
# else: random
if retries == SeleniumRunner.MAX_RETRY:
service = Service(executable_path=geckodriver_path, port=8080)
else:
service = Service(executable_path=geckodriver_path)
driver = WebDriver(options=options, service=service)
except SeleniumTimeoutException as e:
# retry. This is intended to catch "no connection could be made" error
retries -= 1
Expand Down