从支持文件夹cypress加载函数

从支持文件夹cypress加载函数,cypress,end-to-end,Cypress,End To End,在我的支持文件夹中,我有一个名为action的文件夹。其中有一个名为login-action.js的文件。此文件中的代码如下所示: class LoginActions{ login(usernameField, passwordField, username, password) { cy.get(usernameField).first().type(username); cy.get(passwordField).last().type(pa

在我的支持文件夹中,我有一个名为action的文件夹。其中有一个名为login-action.js的文件。此文件中的代码如下所示:

class LoginActions{   
     login(usernameField, passwordField, username, password) {
        cy.get(usernameField).first().type(username);
        cy.get(passwordField).last().type(password);
     }
    }
    export default new LoginActions();
 export default LoginActions();
import LoginActions from '../../../support/pageObjects/{loginActionsPage}'
const loginActions = new LoginActions();
现在我想在测试中使用这个登录函数

loginActions.login('[data-test=username]', '[data-test=password]', this.user.username, this.user.password);

这就是我在测试中所说的。但不知何故,这是行不通的。它说登录是未定义的。

我不认为您可以像现在这样导出新对象,我通常只导出这样的类:

class LoginActions{   
     login(usernameField, passwordField, username, password) {
        cy.get(usernameField).first().type(username);
        cy.get(passwordField).last().type(password);
     }
    }
    export default new LoginActions();
 export default LoginActions();
import LoginActions from '../../../support/pageObjects/{loginActionsPage}'
const loginActions = new LoginActions();
是否导入并创建新的对象登录,如下所示:

class LoginActions{   
     login(usernameField, passwordField, username, password) {
        cy.get(usernameField).first().type(username);
        cy.get(passwordField).last().type(password);
     }
    }
    export default new LoginActions();
 export default LoginActions();
import LoginActions from '../../../support/pageObjects/{loginActionsPage}'
const loginActions = new LoginActions();
在此之后,您可以:

loginActions.login('[data-test=username]', '[data-test=password]', this.user.username, this.user.password);

现在它说没有构造函数。在我的LoginActions类中是否需要构造函数,以及如何做到这一点。我想我从来没有在JavaScript/Cypress中创建过构造函数,只需在login-action.js中的类LoginActions之前添加“export”