赛普拉斯:检查列是否有正确的数据

发布于 2025-02-07 01:56:54 字数 7187 浏览 4 评论 0原文

我创建了测试用例,从表中获取所有信息,在此表中有用户。 姓名, 角色, 地位, 列出了最后一个活动状态,我根据用户的ID选择每一行,我之前从API中获取ID信息,我无法通过API主张它们,因为只有“ ID”,“电子邮件”和“ name”信息,其他信息不可用。 如何测试列角色,状态,最后一个活动状态具有正确的数据?事先感谢您的所有想法。

表的示例;
名称|电子邮件|角色|状态|最后一个活动
user00 | 医生|活动| 1小时前
user01 |
工程师|活动| 2分钟前
user02 |
医生|等待| 2个月前
user03 |
警察|不活动| 11天前*

子元素和[7]子元素不需要检查)

  <table>
     <tbody class="TableBody-root">
      <tr class="TableRow-root user_12341234blabla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user00</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Doctor</td>
       <td class"TableCell-root TableCell-body">Active</td>
       <td class"TableCell-root TableCell-body">1 hour ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>
      <tr class="TableRow-root user_42241234alsbla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user01</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Engineer</td>
       <td class"TableCell-root TableCell-body">Active</td>
       <td class"TableCell-root TableCell-body">2 minutes ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>
    <tr class="TableRow-root user_3554a234alsbla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user02</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Doctorr</td>
       <td class"TableCell-root TableCell-body">Pending</td>
       <td class"TableCell-root TableCell-body">2 months ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>
    <tr class="TableRow-root user_87941234sasbla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user03</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Police</td>
       <td class"TableCell-root TableCell-body">Inactive</td>
       <td class"TableCell-root TableCell-body">11 days ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>

   </tbody> 
</table>

