Closed hwk06023 closed 1 month ago
A few things: If using ThreadPoolExecutor
instead of pytest-xdist
for multithreading, be sure to add
sys.argv.append("-n")
to activate SeleniumBase thread-locking as needed. Example:
import sys
from concurrent.futures import ThreadPoolExecutor
from seleniumbase import Driver
sys.argv.append("-n") # Tell SeleniumBase to do thread-locking as needed
def launch_driver(url):
driver = Driver()
try:
driver.get(url=url)
driver.sleep(2)
finally:
driver.quit()
urls = ['https://seleniumbase.io/demo_page' for i in range(4)]
with ThreadPoolExecutor(max_workers=len(urls)) as executor:
for url in urls:
executor.submit(launch_driver, url)
For headless Linux environments, you may want to use xvfb=True
in your Driver()
declaration. Also note that there is a newer Chromium headless mode, which is activated by using headless2=True
in your Driver()
declaration.
Now, I'm using like below.
This doesn't work well in parallel. How can I fix it?
It worked fine when using Selenium's Webdriver, but I want to use it(Seleniumbase) because of chromedriver's automatic download feature.
In above, it worked fine in local, but when running in environments like AWS Lambda, the Chrome WebDriver was not automatically installed properly.
Thank you.