我已經看到如何檢索運行Python Selenium Unittest的當前測試用例的名稱。檢索當前正在運行的測試用例的名稱
unittest.TestCase.id()
如何使用Webdriver Py.test框架來實現這一目標?
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import *
import pytest, re, time, unicodedata
from pageobjects import locators
from os import sys, path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
def test_PointsBlockingTableNavigationPageLinksBlockingPointsOnly02(driver, url):
所以基本上,我想要檢索的名稱"test_PointsBlockingTableNavigationPageLinksBlockingPointsOnly02"
要麼它打印到屏幕上或在文件名中使用:所以我的測試看起來是這樣的,我沒有使用單元測試框架。
@rwbyrd您能否給我一個示例測試,並詳細說明您爲什麼需要測試名稱?謝謝。 – alecxe
我剛更新了說明。就像我所說的,我只想檢索當前正在運行的測試用例的名稱。我打算在我的錯誤代碼中使用它,這樣當我進行屏幕截圖時,屏幕截圖將會有與測試用例相關聯的名稱,但無法防止混淆。 – rwbyrd
@rwbyrd感謝您的更新!你用鼻子或pytest來進行測試嗎.. – alecxe