Python Selenium-I';我试图使用pytest框架,但遇到了错误
运行上述程序时,当功能#2启动时,程序失败:Python Selenium-I';我试图使用pytest框架,但遇到了错误,python,selenium,automated-tests,pytest,qa,Python,Selenium,Automated Tests,Pytest,Qa,运行上述程序时,当功能#2启动时,程序失败: def-test\u-user\u-profile\u-section\u存在(自身): 它抛出一个错误: self= 响应={'sessionId':'57da643e085012ed03d18a284c063c24','status''7','value':{'message':'没有这样的元素:找不到…r信息:chromedriver=2.29.461591(62EBF098772160F391D75E589DC567915B233),平台=W
def-test\u-user\u-profile\u-section\u存在(自身):
它抛出一个错误:
self=
响应={'sessionId':'57da643e085012ed03d18a284c063c24','status''7','value':{'message':'没有这样的元素:找不到…r信息:chromedriver=2.29.461591(62EBF098772160F391D75E589DC567915B233),平台=Windows NT 6.1.7601 SP1 x8664)}
当程序中只有一个函数时,它可以完美地执行 出现此错误是因为该类元素实际上不存在或不可见。 同样
driver.find\u元素(By.CLASS\u NAME,'user NAME')
不是布尔类型,因此您不能直接对其使用assert
您可以使用以下方法对所有测试进行测试验证
from selenium import webdriver
from selenium.webdriver.common.by import By
from commonPages.LoginPage import LoginPage
from util.InitialSetUp import InitSetup
i = InitSetup()
chrome_options = i.close_popup()
driver = webdriver.Chrome(chrome_options=chrome_options)
log = LoginPage(driver)
log.nav_login_page()
class Test_Home_Page:
def test_logo_exists(self):
logo = driver.find_element(By.CLASS_NAME, 'logo')
assert logo
def test_user_profile_section_exists(self):
user_profile_section = driver.find_element(By.CLASS_NAME, 'user-name')
assert user_profile_section
def test_user_profile_link_click_opens_dropdown(self):
user_profile_link = driver.find_element(By.CLASS_NAME, 'user-dropdown-button')
user_profile_link.click()
user_profile_menu_item = driver.find_element(By.CLASS_NAME, 'user-profile-menu-item')
assert user_profile_menu_item
driver.close()
def test_user_profile_section_exists(self):
try:
driver.find_element(By.CLASS_NAME, 'user-name')
except NoSuchElementException:
assert False
assert True