如何向 Selenium RC TestSuite 输入参数?
我必须测试几个销售相同产品的网站,但他们有另一个模板。
所以我想运行每个 MainTestClass 并给出一些输入参数,比方说:
java -jar SeleniumServerStandalone-2.0b2.jar -port 5555 (template_id=5)
这可能吗?
class MainTestCases(unittest.TestCase):
def setUp(self):
#self.template_id=template_id I want something like that
self.verificationErrors = []
self.selenium = selenium("localhost", 5555, "*chrome", "http://www.google.com/")
time.sleep(5)
self.selenium.start()
def test_test1(self):
if self.template_id==1:
...
elif self.template_id==2:
...
def test_test2(self):
if self.template_id==1:
...
elif self.template_id==2:
...
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
I have to test few sites which sales the same things, but they have an another template.
So I want to run each MainTestClass with giving some input parameter, let's say :
java -jar SeleniumServerStandalone-2.0b2.jar -port 5555 (template_id=5)
Is it possible?
class MainTestCases(unittest.TestCase):
def setUp(self):
#self.template_id=template_id I want something like that
self.verificationErrors = []
self.selenium = selenium("localhost", 5555, "*chrome", "http://www.google.com/")
time.sleep(5)
self.selenium.start()
def test_test1(self):
if self.template_id==1:
...
elif self.template_id==2:
...
def test_test2(self):
if self.template_id==1:
...
elif self.template_id==2:
...
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试向 MainTestCases 添加一个 init 方法,如下所示:
由于此自定义,您将需要手动构建测试套件,因为每个测试用例都必须使用 template_id 实例化,如下所示 -
然后main,而不是unittest.main(),做:
Try adding an init method to MainTestCases, like so:
Due to this customization, you will need to build your test suite manually because each test case has to be instantiated with the template_id, like so--
Then in main, instead of unittest.main(), do:
现在,我使用这个解决方案:
导入unittest
从 Flights.FlightsTestCases 导入 FlightsTestCases
导入系统
from Flights.FlightTemplate import FlightTemplate
def suite():
将 set_up 更改为:
class FlightsTestCases(unittest.TestCase):
www_地址 = 无
飞行模板 = 无
xml_report_generator = 无
Now, I use this solution:
import unittest
from Flights.FlightsTestCases import FlightsTestCases
import sys
from Flights.FlightTemplate import FlightTemplate
def suite():
change set_up to something like:
class FlightsTestCases(unittest.TestCase):
www_address = None
flight_template = None
xml_report_generator = None