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

654    Asked by AlastairMcDade in QA Testing , Asked on Feb 15, 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 alex GONZALEZ

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