2

I need to open every new iteration, new browser windows. For example:

class GoogleTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.browser = browser_incognito.chrome_incognito()
        cls.wait = WebDriverWait(cls.browser, 20)
        cls.browser.implicitly_wait(30)

    def test_01_goole(self):
        for i in range(3):
            browser = self.browser
            browser.get('http://www.google.com')

In this situation I don't see new browser windows. But in this situation:

class GoogleTest(unittest.TestCase):

    # @classmethod
    # def setUpClass(cls):
        # cls.browser = browser_incognito.chrome_incognito()
        # cls.wait = WebDriverWait(cls.browser, 20)
        # cls.browser.implicitly_wait(30)

    def test_01_goole(self):
        for i in range(3):
            # browser = self.browser
            browser = browser_incognito.chrome_incognito()
            browser.get('http://www.google.com')

I receive 3 new browser windows (browser_incognito.chrome_incognito() it's another module that I created). I need browser from setUpClass().

  • Why do you want to loop in the test? Wouldn't it be better to create three separate tests? – Niels van Reijmersdal Feb 9 '17 at 10:55
  • In my situation I need create users (for example I need 8 users), every iteration I create new user, the problem is that all user must to do google authorization, and where is the problem, the problem is when I start new iteration after I created new user in previously iteration the browser record session for previously user and I can't continue with my process. So for solution of this problem I want to use chrome incognito, and every iteration open new chrome incognito windows. – alex Feb 9 '17 at 11:04
1

You are using setUpClass() this is only run once when the testClass is created.

I think you want to use setUp() instead which is called before each test.

setUp(): Method called to prepare the test fixture. This is called immediately before calling the test method; other than AssertionError or SkipTest, any exception raised by this method will be considered an error rather than a test failure. The default implementation does nothing.

Read the documentation to understand the difference better: https://docs.python.org/2/library/unittest.html#test-cases

For having setting up multiple browsers in your setup functions you could try to create an array.

def setUp(cls):
    cls.browser[1] = browser_incognito.chrome_incognito()
    cls.browser[2] = browser_incognito.chrome_incognito()
    cls.browser[3] = browser_incognito.chrome_incognito()

def test(self):
    for i in range(3):
        browser = self.browser[i]
        browser.get('http://www.google.com')
  • It's still open only one window. – alex Feb 9 '17 at 10:36
  • Ah sorry miss read your question, you want ONE test to have three browsers windows open, not each test having a fresh browser. – Niels van Reijmersdal Feb 9 '17 at 10:50
  • Yes, in one test I want open every iteration, new browsers windows. – alex Feb 9 '17 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.