如何在 Cypress.io (electron/chrome) 中设置浏览器的语言? [英] How to set the browser's language in Cypress.io (electron/chrome)?
本文介绍了如何在 Cypress.io (electron/chrome) 中设置浏览器的语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是关于配置 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 toen_US
?
我试过了(没有成功):
I tried (without much success):
- 在终端调用中使用
LANGUAGE=en_US
, - 使用浏览器的 API 插件(参见 Cypress 的 浏览器启动 API 文档)
谢谢!
推荐答案
来自 Gleb Bahmutov:
from Gleb Bahmutov:
您在 cy.visit 期间使用 onBeforeLoad
设置它,例如 Object.defineProperty(navigator, 'language', { value: 'de-GE' })
you set it during cy.visit using
onBeforeLoad
with something likeObject.defineProperty(navigator, 'language', { value: 'de-GE' })
src:https://gitter.im/cypress-io/cypress?at=5d61408a07d1ff39f8769545
这篇关于如何在 Cypress.io (electron/chrome) 中设置浏览器的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文