Error: DeprecationWarning: Unhandled promise rejections are deprecated. - Promises in Javascript with Selenium

Error: DeprecationWarning: Unhandled promise rejections are deprecated. - Promises in Javascript with Selenium

我正在尝试在 Javascript 中使用 Selenium 设置一些测试用例以进行简单的登录页面测试。我正试图通过在 Promise 中拒绝来设置正确的错误捕获。这是我的承诺代码:

//Test Case 1: Valid Email / Valid Password
async function tc1() {
    announceTC();
    //Create promise to handle execution of async test case
    let promise = new Promise(async function (resolve, reject) {
        //Create the webdriver (Chrome) and open an instance of the test page
        const driver = createDriver();

        //Enter valid email / valid password
        await validEmail(driver, reject);
        await validPassword(driver);

        //Click login button
        await clickLoginButton(driver);

        //Test for a successful login
        await testSuccessfulLogin(driver, resolve, reject);

        //Exit the driver instance.
        await driver.quit();

        //Trigger the callback functions
        promise
            .then(value => console.log(value),
                value => console.log(value))
            .catch(value => console.log(value))
            .finally(() => tc2());
    });
};

在我的 validEmail 函数中,如果发生错误,我会尝试拒绝。这是我对该功能的代码:

//Find and enter valid email on login page
async function validEmail(driver, reject) {
    try{
        //Click email input box.
        let emailBox = await driver.wait(until.elementLocated(By.xpath("//*[@id='email']/iput")), 5000);
        await emailBox.click();

        //Input email.
        driver.findElement(By.xpath("//*[@id='email']/input")).sendKeys("redacted@gmail.com");
    } catch(error) {
        console.log(error);
        reject(tcErrorMsg());
    }
}

我对这个错误的理解是,当您没有提供承诺来处理被拒绝的案例时,它就会发生。

我的 testSuccessfulLogin 函数使用 resolve 并且 promise 通过 .then 正确运行,所以我不确定为什么当我以同样的方式使用 reject 时会收到未处理的拒绝错误。

下面的代码应该移到异步函数之外

 //Trigger the callback functions
        promise
            .then(value => console.log(value),
                value => console.log(value))
            .catch(value => console.log(value))
            .finally(() => tc2());