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

526    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/')
    sel.start()
    # do stuff
def tearDown(self):
    sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')
    sel.close()
    sel.stop()

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/')
        self.selenium.start()
    def tearDown(self):
        self.selenium.stop()
    def test_bar(self):
        self.selenium.open("/somepage")
        #and so forth

Your Answer

Interviews

Parent Categories