【问题标题】:Changing test name in python unittest using selenium使用 selenium 在 python unittest 中更改测试名称
【发布时间】:2020-01-30 10:34:20
【问题描述】:

我有一个问题。是否可以使用 python unittests 更改输出中的名称 test?

比如我的测试:

from selenium import webdriver
import unittest
from data.readData import Data
from actions.actions import Actions
from pages.notificationsPage import NotificationsPage

class NotificationsTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome(executable_path=Data.driver)
        cls.driver.implicitly_wait(10)
        cls.driver.maximize_window()

    def test_order_confirmation(self):
        Actions.login(self, Data.email, Data.password)
        driver = self.driver
        driver.get(Data.website + "Admin/Configuration/Message")
        notify = NotificationsPage(driver)
        notify.order_confirmation()

    @classmethod
    def tearDownClass(cls):
        cls.driver.close()
        cls.driver.quit()

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

我的输出:

我想在此输出中以及 res.xml 中的结果文件中将标记的一个测试名称更改为自己的字符串(我认为它是相同的值)。

有可能吗?

【问题讨论】:

    标签: python selenium python-unittest


    【解决方案1】:

    是的,只需更改测试方法的名称即可。只是改变:

        def test_order_confirmation(self):
    

    def whatever_you_want_to_call_your_test(self):
    

    【讨论】:

    • 嘿,嗯...是的。我知道。我的问题不同:如何将测试名称更改为简单字符串?没有test_order_confirmation,而是“测试订单配置”。
    猜你喜欢
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    相关资源
    最近更新 更多