简体   繁体   English

使用 Cypress.Promise 在测试中获取列表值以进行比较和搜索

[英]Using Cypress.Promise to get list values in test for comparisons and searches

My question I know ahead of time may not be a " best practice " but I promise you I won't understand the "best practice" until I can implement the question at hand and then understand why it is inefficient.我提前知道的问题可能不是“ best practice ”,但我 promise 你我不会理解“最佳实践”,直到我可以实施手头的问题然后理解它为什么效率低下。

I work with react tables and I'm trying to create helper functions based on Cypress.Promise.我使用反应表,我正在尝试基于 Cypress.Promise 创建辅助函数。 I've done so in the past at a previous job but I never internalized the logic behind Promises and consequentially forgot how to get values, pull strings and then return the list to a variable for the rest of the tests.我过去在之前的工作中这样做过,但我从未内化 Promises 背后的逻辑,因此忘记了如何获取值、拉字符串,然后将列表返回给测试的 rest 的变量。 And while it sounds simple to describe I'm having a difficult/frustrating time remembering how to implement it.虽然描述起来听起来很简单,但我很难/令人沮丧地记住如何实现它。

  1. From there the plan would be to sort the list (asc & desc) via UI & confirm with Cypress.从那里开始,计划是通过 UI 对列表进行排序(asc 和 desc)并与 Cypress 确认。
  2. Search a random name in the list and validate it's the only value in the list在列表中搜索一个随机名称并验证它是列表中的唯一值
  3. I forgot...我忘了...

But I just need a function that like let table_strings = CyPromiseFunction("table_element")但我只需要一个 function 就像 let table_strings = CyPromiseFunction("table_element")

That returns a list like ["Slack","Meet","Hangouts","Messenger","Teams"]这会返回一个类似["Slack","Meet","Hangouts","Messenger","Teams"]的列表

That I can filter & search off of.我可以过滤和搜索。

It's not super clear what it is you're trying to achieve, but it sounds like you want to grab table data and use that data to validate against filtering, sorting, etc. If this is not the case, please update your answer to be more specific.目前尚不清楚您要实现什么目标,但听起来您想获取表数据并使用该数据来验证过滤、排序等。如果不是这种情况,请将您的答案更新为更详细。

If this is what you are trying to do, then I am not sure why you need to use Cypress.Promise to achieve this.如果这是你想要做的,那么我不确定你为什么需要使用Cypress.Promise来实现这一点。

If your React table uses tbody/theader/tr/td type structure, you could probably use the Cypress-Get-Table plugin to grab your table data.如果你的 React 表使用tbody/theader/tr/td类型的结构,你可以使用Cypress-Get-Table插件来获取你的表数据。 If nothing else, reviewing the source code could help put you on the right track.如果不出意外,查看源代码可以帮助您走上正轨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM