seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.67k stars 929 forks source link

Account conflict problem under multi-threaded operation #1779

Closed chenhaijun02 closed 1 year ago

chenhaijun02 commented 1 year ago

Hi I'm a beginner and I'm writing a script using this framework. The current scenario is that editor and approver login operations are required in each case. Is there a good way to avoid account conflicts in the case of multi-threaded operation?

mdmintz commented 1 year ago

Hello! There's built-in multithreaded functionality if you use pytest -n=4 (for 4 threads) for example. That will spin up 4 different browsers for your tests, where each one has its own cache. There are several examples in https://github.com/seleniumbase/SeleniumBase/tree/master/examples for login, and there's also a few examples of TinyMCE text editors.

chenhaijun02 commented 1 year ago

Hello! There's built-in multithreaded functionality if you use pytest -n=4 (for 4 threads) for example. That will spin up 4 different browsers for your tests, where each one has its own cache. There are several examples in https://github.com/seleniumbase/SeleniumBase/tree/master/examples for login, and there's also a few examples of TinyMCE text editors.

Thank you very much for your answer, but I currently have account 1 in case1 and need to log in. Case2 also requires account 1 to log in. Using -n=2 will open two windows for account 1 login. But only one can log in successfully, and the other is 403

mdmintz commented 1 year ago

Then it sounds like that website doesn't allow multiple logins by the same user at the same time. Rather than trying to multithread your tests, reuse the session with pytest --rs so that the browser window stays open, and tests run faster.

chenhaijun02 commented 1 year ago

Then it sounds like that website doesn't allow multiple logins by the same user at the same time. Rather than trying to multithread your tests, reuse the session with pytest --rs so that the browser window stays open, and tests run faster.

Thank you so much!!!