typescript - Cypress 断言文本,同时忽略软连字符

标签 typescript automated-tests cypress soft-hyphen

我正在尝试使用 cypress/cucumber 对 Web 应用程序进行 E2E 测试。 我正在测试的页面有一个 H1 标题,我想检查其内容。通常我会使用类似 cy.get('H1').should('contain.text', 'some longpagetitle')

但是标题中有一个软连字符(准确地说是­)。所以上面的行失败了..我宁愿不在我的断言中添加软连字符。

是否可以在忽略软连字符的情况下断言文本?

最佳答案

对文本应用替换,

<h1>extra&shy;ordinarily lond&shy;winded text</h1>
cy.get('h1')
  .invoke('text')
  .then(text => text.replace(/\u00AD/g,''))
  .should('eq', 'extraordinarily longwinded text')    // passes

关于typescript - Cypress 断言文本,同时忽略软连字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72924619/

相关文章:

typescript - 为什么我必须使用 "new BrowserWindow"而不是 "new Electron.BrowserWindow"实例化 Electron.BrowserWindow ?

javascript - 等待页面加载 - Cypress

cypress - 在 Cypress 中如何计算选择的项目并获得长度?

typescript - ionic 2 "Type ' { }' is not assignable to type ' 任何[]”

javascript - 如何手动抛出可观察到的错误?

inheritance - 如何在 Aurelia 中设置 "inherit"可绑定(bind)属性?

java - 使用 TestNG 进行并行测试 - 测试仅在一种浏览器上运行

automated-tests - OpenTest 是否支持在 headless 浏览器上进行自动化测试?

javascript - Cypress - 始终将元素聚焦到屏幕顶部的给定偏移量

reactjs - 使用 Cypress 或 React 测试库进行集成测试?