问题描述
我有一个名为 basetestcase() 的父测试类这是由所有测试类继承的
I have a parent test class named as basetestcase() This is inherited by all the test classes
然后我有两个单独的测试类:
Then I have two separate test classes:
这是第二类,两个类都在单独的 .py 文件中
This is the 2nd class, both the classes are in separate .py files
然后我有一个测试套件脚本,一个单独的 .py 文件,它将它们组合在一起在一个套件中运行
Then I have a test suite script, a separate .py file which clubs them together to run in a suite
我想运行测试套件,并想从命令行向 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:
在运行器文件TestSuite.py中:
In the runner file TestSuite.py:
这篇关于Python unittest 将参数传递给父测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!