test suite python - webdriver

后端 未结 1 1714
情深已故
情深已故 2021-01-14 08:42

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 variabl

相关标签:
1条回答
  • 2021-01-14 09:26

    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.

    0 讨论(0)
提交回复
热议问题