简体   繁体   中英

Python + Selenium: Running tests in parallel

How do I run multiple tests in parallel? The tests are written in Python, suite kicks off from jenkins and runs on sauce labs.

When I set up different jobs in jenkins and run them simultaneously they will all fail, I think it is because they aren't set up to run that way.

I apologize if this is a very convoluted question, I was hoping someone could point me in the right direction and I am willing to provide additional documentation.

I've checked this link http://nose.readthedocs.org/en/latest/doc_tests/test_multiprocess/multiprocess.html

and I do run the tests using nose but am not sure if I set it up correctly.

I've also had trouble running Selenium tests in parallel under nose with both Windows and CentOS 7, and with both CPython 3.5.1 AND CPython 3.4.6.

I recommend you switch to pytest and run in parallel using pytest-xdist . A github repository demonstrating how to combine pytest , 'pytest-xdist , and selenium` is available at https://github.com/danizen/python-selenium-parallel .

The key considerations are making sure that an instance of Selenium Webdriver is specific to a process. My recommendation is to use threading.local for that, but my example does it instead by sharing only at the class level.

I also think there's a general need to provide a way for DevOps and developers to specify the parameters for creating the Selenium web driver based on environment variables or command-line options. See https://pypi.org/project/holmium.core/ for one take on how to do that - they may also support multi-threading, but I am not sure. I don't endorse holmium's idea of page objects, however, and many selenium grids are home grown. See https://github.com/ncbi/robotframework-pageobjects/ for another way to do this, this time with robotframework.

Note that nose development has been stopped, but I imagine it would work, at least on Linux, if you are using CPython 2.7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM