Skip to content

Commit

Permalink
python-selenium-is-seledroid: fix bug of python selenium.webdriver.su…
Browse files Browse the repository at this point in the history
…pport.expected_conditions (#481)
  • Loading branch information
nacho00112 authored Jul 3, 2023
1 parent c6d2d97 commit 8877bb3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
5 changes: 2 additions & 3 deletions tur/python-selenium-is-seledroid/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ TERMUX_PKG_SKIP_SRC_EXTRACT=true
# seledroid is unlicensed, the original selenium is Apache-2.0
TERMUX_PKG_LICENSE="Unlicense"
TERMUX_PKG_MAINTAINER="@nacho00112"
TERMUX_PKG_VERSION=4.8.2
TERMUX_PKG_REVISION=1
TERMUX_PKG_DEPENDS="python, python-seledroid"
TERMUX_PKG_VERSION=4.10.0
TERMUX_PKG_DEPENDS="python-seledroid"
TERMUX_PKG_SETUP_PYTHON=true
TERMUX_PKG_BUILD_IN_SRC=true

Expand Down
65 changes: 29 additions & 36 deletions tur/python-selenium-is-seledroid/selenium.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,54 @@
# selenium dummy based on seledroid, generated by the termux package python-selenium-is-seledroid
import sys, types

class DummyOptions:
def add_argument(self, arg):
pass

webdriver_original = None

def get_webdriver_original():
global webdriver_original
if webdriver_original is None:
import seledroid.webdriver as webdriver_original

class AdaptedSeledroidChrome(webdriver_original.Chrome):
def __init__(self, *args, options=None, **kwargs):
return super().__init__(*args, **kwargs)

webdriver_original.Chrome = AdaptedSeledroidChrome
return webdriver_original
import sys, types, os
if not os.path.exists("/data/app/com.luanon.chromium-1"):
raise ImportError("Seledroid APP not installed, run `install-seledroid-app` for that")

class SeleniumDummyWebdriverModule(types.ModuleType):
def __prepare(self):
if "__original" in self.__dict__:
return
import seledroid.webdriver as original
class Chrome(original.Chrome):
def __init__(self, *args, options=None, gui=False, **kwargs):
return super().__init__(*args, gui=gui, **kwargs)
class DummyOptions:
def add_argument(self, arg):
pass
original.Chrome = Chrome
original.DummyOptions = DummyOptions
self.__original = original
self.__dict__["__original"] = original
def __dir__(self):
webdriver = get_webdriver_original()
dir_value = dir(webdriver)
return dir_value

def __getattribute__(self, name):
webdriver = get_webdriver_original()
self.__prepare()
return dir(self.__original)
def __getattr__(self, name):
self.__prepare()
try:
value = getattr(webdriver, name)
value = getattr(self.__original, name)
except AttributeError:
if name.endswith("Options"):
value = DummyOptions
elif name[:1].isupper():
value = webdriver.Chrome
value = self.__original.Chrome
else:
raise
return value

# convert this into a selenium dummy package
import seledroid
__package__ = "selenium"
__path__ = seledroid.__path__

# ====== selenium.webdriver ======
sys.modules["selenium.webdriver"] = webdriver = SeleniumDummyWebdriverModule("selenium.webdriver")
webdriver = SeleniumDummyWebdriverModule("selenium.webdriver")
sys.modules["selenium.webdriver"] = webdriver

# ========== Key.RETURN ==========
# ========== Keys.RETURN ==========
from selenium.webdriver.common.keys import Keys
Keys.RETURN = Keys.ENTER

# ======= selenium.common ========
import seledroid.webdriver.common as common
import selenium.webdriver.common as common
sys.modules["selenium.common"] = common

# == selenium.common.exceptions ==
import seledroid.webdriver.common.exception as exceptions
import selenium.webdriver.common.exception as exceptions
sys.modules["selenium.common.exceptions"] = exceptions
common.exceptions = exceptions


0 comments on commit 8877bb3

Please sign in to comment.