Selenium with Python-unittest - 测试返回过程以退出代码0结束,不执行任何操作

时间:2018-06-13 23:03:27

标签: python-3.x selenium selenium-webdriver webdriver python-unittest

有人可以帮助我理解为什么执行以下代码,但是没有执行任何操作吗?

返回的代码为0但未打开浏览器或未执行任何操作。

值得一提的是,setUp方法已在其他模块中以相同方式配置,并且它可以正常工作。 请在最后确认回复。

import unittest
from Init_load import set_up
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By


class HomeTest(unittest.TestCase):

    def setUp(self):
        con = set_up.Connect()
        self.driver = con.setUp()

        #self.link_list = ["Home", "flights", "Destinations", "CONTACT", "SIGN-ON", "REGISTER", "SUPPORT", "Hotels", \
        #                  "Car Rentals", "Cruises"]

        self.home = (By.LINK_TEXT, "Home")
        self.flights = (By.LINK_TEXT, "flights")
        self.destinations = (By.LINK_TEXT, "Destinations")
        self.contact = (By.LINK_TEXT, "CONTACT")
        self.sign_on = (By.LINK_TEXT, "SIGN-ON")
        self.register = (By.LINK_TEXT, "REGISTER")
        self.support = (By.LINK_TEXT, "SUPPORT")
        self.hotels = (By.LINK_TEXT, "Hotels")
        self.car_rentals = (By.LINK_TEXT, "Car Rentals")
        self.cruises = (By.LINK_TEXT, "Cruises")

    def test_homeLink(self):
        self._elementWait(By.LINK_TEXT, "home")
        self.driver.find_element(*self.home).click()

    def test_flight_link(self):
        self._elementWait(By.LINK_TEXT, "flights")
        self.driver.find_element(*self.home).click()

    def test_destinations_link(self):
        self._elementWait(By.LINK_TEXT, "flights")
        self.driver.find_element(*self.destinations).click()

    def test_contact_link(self):
        self._elementWait(By.LINK_TEXT, "flights")
        self.driver.find_element(*self.contact).click()

    def test_signOn_link(self):
        self._elementWait(By.LINK_TEXT, "SIGN-ON")
        self.driver.find_element(*self.contact).click()

    def test_register_link(self):
        self._elementWait(By.LINK_TEXT, "REGISTER")
        self.driver.find_element(*self.register).click()

    def test_support_link(self):
        self._elementWait(By.LINK_TEXT, "SUPPORT")
        self.driver.find_element(*self.support).click()

    def test_hotels_link(self):
        self._elementWait(By.LINK_TEXT, "hotels")
        self.driver.find_element(*self.hotels).click()

    def test_carRentals_link(self):
        self._elementWait(By.LINK_TEXT, "Car Rentals")
        self.driver.find_element(*self.car_rentals).click()

    def test_cruises_link(self):
        self._elementWait(By.LINK_TEXT, "cruises")
        self.driver.find_element(*self.cruises).click()

    def _elementWait(self,how, what):
        WebDriverWait(self.driver, 12).until(expected_conditions.element_to_be_clickable((how, what)), \
                                               "Element not loaded yet")

    def tearDown(self):
        self.driver.quit()

这是回复:

/home/osboxes/PycharmProjects/Automation/venv/bin/python /home/osboxes/PycharmProjects/Automation/unit_test/home_test.py

Process finished with exit code 0

具有完全相同的setUp()函数的其他脚本正确执行但没有这个。我尝试了很多选项,但没有任何作用

1 个答案:

答案 0 :(得分:4)

您是否使用以下代码致电unittest

if __name__ == '__main__':
    unittest.main()

如果不这样做,那么您只是定义测试,而不是实际执行任何操作。