更改Firefox Selenium Django / Python中的语言进行测试

发布于 2025-01-31 16:04:49 字数 823 浏览 1 评论 0原文

我正在为Django / Python项目进行Firefox的本地硒行为。我的Firefox浏览器设置为英语,我通过手动浏览器访问本地网站。但是,当我使用Selenium进行行为测试时,浏览器是德语,以及我网站上选择的标准语言。当我使用修复此线程它将浏览器语言更改为英语,而不是网站的默认语言。这将是frefor_all脚本的代码:(

from selenium.webdriver import Firefox, FirefoxOptions
from selenium.webdriver.support.ui import WebDriverWait

def before_all(context):
    """Run once before any testing begins."""
    options = FirefoxOptions()
    options.set_preference('intl.locale.requested', 'en')
    options.headless = False
    context.driver = Firefox(options=options)
    context.driver.implicitly_wait(5)
    context.driver.set_window_size(1024, 768)
    context.wait = WebDriverWait(context.driver, 30)

    logging.disable(logging.ERROR)

问题在于,行为测试找不到德语按钮文本)

I am running local Selenium Behave tests on Firefox for a Django / Python project. My Firefox browser is set to English and I visit my local website via the browser manually everything is in English. However, when I run the Behave tests with Selenium, the browser is in German, as well as the standard language selected on my website. When I use the fix in this thread it changes the browser language to English but not the default language of the website. This would be the code of the before_all script:

from selenium.webdriver import Firefox, FirefoxOptions
from selenium.webdriver.support.ui import WebDriverWait

def before_all(context):
    """Run once before any testing begins."""
    options = FirefoxOptions()
    options.set_preference('intl.locale.requested', 'en')
    options.headless = False
    context.driver = Firefox(options=options)
    context.driver.implicitly_wait(5)
    context.driver.set_window_size(1024, 768)
    context.wait = WebDriverWait(context.driver, 30)

    logging.disable(logging.ERROR)

(The problem is that the behave tests do not find the German button texts)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文