Entonces, todo lo que quiero hacer es automatizar un inicio de sesión a través de WebdriverIO.
Esta es la clase LoginPage donde ocurre el error, función de inicio de sesión - "elemento no interactuable"
class LoginPage { get inputUsername() { const username = $("#username"); username.waitForClickable(); return username; } get inputPassword() { const password = $("#current-password"); password.waitForClickable(); return password; } get btnSubmit() { const submitButton = $(".button.button--primary.button--l"); submitButton.waitForClickable(); return submitButton; } async login(username, password) { await this.inputUsername.setValue(username); //<--Throws error await this.inputPassword.setValue(password); //<--Throws error await this.btnSubmit.click(); //<--Not sure if throws error } }Los parámetros de la función de inicio de sesión provienen de su llamada en el archivo de prueba.
describe("login", () => { it("should successfully login", async () => { await browser.maximizeWindow(); await LoginPage.open(); //<--Opens the login page on the browser await LoginPage.login( "emailtest@test.com", process.env.PASSWORD ); await expect(browser).toHaveUrl(process.env.CLIENT_AREA_URL); } }Creo que estoy usando mocha para la estructura de la prueba y para los reporteros (spec y allure), corrígeme si me equivoco en algo.
Soy un poco nuevo en las pruebas web automatizadas, ¿alguien puede ayudarme con esto?
Parece que waitForClickable no funciona en este caso. ¿Podría moverlo a la función asíncrona?
Basado en su código:
get inputUsername() { return $("#username"); } async login(username, password) { await this.inputUsername.waitForClickable(); await this.inputUsername.setValue(username); ... } wait... y set... se pueden mover a browser.addCommand() en wdio.conf para tener un código más limpio.
Prueba esto:
class LoginPage { get inputUsername() { return $("#username"); get inputPassword() {return $("#current-password"); get btnSubmit() {return $(".button.button--primary.button--l"); async login(username, password) { await this.inputUsername.waitForClickable(); await this.inputUsername.setValue(username); await this.password.waitForClickable(); await this.inputPassword.setValue(password); await this.submitButton.waitForClickable(); await this.submitButton.click(); } }Recomendaría escribir incluso un método para completar la entrada:
async fillLoginName(loginname){ await this.inputUsername.waitForExist(); await this.inputUsername.clearValue(); await this.inputUsername.setValue(loginname);}
y llamaste solo en tu prueba como:
it("should successfully login", async () => { await Loginpage.fillLoginName("emailtest@test.com"); // do the rest for password field and click login button )}Hay un par de cosas que podrían estar causando esto:
username.waitForClickable(); llamadas, pero creo que es posible que deban await username.waitForClickable(); trabajar.