首页 > 解决方案 > 没有显示错误,但程序未在 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 完成, 因为它没有进入类或函数,我没有得到任何结果或浏览器调用或其他任何东西。

标签: pythonselenium

解决方案


您正在定义一个类和一个函数,但在我看来,您在主文件中没有使用任何东西,尝试为 testloginfunction 创建一个对象并使用该方法。


推荐阅读