【问题标题】:Testcafe - Select an element that contains 'text' or 'text'Testcafe - 选择一个包含 \'text\' 或 \'text\' 的元素
【发布时间】:2023-02-21 00:04:42
【问题描述】:

我正在尝试获取包含英文文本的元素或者法语文本。但是,它只考虑第一个文本(“法语文本”||“英语文本”)。 如何选择两种语言的元素?

邮件助手:

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', ('法语文本'||'英语文本') 的所有变体。

仅考虑第一部分,当我将语言更改为 EN 时测试失败。

【问题讨论】:

    标签: typescript selector testcafe


    【解决方案1】:

    MailHelper.getMailEmail('email', ('text in French'||'text in English')... 是错的

    ('text in French'||'text in English')

    是一个 or 运算符,如果第一个参数为 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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 2014-02-19
      • 2022-08-03
      • 1970-01-01
      相关资源
      最近更新 更多