html部分的示例([1 ] 代码;

  cy.wait("@getUsers") 
 
      .its("response.body")
      .its("user")
      .then(user => {
  

        for (let i = 0; i < user.length; i++) {
          for (let a = 2; a <= 6; a++) {
            cy.get(`.user_${user[i].id}>:nth-child(${a})`)
              .invoke("text")
              .then(userInfo => {
                expect(userInfo).to.equal() // here i stuck
              });
          }
        }
**Its response.body**

    user    [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
    0   Object { id: "user_12341234blabla", name: "user00", email: "[email protected]", … }
    1   Object { id: "user_42241234alsbla", name: "user01", email: "[email protected]", … }
    2   Object { id: "user_3554a234alsbla", name: "user02", email: "[email protected]", … }

    3   Object { id: "user_87941234sasbla", name: "user03", email: "[email protected]", … }
    
    **Under the object [0]**
    
    id  "12341234blabla"
    name    "user00"
    email   "[email protected]"
    locale  "en"
    receive_notifications   true
    current_sign_in_at  "2022-06-14T00:36:41.240+02:00"
    created_at  "2022-02-10T10:25:45.333+01:00"
    updated_at  "2022-06-14T00:36:41.240+02:00"
    unconfirmed_email   null
    pending_reconfirmation  false
    confirmation_sent_at    null
    confirmation_period_expired null
    is_invited  false  //if its true it means status is pending otherwise active or inactive 
    is_managed_externally   false
    roles_without_context   [ {…} ]
    resource_role_users [ {…} ]
    invitee_invitations []
    
    **Under roles_without_context [{...}]**
    
    0   Object { id: "0a79-43ee-ae43", 
    created_at: "2022-02-10T10:25:45.345+01:00", 
    updated_at: "2022-02-10T10:25:45.345+01:00", … }
    id  "0a79-43ee-ae43"
    context_type    null
    context_id  null
    role    null
    created_at  "2022-02-10T10:25:45.345+01:00"
    updated_at  "2022-02-10T10:25:45.345+01:00"
    locked  true
    name    "Doctor"   //it shows role 
    clm_name    null
    client_id   "8506-d772d917af86"

I have created test case that gets all informations from table, in this table there is Users;
Name,
Role,
Status,
Last active statuses are listed, I select each line according to the user's id, I get the id information from the API before, I cannot assert them through the API because there are only "id","email" and " name" information, other information is not available.
How can I test that columns Role,Status, Last active status has the correct data? Thanks in advance for all the ideas.

Example of table;
Name |Email | Roles | Status | Last active
user00 |[email protected] | Doctor | Active | 1 hour ago
user01 |[email protected] | Engineer | Active |2 minutes ago
user02 |[email protected] | Doctor | Pending | 2 months ago
user03 |[email protected] | Police |Inactive | 11 days ago*

Example of html part ( [1]child element and [7] child element are not necessary to check)

  <table>
     <tbody class="TableBody-root">
      <tr class="TableRow-root user_12341234blabla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user00</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Doctor</td>
       <td class"TableCell-root TableCell-body">Active</td>
       <td class"TableCell-root TableCell-body">1 hour ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>
      <tr class="TableRow-root user_42241234alsbla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user01</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Engineer</td>
       <td class"TableCell-root TableCell-body">Active</td>
       <td class"TableCell-root TableCell-body">2 minutes ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>
    <tr class="TableRow-root user_3554a234alsbla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user02</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Doctorr</td>
       <td class"TableCell-root TableCell-body">Pending</td>
       <td class"TableCell-root TableCell-body">2 months ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>
    <tr class="TableRow-root user_87941234sasbla">
       <td class"TableCell-root TableCell-body width">
       <td class"TableCell-root TableCell-body">user03</td>
       <td class"TableCell-root TableCell-body">[email protected]</td>
       <td class"TableCell-root TableCell-body">Police</td>
       <td class"TableCell-root TableCell-body">Inactive</td>
       <td class"TableCell-root TableCell-body">11 days ago</td>
       <td class"TableCell-root TableCell-body stngs">
      </tr>

   </tbody> 
</table>

And this is my code;

  cy.wait("@getUsers") 
 
      .its("response.body")
      .its("user")
      .then(user => {
  

        for (let i = 0; i < user.length; i++) {
          for (let a = 2; a <= 6; a++) {
            cy.get(`.user_${user[i].id}>:nth-child(${a})`)
              .invoke("text")
              .then(userInfo => {
                expect(userInfo).to.equal() // here i stuck
              });
          }
        }
**Its response.body**

    user    [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
    0   Object { id: "user_12341234blabla", name: "user00", email: "[email protected]", … }
    1   Object { id: "user_42241234alsbla", name: "user01", email: "[email protected]", … }
    2   Object { id: "user_3554a234alsbla", name: "user02", email: "[email protected]", … }

    3   Object { id: "user_87941234sasbla", name: "user03", email: "[email protected]", … }
    
    **Under the object [0]**
    
    id  "12341234blabla"
    name    "user00"
    email   "[email protected]"
    locale  "en"
    receive_notifications   true
    current_sign_in_at  "2022-06-14T00:36:41.240+02:00"
    created_at  "2022-02-10T10:25:45.333+01:00"
    updated_at  "2022-06-14T00:36:41.240+02:00"
    unconfirmed_email   null
    pending_reconfirmation  false
    confirmation_sent_at    null
    confirmation_period_expired null
    is_invited  false  //if its true it means status is pending otherwise active or inactive 
    is_managed_externally   false
    roles_without_context   [ {…} ]
    resource_role_users [ {…} ]
    invitee_invitations []
    
    **Under roles_without_context [{...}]**
    
    0   Object { id: "0a79-43ee-ae43", 
    created_at: "2022-02-10T10:25:45.345+01:00", 
    updated_at: "2022-02-10T10:25:45.345+01:00", … }
    id  "0a79-43ee-ae43"
    context_type    null
    context_id  null
    role    null
    created_at  "2022-02-10T10:25:45.345+01:00"
    updated_at  "2022-02-10T10:25:45.345+01:00"
    locked  true
    name    "Doctor"   //it shows role 
    clm_name    null
    client_id   "8506-d772d917af86"

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

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

发布评论

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

评论(1

清引 2025-02-14 01:56:54

您是否需要在用户对象上进行比较的值?

使用console.log(user)检查

[
  {
    id: "user00",
    email: "[email protected]",
    roles_without_context: {
      name: "Doctor"
    }
    status: "Active",
    lastSeen: "1 hour ago"
  },
  {
    id: "user01",
  ...
]

一下

const thisUser = user[i]

if (a === 2) {
  expect(userInfo).to.equal(thisUser.email)
} 
if (a === 3) {
  const role = user.roles_without_context.name
  expect(userInfo).to.equal(role)
} 
if (a === 4) {
  const status = thisUser.pending_reconfirmation ? 'Pending' : 'Active';
  expect(userInfo).to.equal(status)
} 
if (a === 5) {
  const lastSeen = thisUser.??? // what field is this
  expect(userInfo).to.equal(lastSeen)
} 

Are the values you need to compare on the user object?

Check it out with console.log(user), for example if user looks like

[
  {
    id: "user00",
    email: "[email protected]",
    roles_without_context: {
      name: "Doctor"
    }
    status: "Active",
    lastSeen: "1 hour ago"
  },
  {
    id: "user01",
  ...
]

then in the test (roughly)

const thisUser = user[i]

if (a === 2) {
  expect(userInfo).to.equal(thisUser.email)
} 
if (a === 3) {
  const role = user.roles_without_context.name
  expect(userInfo).to.equal(role)
} 
if (a === 4) {
  const status = thisUser.pending_reconfirmation ? 'Pending' : 'Active';
  expect(userInfo).to.equal(status)
} 
if (a === 5) {
  const lastSeen = thisUser.??? // what field is this
  expect(userInfo).to.equal(lastSeen)
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文