如何在Cypress.io(电子/铬)中设置浏览器的语言? [英] How to set the browser's language in Cypress.io (electron/chrome)?

查看:241
本文介绍了如何在Cypress.io(电子/铬)中设置浏览器的语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于配置 Cypress 以启动某种语言的浏览器实例.

My question is about configuring Cypress to launch a browser instance in a certain language.

为了:

  • 对本地化(i18n)文本标签进行断言?
  • 检查i18n功能(在语言之间切换)
  • 例如,在以下情况下,
  • 绕过持续集成(CI/CD)的问题: 本地计算机上,浏览器默认为fr_FR,在CI/CD VM上默认为en_US?
  • make assertions on localized (i18n) text labels?
  • check i18n features (switching between languages)
  • bypass issues of Continuous Integration (CI/CD) when, for example, on a local computer, the browser default to fr_FR, and on the CI/CD VM it defaults to en_US?

我尝试了(没有成功):

I tried (without much success):

  • using LANGUAGE=en_US from the terminal invocation,
  • using the Browser's API plugin (see Cypress' browser launch API documentation)

谢谢!

推荐答案

来自Gleb Bahmutov:

from Gleb Bahmutov:

您可以在cy.visit期间使用onBeforeLoad和类似Object.defineProperty(navigator, 'language', { value: 'de-GE' })

src: https://gitter.im/cypress-io/cypress?at = 5d61408a07d1ff39f8769545

这篇关于如何在Cypress.io(电子/铬)中设置浏览器的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