0

我有一个要求,我需要将用户电子邮件存储到一个变量中,然后需要使用相同的电子邮件在 cypress 的另一种方法中搜索使用相同电子邮件创建的用户我该怎么做?

下面是我的方法

class UserManager {
    CreatePrimaryuser() {
        const button = cy.get(':nth-child(2) > a > h3')
        button.click()
        const button1 = cy.get('.btn-edit-user-view')
        button1.click()
        const uemail = cy.get('#emailField')
        var currentDate = new Date();
       var currentTime = currentDate.getTime();
       var commentText = 'Automation' + currentTime + '@email.com';
        uemail.type(commentText)
}
SearchUser() {
        cy.get('#searchUsers').click().type(commentText)

    }

我想在存储在 CreatePrimaryuser 方法中的 searchuser 方法中使用相同的 commontext 值

4

2 回答 2

3

您也可以将其保存在环境变量中。

class UserManager {
  CreatePrimaryuser() {
    const button = cy.get(':nth-child(2) > a > h3')
    button.click()
    const button1 = cy.get('.btn-edit-user-view')
    button1.click()
    const uemail = cy.get('#emailField')
    var currentDate = new Date();
    var currentTime = currentDate.getTime();
    var commentText = 'Automation' + currentTime + '@email.com';
    uemail.type(commentText)
    Cypress.env('commentText', commentText);
  }

  SearchUser() {
    cy.get('#searchUsers').click().type(Cypress.env('commentText'));
  }
}
于 2021-09-24T07:10:10.730 回答
1

您可以将值存储在一个字段中:

class UserManager {
  commentText
  
  constructor() {
    var currentDate = new Date();
    var currentTime = currentDate.getTime();
    this.commentText = 'Automation' + currentTime + '@email.com';
  }

  CreatePrimaryuser() {
    const button = cy.get(':nth-child(2) > a > h3')
    button.click()
    const button1 = cy.get('.btn-edit-user-view')
    button1.click()
    const uemail = cy.get('#emailField')
    
    uemail.type(this.commentText)
  }

  SearchUser() {
    cy.get('#searchUsers').click().type(this.commentText)

  }
}
于 2021-09-23T14:07:38.997 回答