typescript Testcafe -选择包含“文本”或“文本”的元素

k10s72fa  于 2023-02-25  发布在  TypeScript
关注(0)|答案(1)|浏览(152)

我正在尝试获取包含英语文本或法文文本的元素。但是,它只考虑了('text in French'中的第一个文本||'text in English')。如何选择两种语言的元素?
邮件助手:

async getEmail(filterEmail: string, filterSubject: string): Promise<string> {
        const filtered = json.filter(item => item['to_email'] === filterEmail && item['subject'] && item['subject'].includes(filterSubject));
        if (filtered.length > 0) {
            const emailLink = await this.getEmail(filtered[0].html_path);
            result = htmlDecoderHelper.decodeHTMLEntities(emailLink);
        } else {
            console.log("No email found");
        }
        return result;
    }

试验

test
('forgotPassword', 
 async t => {
  await t
    .click (ResetPasswordPage.mainPageButton);

    const emailLink = await MailHelper.getMailEmail('email', ('text in French'||'text in English'));
    console.log('resetPasswordEmail: ', emailLink);

  await t.navigateTo(emailLink)
    .expect(ResetPasswordPage.newPasswordCriterias.exists).ok()
  });

我尝试了const emailLink = await MailHelper.getMailEmail('email', ('text in French'||'text in English'));的所有变体
只考虑第一部分,当我将语言更改为EN时,测试失败。

w7t8yxp5

w7t8yxp51#

MailHelper.getMailEmail('email', ('text in French'||'text in English'))就是错了
('text in French'||'text in English')
||运算符,如果第一个参数为True,则返回第一个参数;如果第二个参数为True,则返回第二个参数,在这种情况下,字符串始终为True,除非字符串为空

> 'first' || "second"
> 'first'
> '' || "second"
> 'second'

您需要更改函数并传递一个字符串列表:
MailHelper.getMailEmail('email', ['text in French', 'text in English'])

async getEmail(filterEmail: string, filterSubjects: string[]): Promise<string> {
    for (subject in filterSubjects){
         ... your code
    }
    ...
}

相关问题