2

I have a python script, which uses Selenium. I need to run multiple instances of the script at the same time, that is, the same script run multiple times with the different arguments:

python my_script.py --arg1 2222222
python my_script.py --arg1 222
python my_script.py --arg1 342432

In the code they all use the same browser (not the same window, but the same browser). Each script uses only one thread in it if that matters.

So is it ok to run them all at the same time? Can it lead to a misbehaviour? Or generally everything should be ok?

I haven't found an information at Selenium website about that.

And also and more importantly, will they share cache/proxies/cookies or will each instance of a browser have its own ones? For example, if I run 5 scripts so each one will have its own browser, say, Firefox, will each Firefox have its own cache/proxies/cookies?

1 Answers1

2

Everytime we invoke browser through Selenium, it creates a new instance thread of specified browser. If you have defined DesiredCapabilities those specific settings will be applied to the browser instance that gets invoked.

This is the exact reason, you can run selenium tests parallel fashion, running multiple instances of the browser, where each browser is getting executed with different scripts.

http://www.guru99.com/sessions-parallel-run-and-dependency-in-selenium.html gives little bit of information about how selenium handles browser instances.

Browser starts from clean state where No Cache/Proxy/Cookies are stored. You can notice that selenium launched browser instance will not have any extensions/add-ons.

parishodak
  • 4,506
  • 4
  • 34
  • 48
  • so each instance of the **same** browser can connect to the internet via its own proxy? –  Dec 17 '15 at 13:09
  • you mean you have many internet sources, and you want proxies to be changed for each browser? Refer this link for setting your own proxy http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy – parishodak Dec 17 '15 at 13:11
  • if you just want the website to be connected from browser, be assured that browser instances are on its own, and though it uses same proxy, there wont be any interference between two browsers. – parishodak Dec 17 '15 at 13:17
  • I know how to change it. My question is about multiple instances of my script and each of them running an instance of, say, Firefox. So there're 5 Fifrefox'es running at the **same time** (probably for different urls but not necessarily), can I set for each of those 5 Firefox'es a different proxy? –  Dec 17 '15 at 13:31