2

I have a simple test suite defined as below

from unittest import TestLoader, TestSuite, TextTestRunner
from TestScripts.LogOn import test_1
from TestScripts.FirstLog import test_2



if __name__ == "__main__":

    loader = TestLoader()
    suite1 = TestSuite((
        loader.loadTestsFromTestCase(test_1),
        loader.loadTestsFromTestCase(test_2)
        ))


    xrunner = TextTestRunner(verbosity=2)
    xrunner.run(suite1)

When ever I run, I get below error for first test of test class test_1

 selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None
Message: 

But If I comment one of imports (either test_1 or Test_2) and avoid respective test loading to suite, work perfectly. in other words individual test working OK.

If I import both test_1 and test_2 classes, and load only one, same problem occurs i.e. disregards to test loading all imported classes were run and gets the error.

What am'I doing wrong? how to correct it?

I'm developing and running test using eclipse with PyDev

additional.... my classes are derived as below base class....

class BaseTestCase(unittest.TestCase):

    def setUp(self):
        self.driver = DRIVER
        self.driver.implicitly_wait(3)

    def tearDown(self):
        #self.driver.quit()
        pass    


def getFoxDriver():
    ffdrive= webdriver.Firefox()
    ffdrive.get('http://localhost/balbla../')
    time.sleep(20)
    return ffdrive    

DRIVER = getFoxDriver()
1

Looks like you might have some config that needs to be added to the the test classes that isnt being set when they are invoked by the runner. Do you have a ' main' block in the classes file that does this ? If so that won't work , the code that sets up fixtures should go in a SetupClass method.

  • added base class for test cases...I'm instantiation driver separately since need to keep driver alive for those set of test. dose that matters? – 1234 Mar 26 '18 at 22:27
  • Put the call to getFoxDrivet in a SetupClass method , it's currently not in the class so invisible to the test runner – Amias Mar 27 '18 at 7:32
  • You then store DRIVER as cls.driver and use in an instance methods as self.driver – Amias Mar 27 '18 at 7:33
  • Ah , don't try to subclass unitest.testcase classes – Amias Mar 27 '18 at 11:28
  • Got it ..couldn't upvote of lack of reputation – 1234 Mar 27 '18 at 23:45

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.