【发布时间】:2016-05-10 02:35:42
【问题描述】:
我正在 Python 中进行硒测试,并且我在项目中有很多测试。我从 linux 服务器迁移到 windows 测试服务器(浏览器和测试正在此服务器上运行)一切正常,但是创建的每个新测试我都无法运行,我不知道为什么。它写 "Ran 0 test in 0.000s" "OK" 我可以正常运行的其他测试。
cmd中的两个命令(第一个失败,第二个正确):
C:\Python27\python.exe -m unittest discover ../autotesty "test_systemlive_2_4_2_6-7_extensions.py"
C:\Python27\python.exe -m unittest discover ../autotesty "test_systemlive_2_4_2_1_new_rec_unit.py"
文件 test_systemlive_2_4_2_6-7_extensions.py - 测试失败(写入 cmd "Ran 0 tests in 0.000s" "OK"):
# coding=utf-8
__author__ = 'u-zima00m1'
from lib import selenium_tools as st
import unittest
import time
class Extensions(unittest.TestCase):
def setUp(self):
st.set_up(self)
def test_13_01_extensions(self):
driver = self.driver
st.login(self, "bossboss", "Bossboss1")
st.select_roles(self, "God", "root")
st.switch_to_page(self, "System")
st.switch_to_sub_page(self, "CTI")
st.switch_to_sub_sub_page(self, "CTI Servers")
st.wait_for_element(self, "//a[@title='New']/img[@src='/experience/img-dist/New.svg']", "XPATH")
driver.find_element_by_xpath("//a[@title='New']/img[@src='/experience/img-dist/New.svg']").click()
time.sleep(1)
# Other long code ...
def tearDown(self):
st.tear_down(self)
if __name__ == "__main__":
unittest.main()
文件 tests_systemlive_2_4_2_1_new_rec_unit.py - 正确的测试(这将运行浏览器和 selenium 完成他的工作):
# coding=utf-8
__author__ = 'u-zima00m1'
from lib import selenium_tools as st
import unittest
import time
class NewRecUnit(unittest.TestCase):
def setUp(self):
st.set_up(self)
def test_10_01_create_RU(self):
driver = self.driver
suite = unittest.TestLoader().discover('.', pattern="rex_simulator.py")
unittest.TextTestRunner(verbosity=3).run(suite)
st.login(self, "bossboss", "Bossboss1")
st.select_roles(self, "God", "root")
st.switch_to_page(self, "System")
st.switch_to_sub_page(self, "Recording sources")
st.switch_to_sub_sub_page(self, "Recording units")
driver.find_element_by_xpath("//a[@title='New']/img[@src='/experience/img-dist/New.svg']").click()
time.sleep(1)
# Other long code ...
def tearDown(self):
st.tear_down(self)
if __name__ == "__main__":
unittest.main()
两个测试中的 setUp 和 tearDown 来自相同的方法 - 我认为没有问题。有什么解决办法吗?
【问题讨论】:
-
Ups... 这是因为文件名 test_systemlive_2_4_2_6-7_extensions.py 中的破折号。对不起,我还是 Python 的初学者 :(
标签: python-2.7 selenium automated-tests