test suite python - webdriver

2019-02-18 17:55发布

I'm new with python, and I'm trying to create my own test suite.

The main pourpose is to execute the same test on different browser, that's why I used the variable browser, that is used within the test to call the webdriver.

I have this:

def test_01(self,browser):

def test_02(self,browser):

my Suite:

    def suite():
        test_suite = unittest.TestSuite()
        suite.addTest(unittest.makeSuite(Test01))
        return test_suite

main:

     if __name__ == "__main__":
             suite1 = unittest.TestSuite()
             self = Test01()
             suite1.addTest(Test01.test_01(self, 'firefox'))
             suite1.addTest(Test01.test_02(self, 'firefox'))
             unittest.TextTestRunner(verbosity=2).run(suite())

When I try to execute that script, the first one test is execute, the second one not, and I got the following error:

Traceback (most recent call last): File "SuiteWebMail.py", line 138, in suite1.addTest(Test01.test_01(self, 'firefox')) File "c:\Python34\lib\unittest\suite.py", line 50, in addTest raise TypeError("{} is not callable".format(repr(test))) TypeError: None is not callable

Thank you in advance

C

1条回答
时光不老,我们不散
2楼-- · 2019-02-18 18:25

maybe isn't a Pythonic way, but I found a solution:

class Test01(unittest.TestCase):

    def test_login(self):
        self.page = "https://myWebPageAddress"
        self.username = "userName"
        self.password = "Password"
        self.browser_label = ['firefox', 'chrome', 'ie']

        for index in range(len(self.browser_label)):
            self.browser_name = self.browser_label[index]


            if self.browser_name == 'firefox':
                logger.debug("Opening [" + self.browser_name + "] ...")
                self.driver = webdriver.Firefox()
            if self.browser_name == 'chrome':
                logger.debug("Opening [" + self.browser_name + "] ...")
                self.driver = webdriver.Chrome()
            if self.browser_name == 'ie':
                logger.debug("Opening [" + self.browser_name + "] ...")
                self.driver = webdriver.Ie()

            try:
                logger.info("Test_01::Case_01::Login OK")
                Test01.case_01(self)
            except BaseException as e:
                logger.fatal(e.value)
        logger.info("End")
        self.driver.close()

    def case_01(self):
    ....
    ....

I hope that's could be helpfull for someone.

查看更多
登录 后发表回答