久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='vIqlJ'><style id='vIqlJ'><dir id='vIqlJ'><q id='vIqlJ'></q></dir></style></legend>

    <i id='vIqlJ'><tr id='vIqlJ'><dt id='vIqlJ'><q id='vIqlJ'><span id='vIqlJ'><b id='vIqlJ'><form id='vIqlJ'><ins id='vIqlJ'></ins><ul id='vIqlJ'></ul><sub id='vIqlJ'></sub></form><legend id='vIqlJ'></legend><bdo id='vIqlJ'><pre id='vIqlJ'><center id='vIqlJ'></center></pre></bdo></b><th id='vIqlJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vIqlJ'><tfoot id='vIqlJ'></tfoot><dl id='vIqlJ'><fieldset id='vIqlJ'></fieldset></dl></div>
  • <small id='vIqlJ'></small><noframes id='vIqlJ'>

    • <bdo id='vIqlJ'></bdo><ul id='vIqlJ'></ul>

    <tfoot id='vIqlJ'></tfoot>

        Python unittest 將參數傳遞給父測試類

        Python unittest passing arguments to parent test class(Python unittest 將參數傳遞給父測試類)

            <small id='xSNpK'></small><noframes id='xSNpK'>

              <tfoot id='xSNpK'></tfoot>
            • <i id='xSNpK'><tr id='xSNpK'><dt id='xSNpK'><q id='xSNpK'><span id='xSNpK'><b id='xSNpK'><form id='xSNpK'><ins id='xSNpK'></ins><ul id='xSNpK'></ul><sub id='xSNpK'></sub></form><legend id='xSNpK'></legend><bdo id='xSNpK'><pre id='xSNpK'><center id='xSNpK'></center></pre></bdo></b><th id='xSNpK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xSNpK'><tfoot id='xSNpK'></tfoot><dl id='xSNpK'><fieldset id='xSNpK'></fieldset></dl></div>
                <tbody id='xSNpK'></tbody>
                <bdo id='xSNpK'></bdo><ul id='xSNpK'></ul>
                  <legend id='xSNpK'><style id='xSNpK'><dir id='xSNpK'><q id='xSNpK'></q></dir></style></legend>
                  本文介紹了Python unittest 將參數傳遞給父測試類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個名為 basetestcase() 的父測試類這是由所有測試類繼承的

                  I have a parent test class named as basetestcase() This is inherited by all the test classes

                  class BaseTestCase(unittest.TestCase):
                  
                      driver = None
                      browser = read from command line
                      operatingSystem = read from command line
                      url = read from command line
                  
                      @classmethod
                      def setUpClass(cls):
                          """
                          SetUp to initialize webdriver session, pages and other needed objects
                  
                          Returns:
                          None
                          """
                          # Get webdriver instance
                          # Browser should be read from the arguments
                          if browser == "iexplorer":
                              cls.driver = webdriver.Ie()
                          elif browser == "firefox":
                              cls.driver = webdriver.Firefox()
                          elif browser == "chrome":
                              cls.driver = webdriver.Chrome()
                          else:
                              cls.driver = webdriver.PhantomJS()
                  
                          # Similarly I want to get operating system and url also from command line
                          driver.get(url)
                          print("Tests are running on: " + operatingSystem)
                  

                  然后我有兩個單獨的測試類:

                  Then I have two separate test classes:

                  class TestClass1(BaseTestCase):
                  
                      @classmethod
                      def setUpClass(cls):
                          super(TestClass1, cls).setUpClass()
                          # Create object of another class to use in the test class
                          # cls.abc = ABC()
                  
                      def test_methodA(self):
                          # self.abc.methodFromABC() # This does not work
                          # Not sure if I can use self.driver as it was defined as cls.driver in the setUpClass()
                          self.driver.find_element(By.ID, "test_id").click()
                  
                  if __name__ == '__main__':
                  unittest.main(verbosity=2)
                  

                  這是第二類,兩個類都在單獨的 .py 文件中

                  This is the 2nd class, both the classes are in separate .py files

                  class TestClass2(GUIBaseTestCase):
                  
                      @classmethod
                      def setUpClass(self):
                          super(TestClass2, self).setUpClass()
                  
                      def test_methodA(self):
                          self.driver.find_element(By.ID, "test_id").click()
                  
                  if __name__ == '__main__':
                  unittest.main(verbosity=2)
                  

                  然后我有一個測試套件腳本,一個單獨的 .py 文件,它將它們組合在一起在一個套件中運行

                  Then I have a test suite script, a separate .py file which clubs them together to run in a suite

                  import unittest
                  from tests.TestClass1 import TestClass1
                  from tests.TestClass2 import TestClass2
                  
                  # Get all tests from TestClass1 and TestClass2
                  tc1 = unittest.TestLoader().loadTestsFromTestCase(TestClass1)
                  tc2 = unittest.TestLoader().loadTestsFromTestCase(TestClass2)
                  
                  # Create a test suite combining TestClass1 and TestClass2
                  smokeTest = unittest.TestSuite([tc1, tc2])
                  
                  unittest.TextTestRunner(verbosity=2).run(smokeTest)
                  

                  我想運行測試套件,并想從命令行向 basetestcase 提供瀏覽器、操作系統和 url,這些參數直接由 basetestcase.py 使用.實際測試類繼承 basetestcase.

                  I want to run the test suite and want to provide browser, operating system and url to the basetestcase from the command line and these arguments are directly used by basetestcase.py. Actual test classes inherit the basetestcase.

                  您能否幫助我以最佳方式從命令行獲取這些值并提供給基本測試用例?

                  Could you please help me with how to get these values from the command line in the best way and provide to the basetestcase?

                  推薦答案

                  我也很難在多個瀏覽器上運行相同的測試用例.經過多次迭代、反復試驗以及朋友們的意見,我為我的項目實施了以下解決方案:

                  I also struggled to run the same test cases on multiple browsers. After a lot of iterations, trial and error and input from friends I implemented the following solutions to my projects:

                  這里的 TestCase 是包含所有測試的類,瀏覽器驅動程序為 None.SafariTestCase 繼承 TestCase 并覆蓋 setUpClass 并將瀏覽器驅動程序設置為 safari 驅動程序,與 ChromeTestCase 相同,您可以為其他瀏覽器添加更多類.可以在 TestSuite 文件中獲取命令行輸入,并根據參數有條件地加載測試:

                  Here TestCase is the class that has all the tests and the browser driver is None. SafariTestCase inherits the TestCase and overrides setUpClass and sets the browser driver to be safari driver and same with the ChromeTestCase and you can add more class for other browsers. Command Line input can be taken in the TestSuite file and conditionally load tests based on the arguments:

                  class TestCase(unittest.TestCase):
                    @classmethod
                    def setUpClass(cls):
                      cls.browser = None
                  
                    def test_1(self):
                      self.assert(self.browser.find_element_by_id('test1')
                  
                    def test_2(self):
                      self.assert(self.browser.find_element_by_id('test2')
                  
                    def test_3(self):
                      self.assert(self.browser.find_element_by_id('test3')
                  
                    @classmethod
                    def tearDownClass(cls):
                      cls.browser.quit()
                  
                  
                  class SafariTestCase(TestCase):
                    @classmethod:
                    def setUpClass(cls):
                      cls.browser = webdriver.Safari(executable_path='/usr/bin/safaridriver')
                  
                  class ChromeTestCase(TestCase):
                    @classmethod:
                    def setUpClass(cls):
                      cls.browser = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')  
                  

                  在運行器文件TestSuite.py中:

                  In the runner file TestSuite.py:

                  import TestCase as tc
                  
                  if len(sys.argv) == 1:
                    print("Missing arguments, tell a couple of browsers to test against.")
                    sys.exit(1)
                  
                  if sys.argv[1] == 'safari':
                    test = unittest.TestLoader().loadTestsFromTestCase(tc.SafariTestCase)
                  
                  if sys.argv[1] == 'chrome':
                    test = unittest.TestLoader().loadTestsFromTestCase(lt.ChromeTestCase)
                  
                  unittest.TextTestRunner().run(test)
                  

                  這篇關于Python unittest 將參數傳遞給父測試類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)
                • <legend id='7Mu7b'><style id='7Mu7b'><dir id='7Mu7b'><q id='7Mu7b'></q></dir></style></legend>

                    <tfoot id='7Mu7b'></tfoot>
                            <tbody id='7Mu7b'></tbody>

                        • <i id='7Mu7b'><tr id='7Mu7b'><dt id='7Mu7b'><q id='7Mu7b'><span id='7Mu7b'><b id='7Mu7b'><form id='7Mu7b'><ins id='7Mu7b'></ins><ul id='7Mu7b'></ul><sub id='7Mu7b'></sub></form><legend id='7Mu7b'></legend><bdo id='7Mu7b'><pre id='7Mu7b'><center id='7Mu7b'></center></pre></bdo></b><th id='7Mu7b'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7Mu7b'><tfoot id='7Mu7b'></tfoot><dl id='7Mu7b'><fieldset id='7Mu7b'></fieldset></dl></div>
                            <bdo id='7Mu7b'></bdo><ul id='7Mu7b'></ul>

                            <small id='7Mu7b'></small><noframes id='7Mu7b'>

                            主站蜘蛛池模板: 国产免费一区 | 久久综合av| 久久久综合 | 国产网站在线 | 日韩精品中文字幕在线观看 | 国产午夜精品视频 | 三级a毛片| 日韩精品一区二区三区免费视频 | 免费在线小视频 | 免费av大片 | 免费毛片在线 | 欧美精品二区三区四区免费看视频 | 神马影院午夜伦理片 | 国产激情小视频 | 欧美日韩高清 | 国产区视频 | 中文一级片 | 色中色av| 国产a久久麻豆入口 | 97在线免费观看 | 91久久久久国产一区二区 | 免费看一级片 | 欧美日韩一 | 在线观看免费av网站 | 一级片免费观看 | 国产精品欧美精品 | 91亚洲精品在线 | 一区二区高清视频 | 国产极品国产极品 | 天天色小说 | 日韩av一级片 | 国产精品99久久久久久久久久久久 | 欧美成人精品一区二区三区 | 免费看黄色av | 国产一区在线播放 | 日本免费中文字幕 | 青青草视频免费在线观看 | 中文字幕国产 | 欧美激情精品 | 国产在线一区二区三区 | 国产成人三级在线观看 |