[英]Passing arguments while running selenium webdriver for Python
I am using selenium python webdriver for my python test cases. 我在我的python测试用例中使用了selenium python webdriver。 I have a python script NowSpots_Traffic.py which I'm trying to run from Ubuntu terminal (something similar to command prompt in windows) 我有一个Python脚本NowSpots_Traffic.py,我正尝试从Ubuntu终端运行该脚本(类似于Windows中的命令提示符)
python /home/vijay/Projects/SeleniumScripts/NowSpots_Traffic.py samuel secrete python /home/vijay/Projects/SeleniumScripts/NowSpots_Traffic.py samuel secrete
where samuel and secrete are two arguments which I need to pass to my python script NowSpots_Traffic.py 其中samuel和secrete是我需要传递给python脚本NowSpots_Traffic.py的两个参数
I followed the instructions found at Running Tests in Python with Selenium 2 and WebDriver section "Multiple browsers and multiple platforms". 我按照在使用Selenium 2和WebDriver的Python中运行测试中找到的说明进行操作,该说明位于“多个浏览器和多个平台”部分。
But I get the following error message 但是我收到以下错误消息
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'
The Unittest.main() function uses the arguments you pass in to determine test cases to run. Unittest.main()函数使用您传入的参数来确定要运行的测试用例。 See here: Test Discovery 参见此处: 测试发现
If your script also needs arguments, you will want to remove them from sys.argv before calling 如果您的脚本也需要参数,则在调用之前,您需要将其从sys.argv中删除。
unittest.main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.