Selenium对Python测试结果在0.000s内运行0次测试

时间:2016-02-01 15:15:15

标签: python-2.7 selenium automated-tests

我在Python中进行selenium测试,我在项目中有很多测试。我从linux服务器迁移到Windows测试服务器(浏览器和测试正在这台服务器上运行)一切都很顺利,但是每次创建的新测试都无法运行,我不知道为什么。它写“在0000秒内测试0”“确定”其他测试我可以正常运行。

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“在0.000秒内执行0测试”“确定”):

# 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来自同一个方法 - 我认为没有问题。任何解决方案?

1 个答案:

答案 0 :(得分:0)

它是文件名中的短划线( - )" test_systemlive_2_4_2_6-7_extensions.py"