在 selenium pytest 中找不到固定装置“名字”

问题描述 投票:0回答:0

错误是

错误[100%] 测试设置失败 文件 E:\Python-Selenium opCommerce_SQA estcases est_placeOrder.py,第 16 行 @data(*utils().read_data_from_csv("E:\Python-Selenium opCommerce_SQA estdata datacsv.csv")) @解包 def testPlaceOrder(自我、名字、姓氏、电子邮件、国家、城市、地址、邮政编码、电话): 未找到 E 装置“名字”

  available fixtures: _session_faker, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, extra, faker, include_metadata_in_junit_xml, metadata, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, setup, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
  use 'pytest --fixtures [testpath]' for help on them.

这是我的测试用例代码:

import time
import pytest
from pages.account_page import AccountPage
from pages.add_to_cart_page import AddCartPage
from pages.billing_page import BillingPage
from pages.cell_phones_page import CellPhonePage
from pages.shopping_cart_page import ShoppingCartPage
from utilities.utils import utils
from ddt import ddt, data, unpack


@pytest.mark.usefixtures("setup")
@ddt
class TestPlaceOrder:
# @data(*utils().read_data_from_excel("E:\\Python-       Selenium\\nopCommerce_SQA\\testdata\\tdataexcel.xlsx","Sheet2"))
@data(*utils().read_data_from_csv("E:\\Python-Selenium\\nopCommerce_SQA\\testdata\\tdatacsv.csv"))
@unpack
def testPlaceOrder(self, firstname, lastname, email, country, city, address, zip, phone):
    ap=AccountPage(self.driver)
    ap.mouseHoverOnElectronicsAndClickCellPhone()
    cpp=CellPhonePage(self.driver)
    cpp.clickNokiaLumia()
    acp=AddCartPage(self.driver)
    acp.addToCart(2)
    scp=ShoppingCartPage(self.driver)
    scp.clickTearmsCheckboxAndCheckOutButton()
    scp.clickCheckoutAsGuestButton()
    bp=BillingPage(self.driver)
    bp.enterBillingAddress(firstname, lastname, email, country, city, address, zip, phone)
    time.sleep(3)

这是我的账单页面代码:

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from base.base_driver import BaseDriver
from selenium.webdriver.support.select import Select


class BillingPage(BaseDriver):
def __init__(self, driver):
    super().__init__(driver)
    self.driver = driver
firstName="//input[@id='BillingNewAddress_FirstName']"
lastName="//input[@id='BillingNewAddress_LastName']"
email="//input[@id='BillingNewAddress_Email']"
country="//select[@id='BillingNewAddress_CountryId']"
city="//input[@id='BillingNewAddress_City']"
address_id="BillingNewAddress_Address1"
zip="//input[@id='BillingNewAddress_ZipPostalCode']"
phone="//input[@id='BillingNewAddress_PhoneNumber']"
continue_button="//button[@onclick='Billing.save()']"
def getFirstName(self):
    return self.wait_elements_clickable(By.XPATH,self.firstName)
def getLastName(self):
    return self.wait_elements_clickable(By.XPATH,self.lastName)
def getEmail(self):
    return self.wait_elements_clickable(By.XPATH,self.email)
def getCountry(self):
    return self.wait_element_located(By.XPATH,self.country)
def getCity(self):
    return self.wait_elements_clickable(By.XPATH,self.city)
def getAddress(self):
    return self.wait_elements_clickable(By.ID,self.address_id)
def getZip(self):
    return self.wait_elements_clickable(By.XPATH,self.zip)
def getPhone(self):
    return self.wait_elements_clickable(By.XPATH,self.phone)
def getContinueButton(self):
    return self.wait_elements_clickable(By.XPATH,self.continue_button)

def enterFirstName(self,firstname):
    self.getFirstName().send_keys(firstname)
def enterLastName(self,lastname):
    self.getLastName().send_keys(lastname)
def enterEmail(self,email):
    self.getEmail().send_keys(email)
def selectCountry(self,country):
    countryName=Select(self.getCountry())
    countryName.select_by_visible_text(country)
def enterCity(self,city):
    self.getCity().send_keys(city)
def enterAddress(self,address):
    self.getAddress().send_keys(address)
def enterZip(self,zip):
    self.getZip().send_keys(zip)
def enterPhone(self,phone):
    self.getPhone().send_keys(phone)
def clickContinueButton(self):
    self.getContinueButton().click()
def enterBillingAddress(self,firstname,lastname,email,country,city,address,zip,phone):
    self.enterFirstName(firstname)
    self.enterLastName(lastname)
    self.enterEmail(email)
    self.selectCountry(country)
    self.enterCity(city)
    self.enterAddress(address)
    self.enterZip(zip)
    self.enterPhone(phone)
    self.clickContinueButton()

这是我的实用程序代码

import softest
from openpyxl import Workbook, load_workbook
import csv
class utils():
def assertText(self,screenText,value):
    if screenText == value:
        assert screenText == value
        print("test passed")
    else:
        print("test failed")


def read_data_from_excel(self,filename,sheetname):
    datalist=[]
    wb= load_workbook(filename=filename)
    sh=wb[sheetname]
    row_ct=sh.max_row
    col_ct=sh.max_column
    for i in range(2,row_ct+1):
        row=[]
        for j in range(1,col_ct+1):
            row.append(sh.cell(row=i,column=j).value)
        datalist.append(tuple(row))
    return datalist
def read_data_from_csv(self,filename):
    datalist=[]
    csvdata=open(filename,"r")
    reader=csv.reader(csvdata)
    next(reader)
    for rows in reader:
        datalist.append(rows)
    return datalist

这是比赛

import pytest
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

@pytest.fixture(scope="class")
def setup(request):
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
driver.get("https://demo.nopcommerce.com/")
driver.maximize_window()
request.cls.driver = driver
yield
driver.quit()

我之前做了另一个项目,但工作正常,然后也工作正常,但现在在进行一些更改并向项目添加更多页面后突然显示错误。我该如何解决这个问题?不管我做什么,班级的论点可能会被认为是固定的?解决办法是什么?

我更改了参数,更改了名称等,但没有什么可以解决这个问题,因为我有另一个测试用例,效果很好:

import pytest
import time
import softest
from pages.launch_page import launchPage
from pages.search_results_page import searchFlightResult
from utilities.utils import utils
from ddt import ddt, data, unpack

@pytest.mark.usefixtures("setup")
@ddt
class TestSearchAndVerifyFilter(softest.TestCase):
@data(*utils().read_data_from_excel("E:\\Python-Selenium\\TestFrameWorkDemo\\testdata\\tdataexcel.xlsx","Sheet1"))
@unpack
def testSearchFlights(self,going_from,going_to,depart_date,stops):
    lp=launchPage(self.driver)
    lp.searchFlights(going_from,going_to,depart_date)
    time.sleep(3)
    sf=searchFlightResult(self.driver)
    sf.filter_flights_by_stop(stops)
    allstops=sf.getSearchFlightResult()
    time.sleep(3)
    print("")
    print(len(allstops))
    ut=utils()
    ut.assertListText(allstops,stops)
selenium-webdriver pytest fixtures unpack ddt
© www.soinside.com 2019 - 2024. All rights reserved.