我在我的python测试用例中使用selenium python webdriver。 我有一个python脚本NowSpots_Traffic.py,我试图从Ubuntu终端运行(类似于Windows中的命令提示符)
python /home/vijay/Projects/SeleniumScripts/NowSpots_Traffic.py samuel secrete
其中samuel和secrete是我需要传递给我的python脚本的两个参数NowSpots_Traffic.py
我按照Running Tests in Python with Selenium 2 and WebDriver上的说明进行操作 “多个浏览器和多个平台”部分。
但是我收到以下错误消息
Traceback (most recent call last):
File "/home/vijay/Projects/SeleniumScripts/NowSpots_Traffic.py", line 43, in <module>
unittest.main()
File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/usr/lib/python2.7/unittest/main.py", line 152, in parseArgs
self.createTests()
File "/usr/lib/python2.7/unittest/main.py", line 161, in createTests
self.module)
File "/usr/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'samuel'
答案 0 :(得分:1)
Unittest.main()函数使用您传入的参数来确定要运行的测试用例。见这里:Test Discovery
如果您的脚本也需要参数,您需要在调用
之前将其从sys.argv中删除unittest.main()