简体   繁体   中英

Getting error : Promise rejected with no or falsy reason in mocha selenium node js

I am doing unit test with selenium mocha with node js, i am new in that, I want to test with rejection promise, but it is giving me this error: Promise rejected with no or falsy reason , can anyone please look my code and help me to resolve this issue, here i have pasted my whole code

it('Login', async function () {
    this.timeout(200000);
    return new Promise(async function (resolve, reject) {
      driver = await new Builder().forBrowser('firefox')
        .setFirefoxOptions(new firefox.Options().windowSize(screen))
        .build();
      driver.get('http://localhost:4200/login');
      await driver.findElement(By.id('mat-input-0')).sendKeys('root_admin');
      await driver.findElement(By.id('mat-input-1')).sendKeys('Admin123');
      await driver.sleep(5000);
      const button = await driver.findElement(By.className('mt-3'));
      await button.click();
      await driver.sleep(2000);
      await driver.quit();
      let text = "sdsdsds"
      if (text == "Invalid email or password") {
        resolve(true);
      } else {
        reject();
      }
    });
  });

The reason that you are receiving this error message is that you are not putting any arguments into reject() .

If you change that to eg reject(new Error('text does not match \"Invalid email or password\"')); you should see that error message instead.

The issue is that Mocha doesn't support asynchronous functions.

Try just returning the Promise (as you're already doing) but remove the async keyword from the enclosing function. Mocha will detect that it's a Promise and handle it accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM