是否有任何方法可以一一以输入表单以输入表单输入列表值?

发布于 2025-02-08 04:31:55 字数 3327 浏览 0 评论 0原文

面临的问题: - 我有一个页面,必须通过阅读Excel输入数据并单击一些BTN。为了实现这一目标,我创建了一个Excel Reader,该读取器获取数据并在列表中获取(如果Excel具有多个数据集,则嵌套列表)。如果Excel有单个数据集,那么我的脚本工作正常,但是如果有多个集合,则脚本的行为不如预期。它迭代第一个列表值并执行一些操作并关闭浏览器,然后再次启动浏览器并执行相同的操作,而我不想要。我想要如果Excel Reader返回嵌套列表,那么我的脚本应重复执行一组操作,直到最后一个列表值。 以下是步骤详细信息。

我正在使用“ OpenPyXl”

step1读取来自Excel的数据: - 这是我的“ Excel Reader”实用程序: -

def fetchTestDataRowWise(worksheet_name, rowStartIndexDataStartReading, colFromWhereDataStartReading):
dataFilePath = "..//..//TestData1.xlsx"
workbook = openpyxl.load_workbook(dataFilePath)
worksheet = workbook[worksheet_name]
rows = worksheet.max_row
cols = worksheet.max_column
# print(f"Total number of rows {rows} and Total Number of columns are {cols}")
dataList = []
for i in range(rowStartIndexDataStartReading, rows + 1):
    tempDataList = []
    for j in range(colFromWhereDataStartReading, cols + 1):
        data1 = worksheet.cell(i, j)
        data2 = data1.value
        if data2 is not None:
            tempDataList.append(data2)
    dataList.insert(i, tempDataList)
return dataList

步骤2 这是我的Excel数据: - 在此处输入图像描述

步骤3: - Excel Reader返回列表为: - [['840-9754',28],['840-9755',29],['840-9756',30]]

步骤4: - 屏幕截图是我的输入表单,在此输入表格中,我必须输入诸如首先输入项目NBR = 840-9754之类的值,然后item QTY = 28,然后单击“添加SKU” BTN重复此步骤以获取下一个列表,然后完成所有列表。项目单击“完整” BTN。 [在这里输入图像描述] [2]

在此处输入图像描述

这是我的conftest.py

@pytest.fixture(scope="function")
def setup(request):
    driver = webdriver.Chrome()
    driver.get(ConfigReader.readconfigdata('Details', 'app_url'))
    driver.maximize_window()
    request.cls.driver = driver
    yield
    driver.close()

步骤6: - 这是我上述字段的“动作”方法

    def enterItemNbr(self, enterSKU):
    itemNbr = self.driver.find_element(By.XPATH, ConfigReader.readlocator('locators', 'itemNbrInputBox'))
    itemNbr.click()
    itemNbr.send_keys(enterSKU)

def enterItemQty(self, qty):
    itemQTY = self.driver.find_element(By.XPATH, ConfigReader.readlocator('locators', 'itemQtyInputBox'))
    itemQTY.click()
    itemQTY.clear()
    itemQTY.send_keys(qty)

def clickAddSKU(self):
    addSKUBtn = self.driver.find_element(By.XPATH, ConfigReader.readlocator('locators', 'addSKUBtn'))
    addSKUBtn.click()

def AddSKU(self, enterSKU, enterQty):
    self.enterItemNbr(enterSKU)
    self.enterItemQty(enterQty)
    self.clickAddSKU()

步骤7: - 这是我的测试案例

类TestmaterialialialialialialialialialialperperformcyClecount (Baseclass):

@pytest.mark.parametrize('data', BaseClass.fetchTestDataRowWise("CycleCountTestData", 2, 1))
def test_PerformCycleCount(self, data):
    userLogin = Login(self.driver)
    userLogin.login()

    performCycleCount = MaterialPerformCycleCount(self.driver)
    performCycleCount.enterItemNbr(data[1])
    time.sleep(2)
    performCycleCount.enterItemQty(int(data[2]))
    time.sleep(2)
    performCycleCount.clickAddSKUbtn()

