赛普拉斯 - 带有页面对象的链方法返回

发布于 2025-01-31 13:24:20 字数 680 浏览 1 评论 0原文

我用某些链条方法实现了页面对象。

页面看起来像这样

class Table {
    getTable() {
       return cy.get('table#tblItem');
    }

    getListRow() {
       return this.getTable()
           .within(($tbl) => {
               cy.get('tbody').scrollTo('bottom', { ensureScrollable: false, duration: 1000 });
               return cy.wrap($tbl).find('tbody#itemBody tr');
        });
   }
}

,在柏树规范文件中,我确实断言要验证行列表是否具有项目,

Table.getListRow()
     .then((lstRowItem) => {
           expect(lstRowItem).have.length.greaterThan(1);
     })

但我总是得到方法'getTable()''而不是'getlistrow()'的结果。该测试失败了,因为它获得了表的值1。

如何获得此链方法的正确回报。

谢谢

I implemented page objects with some chain methods.

Page looks like this

class Table {
    getTable() {
       return cy.get('table#tblItem');
    }

    getListRow() {
       return this.getTable()
           .within(($tbl) => {
               cy.get('tbody').scrollTo('bottom', { ensureScrollable: false, duration: 1000 });
               return cy.wrap($tbl).find('tbody#itemBody tr');
        });
   }
}

And in cypress spec file, I do assertion to verify if the row list has items

Table.getListRow()
     .then((lstRowItem) => {
           expect(lstRowItem).have.length.greaterThan(1);
     })

But I always get the result of method 'getTable()', not 'getListRow()'. The test failed because it gets value 1 of the table.

How can I get correct return of this chain method.

Thank you

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥繁 2025-02-07 13:24:20

.within()命令将不允许返回内部值。

使用

getListRow() {
  return this.getTable()
    .then($tbl => {
      return cy.wrap($tbl).find('tbody')
        .scrollTo('bottom', { ensureScrollable: false, duration: 1000 })
        .then(() => {
          return cy.wrap($tbl).find('tbody#itemBody tr');
        });
   })

参考:

.within()产生的主题与以前的命令给出了相同的主题。

The .within() command will not permit returning of the inner value.

Use a .then() and .find() instead.

getListRow() {
  return this.getTable()
    .then($tbl => {
      return cy.wrap($tbl).find('tbody')
        .scrollTo('bottom', { ensureScrollable: false, duration: 1000 })
        .then(() => {
          return cy.wrap($tbl).find('tbody#itemBody tr');
        });
   })

Ref: .within()

.within() yields the same subject it was given from the previous command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文