-
Notifications
You must be signed in to change notification settings - Fork 1.3k
UC drivers overlapping on Multithreading #2006
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
Comments
Multi-threading in UC Mode is possible if you use You'll need to use command-line options for this format, eg Below is a sample run command, with the options you need: pytest --uc -n4
Here's a sample file that uses import pytest
@pytest.mark.parametrize("", [[]] * 4)
def test_multi_threaded(sb):
sb.open("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 test_multi_uc.py --uc -n4
============================ test session starts =============================
platform darwin -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.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.17.13
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 there are different syntax formats. See: https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md Also note that |
but i dont wanna use pytest because this is one function in a big project contains GUI and there're shared resources, so it won't be easy if i use pytest to run multiple browsers |
Unfortunately, pytest has the only working multiprocessing system capable of handling all the shared resources successfully at this time. When the other multiprocessing libraries make improvements, there’s already a TODO for utilizing them. In the meantime, you can try calling pytest from a subprocess, etc, in order to run multiple tests at the same time. Using pytest multiprocessing with SeleniumBase has proven itself to be quite capable of handling shared resources correctly for multiple parallel tests. |
Upgrade to |
Will it now be possible to use the driver manager for Multithreading with uc=True ? |
@MacMarde That depends on how you implement thread-locking. It may work (some people claim it has worked since the |
Thanks so much. This sounds not bad. I will give it a try. |
In the above comment, Multithreading issue is solved ,but the UC mode is called from the command |
SeleniumBase/help_docs/customizing_test_runs.md
See seleniumbase/plugins/pytest_plugin.py for all pytest command-line options. |
That's good ,But can I change User-Agent, proxy in the code after launching with |
After launching with SeleniumBase/help_docs/method_summary.md Line 261 in 77ee514
|
Possible solution to preventing overlap when running multithreaded scripts without Run this before you call import sys
sys.argv.append("-n") That way, the extra code for handling multithreading gets run: (Using locks to handle shared resources).
(That's in a lot of places, but adding the |
When executing this snippet of code below it opens the required number of browsers, but it executes the next lines in the first browser only.
so if the loop runs 4 times it opens 4 browsers but opens new tap and open the link 4 times on the first browser but if i didn't use undetected driver it works well
idk if this is a bug or my code isn't correct but i want to find a solution
The text was updated successfully, but these errors were encountered: