python - 没有显示错误,但程序未在 pytest 中运行
问题描述
//这是Conftest.py文件
import pytest
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium import webdriver
option1=Options()
option1.add_experimental_option("prefs",{"profile.default_content_setting_values.notifications":1})
print("setupfunction")
@pytest.fixture(scope="class")
def setup(request):
print("setupfunction")
driver = webdriver.Chrome(executable_path="D:\\chrome\\chromedriver_win32 (1)\\chromedriver.exe",options=option1)
driver.get("https://web.comrate.com/")
driver.maximize_window()
request.cls.driver=driver
yield
driver.close()
//这是baseclass.py文件
import pytest
import logging
@pytest.mark.usefixtures("setup")
class baseclass:
pass
//这是Logintest.py文件
from selenium.webdriver.common.by import By
import pytest
class TESTLOGIN():
def __init__(self,driver):
self.driver=driver
loginbutton=(By.XPATH,"//a[@class='btn btn-default'][@id='loginbtn']")
emailaddress =(By.XPATH,"//input[@name='login_email']")
password=(By.XPATH,"//input[@name='login_password']")
logintoaccount=(By.XPATH,"//a[@class='btn btnDanger']")
def testloginbutton(self):
return self.driver.find_element(TESTLOGIN.loginbutton)
def testemail(self):
return self.driver.find_element(TESTLOGIN.emailaddress)
def testpwd(self):
return self.driver.find_element(TESTLOGIN.password)
def testlogin(self):
return self.driver.find_element(TESTLOGIN.logintoaccount)
//这是主文件
import time
import pytest
from Logintest import TESTLOGIN
from baseclass import baseclass
class testloginfunction(baseclass):
def testsign(self):
#click loginbutton
log=TESTLOGIN(self.driver)
log.testloginbutton()
time.sleep(5)
log.testemail().sendkeys("hello")
当我运行主文件时,它显示进程以退出代码 0 完成, 因为它没有进入类或函数,我没有得到任何结果或浏览器调用或其他任何东西。
解决方案
您正在定义一个类和一个函数,但在我看来,您在主文件中没有使用任何东西,尝试为 testloginfunction 创建一个对象并使用该方法。
推荐阅读
- wordpress - Wordpress:两个日期之间的月份
- javascript - 影响活动类的延迟功能 - 一页滚动
- html - 在将元素重新引入流后转换它
- php - 表格标签内的 HTML 表单更改表格的格式
- kubernetes - 如何使用 Terraform 在 AWS EKS 上为 kubernetes 设置 letencrypt 证书颁发者
- macos - 根据文件类型编辑 .zshrc 以在 iterm2 中为 ls 输出着色
- php - @return int 总是返回字符串 php
- javascript - 如何将动态变量传递给 JS 中的函数?
- css - 有没有办法针对具有相同元素的多个类
- django - 在 Django 中参数化过滤管理器查询集