【问题标题】:On Running the test suite: Runs the test suite shows test passed Notification but displays "Empty Suite"在运行测试套件时:运行测试套件显示测试通过通知但显示“空套件”
【发布时间】:2020-06-14 13:36:44
【问题描述】:

这是我的代码,但它显示没有找到测试,并打印空套件

import unittest
import time
from selenium import webdriver


class LoginTest(unittest.TestCase):
    driver = webdriver.Chrome(executable_path="C:\\Users\\win\\Desktop\\chromedriver.exe")

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome(executable_path="C:\\Users\\win\\Desktop\\chromedriver.exe")
        cls.driver.implicitly_wait(10)

    def Test(self):
        self.driver.get("https://opensource-demo.orangehrmlive.com/")
        self.driver.find_element_by_id("txtPassword").send_keys("admin123")
        self.driver.find_element_by_id("txtUsername").send_keys("Admin")
        self.driver.find_element_by_id("btnLogin").click()
        time.sleep(2)

    @classmethod
    def tearDownClass(cls):
        cls.driver.close()
        cls.driver.quit()
        print("Test Complete")


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

我编写了这段代码,但在运行我的测试套件时显示如下:

Testing started at 2:47 PM ...
C:\PycharmProject\OrangeHRM\venv\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --target LoginTest.LoginTest
Launching unittests with arguments python -m unittest LoginTest.LoginTest in C:\PycharmProject\OrangeHRM\ScriptsDemo\Tests



Ran 0 tests in 0.000s

OK

Process finished with exit code 0

No Tests were found

Empty suite

【问题讨论】:

    标签: python selenium google-chrome pycharm webdriver


    【解决方案1】:

    unittest library 中存在一个命名约定,即所有测试都以“test”开头,这会告知测试运行器哪些方法代表测试。

    您必须将“测试”方法更改为“测试”

    【讨论】:

    • 它对我有用,但我也想知道,它会打开两个网络浏览器。背后的原因是什么?
    • setUpClass 在执行测试套件之前执行一次,此方法在变量 ⇾ cls.driver 中提供了一个 webdriver 存储实例当您在创建类后分配驱动程序变量时,您正在创建另一个驱动程序这就是为什么您会看到 2 个网络驱动程序。删除第一个即可。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    相关资源
    最近更新 更多