测试套件 python - webdriver [英] test suite python - webdriver

查看:22
本文介绍了测试套件 python - webdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 新手,我正在尝试创建自己的测试套件.

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

主要是在不同的浏览器上执行相同的测试,这就是为什么我使用变量浏览器,在测试中使用它来调用 webdriver.

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.

我有这个:

def test_01(self,browser):

def test_01(self,browser):

def test_02(self,browser):

def test_02(self,browser):

我的套房:

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

主要:

     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:

回溯(最近一次调用最后一次):文件SuiteWebMail.py",第 138 行,在suite1.addTest(Test01.test_01(self, 'firefox'))文件c:\Python34\lib\unittest\suite.py",第 50 行,在 addTestraise TypeError("{} 不可调用".format(repr(test)))类型错误:无不可调用

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

提前致谢

C

推荐答案

也许不是 Pythonic 的方式,但我找到了一个解决方案:

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.

这篇关于测试套件 python - webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