Can Selenium use multi threading in one browser?
Asked Answered
P

2

25

I want to test a web in multi threading but when I open too many chromedrivers they use too much memory. Can I use multi threading in one browser?

Pecos answered 12/6, 2015 at 17:7 Comment(3)
Hi...do you mean you want to run tests simultaneously in different tabs but in a single browser (instance) windowMulatto
Yes,and each tab can run as a threading,then I can open the url in the same time.How can I do.Thx.Pecos
Related question #28093847Riggs
M
29

WebDriver is not thread-safe. The issue of thread-safety isn't in your code but in the actual browser bindings. They all assume there will only be one command at a time (e.g. like a real user). But you can on the other hand instantiate one WebDriver instance for each thread but it will launch multiple browsers which will consume more memory.

Mulatto answered 14/6, 2015 at 10:4 Comment(0)
C
25

The multithreading should be done on different instances of Webdriver as Webdriver itself is a single thread.

Different threads can be run on same Webdriver, but then the results of the tests would not be what you expected. Let me explain it.

When you use multithreading to run different tests on different tabs(that't not impossible, little bit of coding is required), the actions you will perform like click or send keys will go to the opened tab that is currently focused regardless of the test running. That means all the test will run simultaneously on the same tab that has focus and not on intended tab.

You can read about multithreading in Webdriver.

Cristacristabel answered 14/6, 2015 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.