jeudi 18 juillet 2019

Else statement not executing? Want to pass test if error not found

I'm writing an automated test that changes the user password. This function detects if there is an error logging in and will use the opposite password. Problem is, the test doesn't continue if no error as else statement won't execute and I don't understand why.

I've tried return true, null and nothing at all.

async setBackupPassword (password) { // Password to sign in with if current one is wrong (Security test)
        try {
            if (await this.driver.wait(until.elementLocated(By.xpath("//*[contains(text(), 'Invalid Credentials')]")), this.threeSecondsWait)) {
                await this.setPassword(password);
                await this.clickSignInButton();
            } else {
              return true;
            }
        } catch (error) {
            await this.logFailure();
            assert.fail("Unable to set Password");
        }
    }

If the error message doesn't appear, I just want the test to continue but the else statement won't execute at all.

Aucun commentaire:

Enregistrer un commentaire