I am having a problem in running an aggregated test suite of selenium tests using unit-test in python.
Below code is executing the test from another module without the testRunner being called.
When I tried executing in debug mode, the control was passed to pydev_runfiles soon after it executed the class definition line and eventually executed the test in the other module(gmailbutton).
import unittest
from selenium import webdriver
from gmailbutton import gmailButton
class runner():
def runner1(self):
suite = unittest.TestSuite()
suite.addTest(gmailButton)
return suite
As per the documentation(http://docs.python.org/2/library/unittest.html) the above code had to just add the test case to the suite and test should have executed on
unittest.TextTestRunner(verbosity=2).run(suite)
which is not happening here.
Test code for gmailButton is here
import unittest
from selenium import webdriver
class gmailButton(unittest.TestCase):
global browser
def test_gmailButton(self):
browser = webdriver.Firefox()
try:
browser.get("http://www.gmail.com")
browser.find_element_by_id("Email").send_keys("abcd")
browser.find_element_by_id("Passwd").send_keys("123445")
browser.find_element_by_id("signIn").click()
except Exception as e:
raise
print e
finally:
browser.close()
UPDATE:
Here is the exact code I am executing from eclipse.
import unittest
from selenium import webdriver
from gmailbutton import gmailButton
from pyUnitExercise import exercise1
class runner():
def runner1(self):
suite = unittest.TestSuite()
suite.addTest(gmailButton)
return suite
if __name__ == "__main__":
unittest.TextTestRunner(verbosity=2).run(runner.suite)
My expectation from this code is to execute gmailButton test case and NOT exercise1 which is just imported and not added to the test suite. I’ve no idea why is it executing the test which was just imported and not added to the test suite.
If you are using PyDev, you are probably not actually using python’s stdlib unittest. It uses nose and/or py.test:
http://pydev.org/manual_adv_pyunit.html
Both of those libraries search for tests via introspection; you don’t need to add explicit entries to a test suite. Without the output from when the tests get run, it’s hard to tell if this is actually what’s going on, though.