unit testing - How can I execute in parallel Selenium Python tests with unittest -


for example have 2 tests:

class test(unittest.testcase):     def setup(self):     self.driver = webdriver.firefox()     self.driver.get("http://google.com")  def teardown(self):     self.driver.quit()  def test_selenium_1(self):     search_field = self.driver.find_element_by_id("lst-ib")     search_field.send_keys("test 1. number 1")     search_field.submit()     time.sleep(2)  def test_selenium_2(self):     search_field = self.driver.find_element_by_id("lst-ib")     search_field.send_keys("test 1. number 2")     search_field.submit()     time.sleep(2)  if __name__ == '__main__':     unittest.main() 

how can execute these 2 tests in parallel concurrent.futures.executor?

is possible?

i created runner these purposes.

and can execute tests in parallel modules, classes , methods.

import unittest concurrent.futures import threadpoolexecutor  class runner():      def parallel_execution(self, *name, options='by_module'):          """         name - name of class tests or module classes contain tests         modules - name of module tests or class contains tests         options:             by_method - gather tests methods in class/classes , execute in parallel             by_module - gather tests modules in parallel             by_class - execute classes (with tests) in parallel         """          suite = unittest.testsuite()          if (options=='by_method'):             object in name:                 method in dir(object):                     if (method.startswith('test')):                         suite.addtest(object(method))         elif (options=='by_class'):             object in name:                 suite.addtest(unittest.testloader().loadtestsfromtestcase(object))          elif (options=='by_module'):             module in name:                 suite.addtest(unittest.testloader().loadtestsfrommodule(module))         else:             raise valueerror("parameter 'options' incorrect."                              "available options: 'by_method', 'by_class', 'by_module'")          threadpoolexecutor(max_workers=10) executor:             list_of_suites = list(suite)             test in range(len(list_of_suites)):                 test_name = str(list_of_suites[test])                 executor.submit(unittest.texttestrunner().run, list_of_suites[test]) 

examples:

#by_methods runner().parallel_execution(test1.test1, test2.test22, test2.test33, options='by_method')  #by_class runner().parallel_execution(test1.test1, test2.test22, test2.test33, options='by_class')  #by_modules runner().parallel_execution(test1, test2) 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -