【问题标题】:TestCafe & chrome:headless : how to force the browser language (locale)TestCafe & chrome:headless : 如何强制浏览器语言(语言环境)
【发布时间】:2020-01-24 08:18:51
【问题描述】:

我编写了一些使用 TestCafe 运行的浏览器测试,chrome:headless。测试是通过命令行从我不想更改默认语言的服务器启动的。

我的网站是多语言的。我想更改测试的语言,而不必每次都影响服务器/计算机的语言。我该怎么做?

我使用这个命令行启动测试:

npx testcafe chrome:headless src/scenarios/**/*.test.ts

【问题讨论】:

    标签: npm internationalization e2e-testing google-chrome-headless testcafe


    【解决方案1】:

    这完全取决于您的“多语言”实现:

    1. Navigate to 一些“区域设置”页面版本(example.com/en/)。
    2. 从登录页面开始您的测试,然后导航到特定的“语言环境”版本:
    await t
        .click(Selector('#choose-lang-combo')
        .click(Selector('#en-lang'))
    
    1. 尝试在您的请求中添加您自己的 Accept-Language 标头 add
    2. 使用custom user profile也许只使用 --lang 标志 (testcafe chrome --lang=es) 会对您有所帮助(无需自定义用户配置文件)

    例如,要创建一个以西班牙语 (es) 启动 Google Chrome 的快捷方式,您可以创建一个名为 chrome-es 的快捷方式,其目标如下:path_to_chrome.exe --lang=es --user-data-dir=c:\chrome-profile-es

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-10
      • 2019-12-31
      • 2011-05-27
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 2010-10-15
      • 2020-05-22
      相关资源
      最近更新 更多