python-3.x - Selenium 与 Python-unittest - 测试返回进程已完成,退出代码为 0,并且不执行任何操作

标签 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() 函数的其他脚本都可以正确执行,但这个脚本不行。我尝试了很多选择,但没有任何效果

最佳答案

您是否使用以下方式调用您的unittest:

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

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

关于python-3.x - Selenium 与 Python-unittest - 测试返回进程已完成,退出代码为 0,并且不执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50847485/

相关文章:

selenium - 如何使用 Protractor 测试 svg 饼图和图形?

python-3.x - 有没有一种Pythonic方法将日期时间上的数据帧与具有不规则日期时间戳的数据对合并

python - 如何在使用 PyQt5 打开新窗口时隐藏当前窗口

python - cv2.imshow 显示 9 个屏幕而不是 1 个

C# Selenium RC - 如何测试 jQuery 按钮点击?

python - 使用 selenium 从 html 表中获取数据(python): Submitting changes breaks loop

python - urllib.request.urlopen 不接受带空格的查询字符串

python - 如何循环浏览并点击相关项目

python - 单击按钮的代码可以运行一次,但不能运行两次

java - 在 selenium webdriver 中,我可以点击保存按钮然后页面被保存但是它没有显示这样的元素错误消息无法继续