If you're trying to run multi-threaded SeleniumBase tests in UC Mode with a proxy, here's how:
Multi-threading in UC Mode is possible if you use pytest multi-threading provided by pytest-xdist.
You'll need to use command-line options for this format, eg --uc to activate UC Mode, -n4 (for 4 parallel processes, etc), and --proxy=user:pass@host:port to set proxy settings.
Below is a sample run command:
pytest --uc -n4
(Add --proxy=user:pass@host:port to include proxy settings.)
Here's a sample file that uses @pytest.mark.parametrize() to turn one test into four tests when run with pytest:
import pytest
@pytest.mark.parametrize("", [[]] * 4)
def test_multi_threaded(sb):
sb.driver.get("https://nowsecure.nl/#relax")
try:
sb.assert_text("OH YEAH, you passed!", "h1", timeout=5.25)
sb.post_message("Selenium wasn't detected!", duration=2.8)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:
sb.fail('Selenium was detected! Try using: "pytest --uc"')
Here's the output when running that file with pytest --uc -n4:
pytest test_multi_uc.py --uc -n4
============================ test session starts =============================
platform darwin -- Python 3.11.4, pytest-7.4.2, pluggy-1.3.0
rootdir: ~/github/SeleniumBase/examples
configfile: pytest.ini
plugins: html-2.0.1, rerunfailures-12.0, cov-4.1.0, metadata-3.0.0, ordering-0.6, xdist-3.3.1, seleniumbase-4.18.5
4 workers [4 items]
Success! Website did not detect Selenium!
Success! Website did not detect Selenium!
..
Success! Website did not detect Selenium!
.
Success! Website did not detect Selenium!
.
============================= 4 passed in 9.38s ==============================
Some websites may block you if they detect multiple simultaneous connections like that. Be careful where you go.
Note that SeleniumBase has different syntax formats. See: https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md
Also note that pytest-xdist (the multi-processing library for pytest) is more advanced than https://docs.python.org/3/library/concurrent.futures.html for complex multi-threading of this nature.