如何在柏树中获取条件行元素

How to get conditional row element in cypress

我正在用 cypress 测试我的应用程序。例如,我的 Table.

中有 4 个值

在这种情况下,我想获取具有特定值的行 cypress-farm,然后我想获取具有 cypress-farm 的那一行的 id 列,但是 cypress 获取我 [= 中的每个 id 列21=]。有人可以告诉我怎么做吗?我想念什么 本例中的“选择器”值是 id 列 我的问题是上面几行的部分 cy.request

public static addproductToFarm(selector:string, productName:string) {
        cy.get(".list").then(($temp1) =>{
            cy.get(".list")
                .contains("cypress-farm")
                .get(selector).then(($temp)=>{
                const txt = $temp.text()

                cy.request({
                    url: Cypress.env("api_server") + "products/",
                    method: 'POST',
                    form: false,
                    headers: {
                        'Content-Type': 'application/json; charset=utf-8',
                    },
                    body: {
                        availability: true,
                        category: {
                            hasOthers: false,
                            id: 1,
                            indexRanking: 0,
                            name: "Obst",
                            shown: true,
                            subCategories: [
                                null
                            ]
                        },
                        delivery: true,
                        description: productName,
                        descriptionExcerpt: "Cypress Product",
                        farmId: txt,
                        name: "Apple by Postman",
                        pickUp: true,
                        price: 10.00,
                        quantity: 10,
                        storageLimit: 10,
                        unit: "kg",
                        visibility: true
                    }


                })

            })
        } )

        return this;

    }

我想你可能想要 .find(selector) 而不是 .get(selector)

get()从文档开始,但是find()从上一个主题开始(.contains("cypress-farm")的结果)。

Get vs Find

The cy.get command always starts its search from the cy.root element. In most cases, it is the document element, unless used inside the .within() command. The .find command starts its search from the current subject.