注意: - 如果我更改了固定范围,那么我将无法实现其他测试用例的目标。

Problem Facing:- I have a page in which i have to input the data by reading excel and click on some btn. To achieve this i created a excel reader which fetch the data and strore in a list (Nested list if excel has multiple data set). If excel have single data set then my script is working fine but in case there is multiple set then scripts not behaving as expected. it iterating the first list values and perform some actions and close the browser and again launching the browser and doing the same stuff, which i don't want. I wants if excel reader return nested list then my script should perform set of actions repetively till last list values.
below are the step details.

I am reading data from excel using 'openpyxl'

Step1 :- Here is my 'excel reader' Utility:-

def fetchTestDataRowWise(worksheet_name, rowStartIndexDataStartReading, colFromWhereDataStartReading):
dataFilePath = "..//..//TestData1.xlsx"
workbook = openpyxl.load_workbook(dataFilePath)
worksheet = workbook[worksheet_name]
rows = worksheet.max_row
cols = worksheet.max_column
# print(f"Total number of rows {rows} and Total Number of columns are {cols}")
dataList = []
for i in range(rowStartIndexDataStartReading, rows + 1):
    tempDataList = []
    for j in range(colFromWhereDataStartReading, cols + 1):
        data1 = worksheet.cell(i, j)
        data2 = data1.value
        if data2 is not None:
            tempDataList.append(data2)
    dataList.insert(i, tempDataList)
return dataList

Step 2 Here is my Excel Data:-
enter image description here

Step 3:-
Excel reader returning list as :- [['840-9754', 28], ['840-9755', 29], ['840-9756', 30]]

Step 4:- Attached screenshot is my input form, in this input form i have to enter the values like first enter Item Nbr=840-9754 then Item Qty=28 and then Click on 'Add Sku' btn repeat this step for next list and after completing all list items click on 'Complete' btn.
[enter image description here][2]

enter image description here

Step 5:- Here is my Conftest.py

@pytest.fixture(scope="function")
def setup(request):
    driver = webdriver.Chrome()
    driver.get(ConfigReader.readconfigdata('Details', 'app_url'))
    driver.maximize_window()
    request.cls.driver = driver
    yield
    driver.close()

Step 6:- this is my 'action' methods for above mentioned fields

    def enterItemNbr(self, enterSKU):
    itemNbr = self.driver.find_element(By.XPATH, ConfigReader.readlocator('locators', 'itemNbrInputBox'))
    itemNbr.click()
    itemNbr.send_keys(enterSKU)

def enterItemQty(self, qty):
    itemQTY = self.driver.find_element(By.XPATH, ConfigReader.readlocator('locators', 'itemQtyInputBox'))
    itemQTY.click()
    itemQTY.clear()
    itemQTY.send_keys(qty)

def clickAddSKU(self):
    addSKUBtn = self.driver.find_element(By.XPATH, ConfigReader.readlocator('locators', 'addSKUBtn'))
    addSKUBtn.click()

def AddSKU(self, enterSKU, enterQty):
    self.enterItemNbr(enterSKU)
    self.enterItemQty(enterQty)
    self.clickAddSKU()

Step 7:- Here is my Test Case

class TestMaterialPerformCycleCount(BaseClass):

@pytest.mark.parametrize('data', BaseClass.fetchTestDataRowWise("CycleCountTestData", 2, 1))
def test_PerformCycleCount(self, data):
    userLogin = Login(self.driver)
    userLogin.login()

    performCycleCount = MaterialPerformCycleCount(self.driver)
    performCycleCount.enterItemNbr(data[1])
    time.sleep(2)
    performCycleCount.enterItemQty(int(data[2]))
    time.sleep(2)
    performCycleCount.clickAddSKUbtn()

Note:- if i change the fixture scope then i am not achieving the objective for other test cases.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文