-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf17364
commit 4476849
Showing
14 changed files
with
459 additions
and
251 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,9 @@ | ||
*out | ||
*logs | ||
*actions | ||
*notifications | ||
*tools | ||
plugins | ||
user_trunk.yaml | ||
user.yaml | ||
tmp |
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,2 @@ | ||
# Prettier friendly markdownlint config (all formatting rules disabled) | ||
extends: markdownlint/style/prettier |
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,7 @@ | ||
enable=all | ||
source-path=SCRIPTDIR | ||
disable=SC2154 | ||
|
||
# If you're having issues with shellcheck following source, disable the errors via: | ||
# disable=SC1090 | ||
# disable=SC1091 |
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,7 @@ | ||
rules: | ||
quoted-strings: | ||
required: only-when-needed | ||
extra-allowed: ["{|}"] | ||
key-duplicates: {} | ||
octal-values: | ||
forbid-implicit-octal: true |
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 @@ | ||
# This file controls the behavior of Trunk: https://docs.trunk.io/cli | ||
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml | ||
version: 0.1 | ||
cli: | ||
version: 1.22.5 | ||
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) | ||
plugins: | ||
sources: | ||
- id: trunk | ||
ref: v1.6.5 | ||
uri: https://github.com/trunk-io/plugins | ||
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) | ||
runtimes: | ||
enabled: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) | ||
lint: | ||
enabled: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- git-diff-check | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
actions: | ||
disabled: | ||
- trunk-announce | ||
- trunk-check-pre-push | ||
- trunk-fmt-pre-commit | ||
enabled: | ||
- trunk-upgrade-available |
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,4 @@ | ||
{ | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.black] | ||
line-length = 120 | ||
target-version = ['py311'] | ||
target-version = ['py312'] | ||
include = '\.pyi?$' | ||
exclude = ''' | ||
/( | ||
|
@@ -13,48 +13,48 @@ exclude = ''' | |
|Jenkinfile | ||
| _build | ||
| dist | ||
| .venv | ||
)/ | ||
''' | ||
|
||
# ==== isort ==== | ||
[tool.isort] | ||
profile = "black" | ||
line_length = 120 | ||
known_first_party = [ | ||
"config", | ||
"apps", | ||
] | ||
known_first_party = ["config", "apps"] | ||
skip = [] | ||
skip_glob = [] | ||
|
||
[tool.poetry] | ||
name = "seleniumtabs" | ||
version = "0.5.7" | ||
packages = [ | ||
{ include = "seleniumtabs" }, | ||
] | ||
version = "1.0.0" | ||
packages = [{ include = "seleniumtabs" }] | ||
description = "Selenium with tab management in Python" | ||
authors = ["Vishal Kumar Mishra <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
homepage = "https://github.com/TheConfused/selenium-tabs" | ||
repository = "https://github.com/TheConfused/selenium-tabs" | ||
keywords = ["selenium tabs", "selenium python", "selenium python automation", "python automation", ] | ||
include = [ | ||
"LICENSE", | ||
keywords = [ | ||
"selenium tabs", | ||
"selenium python", | ||
"selenium python automation", | ||
"python automation", | ||
] | ||
include = ["LICENSE"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
python = "^3.13" | ||
selenium = "^4.12.0" | ||
django-environ = "^0.11.1" | ||
python-dotenv = "^1.0.0" | ||
PyYAML = "^6.0.1" | ||
pyquery = "^2.0.0" | ||
browserjquery = "^0.1.0" | ||
fake-useragent = "^1.2.1" | ||
tldextract = "^3.6.0" | ||
tldextract = "^5.1.2" | ||
webdriver-manager = "^4.0.2" | ||
schedule = "^1.2.2" | ||
|
||
|
||
[tool.poetry.dev-dependencies] | ||
|
@@ -75,10 +75,7 @@ build-backend = "poetry.core.masonry.api" | |
[tool.pytest.ini_options] | ||
minversion = "6.0" | ||
addopts = "--ds=settings" | ||
python_files = [ | ||
"tests.py", | ||
"test_*.py", | ||
] | ||
python_files = ["tests.py", "test_*.py"] | ||
|
||
# ==== mypy ==== | ||
[tool.mypy] | ||
|
@@ -96,32 +93,77 @@ select = ["E", "F"] | |
ignore = [] | ||
|
||
# Allow autofix for all enabled rules (when `--fix`) is provided. | ||
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"] | ||
fixable = [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
"F", | ||
"G", | ||
"I", | ||
"N", | ||
"Q", | ||
"S", | ||
"T", | ||
"W", | ||
"ANN", | ||
"ARG", | ||
"BLE", | ||
"COM", | ||
"DJ", | ||
"DTZ", | ||
"EM", | ||
"ERA", | ||
"EXE", | ||
"FBT", | ||
"ICN", | ||
"INP", | ||
"ISC", | ||
"NPY", | ||
"PD", | ||
"PGH", | ||
"PIE", | ||
"PL", | ||
"PT", | ||
"PTH", | ||
"PYI", | ||
"RET", | ||
"RSE", | ||
"RUF", | ||
"SIM", | ||
"SLF", | ||
"TCH", | ||
"TID", | ||
"TRY", | ||
"UP", | ||
"YTT", | ||
] | ||
unfixable = [] | ||
|
||
# Exclude a variety of commonly ignored directories. | ||
exclude = [ | ||
".bzr", | ||
".direnv", | ||
".eggs", | ||
".git", | ||
".git-rewrite", | ||
".hg", | ||
".mypy_cache", | ||
".nox", | ||
".pants.d", | ||
".pytype", | ||
".ruff_cache", | ||
".svn", | ||
".tox", | ||
".venv", | ||
"__pypackages__", | ||
"_build", | ||
"buck-out", | ||
"build", | ||
"dist", | ||
"node_modules", | ||
"venv", | ||
".bzr", | ||
".direnv", | ||
".eggs", | ||
".git", | ||
".git-rewrite", | ||
".hg", | ||
".mypy_cache", | ||
".nox", | ||
".pants.d", | ||
".pytype", | ||
".ruff_cache", | ||
".svn", | ||
".tox", | ||
".venv", | ||
"__pypackages__", | ||
"_build", | ||
"buck-out", | ||
"build", | ||
"dist", | ||
"node_modules", | ||
"venv", | ||
] | ||
|
||
line-length = 120 | ||
|
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 |
---|---|---|
@@ -1,14 +1,19 @@ | ||
class BrowserSessions: | ||
def __init__(self): | ||
self.sessions = [] | ||
self.browser_sessions = [] | ||
|
||
def get_browser_for_tab(self, tab): | ||
if browser := [browser for browser in self.browser_sessions if tab in browser]: | ||
return browser[0] | ||
|
||
return None | ||
|
||
def close_tab(self, tab): | ||
if browser := [browser for browser in self.sessions if tab in browser]: | ||
br = browser[0] | ||
br.close_tab(tab) | ||
if browser := self.get_browser_for_tab(tab): | ||
browser.close_tab(tab) | ||
|
||
def add_browser(self, br): | ||
self.sessions.append(br) | ||
self.browser_sessions.append(br) | ||
|
||
|
||
browser_sessions = BrowserSessions() |
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,49 @@ | ||
import time | ||
|
||
import schedule | ||
|
||
from seleniumtabs import settings | ||
|
||
logger = settings.getLogger(__name__) | ||
|
||
|
||
class BrowserTaskScheduler: | ||
""" | ||
A class to manage and schedule tasks across multiple tabs in a Selenium browser. | ||
""" | ||
|
||
def schedule_task(self, tab, task_func, period, *args, **kwargs): | ||
""" | ||
Schedule a task to be executed on a specific tab. | ||
:param tab: The tab object to execute the task on. | ||
:param task_func: The function to execute as a task. | ||
:param args: Arguments for the task function. | ||
:param kwargs: Keyword arguments for the task function. | ||
""" | ||
|
||
def task_decorator(task): | ||
def wrapper(tab, *args, **kwargs): | ||
tab.switch() | ||
time.sleep(0.25) | ||
task(tab, *args, **kwargs) | ||
|
||
return wrapper | ||
|
||
schedule.every(period).seconds.do(task_decorator(task_func), tab, *args, **kwargs) | ||
|
||
def execute_tasks(self, max_time=None): | ||
""" | ||
Execute all scheduled tasks across their respective tabs. | ||
""" | ||
start_time = time.time() | ||
|
||
while True: | ||
schedule.run_pending() | ||
time.sleep(1) | ||
|
||
if max_time and time.time() - start_time > max_time: | ||
break | ||
|
||
|
||
task_scheduler = BrowserTaskScheduler() |
Oops, something went wrong.