Is there a selenium close browser option at the end of a selenium test?

313    Asked by AnkitChauhan in Cyber Security , Asked on Oct 18, 2022

I have googled for the answer, but the .stop() so frequently mentioned doesn't work for me. The Chrome window the test was running in remains open.

def test_getResults(self):
    sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')
    # do stuff
def tearDown(self):
    sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')

Any ideas? I'm using Selenium Server 2.8.0 with Python 2.6 and mostly using Chrome 14 windows to test.

Answered by Amit raj

You're actually creating a second Selenium close browser session in your tearDown() function. You need to put the session created in setUp() into an instance variable, then close that session in tearDown().

class TestFoo(unittest.TestCase):
    def setUp(self):
        self.selenium = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')
    def tearDown(self):
    def test_bar(self):"/somepage")
        #and so forth

Your Answer


Parent Categories