At least a part of the problem is likely because of the Python local vs global behaviour of variables. Adding some comments to your code:
def test_getResults(self):
""" Get a test result """
# The next line creates a local selenium web driver instance and connects it
sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')
sel.start()
# do stuff
# At this point sel goes out of scope but we have done nothing to stop it
def tearDown(self):
"""End of testing!"""
# The next line creates a local selenium web driver instance and connects it
sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')
sel.close() # Closes the local sel instance
sel.stop() # Stops the local sel instance
So the sel
instance that you create in test_getResults
is not, by default, the one that you stop. Unless the selenium
function that you do not show is:
- Checking for an existing instance of the driver and if it exists calling get with the parameters then returning the handle for the driver
- If the driver does not exist create and do get then return the handle
Since you give a self parameter to each method I presume that the methods are being created as class members for the same class instance. In that case something like:
def test_getResults(self):
""" Get a test result """
# The next lines gets or creates a selenium web driver instance and connects it
if not hasattirbute(self, 'sel) or self.sel is None:
# No running instance available
self.sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')
self.sel.start()
sel = self.sel # Local variable to point to the class member
else:
sel = self.sel
self.get('http://blackpearl/')
# do stuff
# At this point sel goes out of scope but but self.sel does not
def tearDown(self):
"""End of testing!"""
if hasattirbute(self, 'sel) and self.sel is not None:
self.sel.Quit()
del self.sel # just in case self persists
else:
print("WARNING: tearDown called with nothing to do!")
Personally I would also import atexit
and when creating self.sel
register self.tearDown
as an exit handler.