Skip to content

allow --force-device-scale-factor=1 as setting in seleniumbase #1294

@svenstehle

Description

@svenstehle

Hi, I want to run my tests on GitHub Actions CI and I am writing the tests locally on macos. The retina display that I am using consistently doubles width and height.

I addressed this by crudely monkeypatching get_new_driver of BaseCase:

from selenium import webdriver
from seleniumbase import BaseCase


class ComponentsTest(BaseCase):
    def get_new_driver(self, *args, **kwargs):
        """ This method overrides get_new_driver() from BaseCase. """
        options = webdriver.ChromeOptions()
        options.add_argument("--force-device-scale-factor=1")    # fix macos retina displays
        if self.headless:
            options.add_argument("--headless")
        driver = webdriver.Chrome(options=options)
        width = 1920
        height = 1080
        driver.set_window_size(width, height)
        print('Window size', driver.get_window_size())
        return driver

But this is a very crude solution and it broke on my second test case when I used self.click. How can I cleanly enable any google chrome browser option that I can pass to selenium.webdriver in that way, also work in seleniumbase?

I found custom_settings.py but I don't know if that is the right place?

Using those works to set the width and height:

CHROME_START_WIDTH = 1920
CHROME_START_HEIGHT = 1080
HEADLESS_START_WIDTH = 1920
HEADLESS_START_HEIGHT = 1080

Can I somehow set force-device-scale-factor=1 with seleniumbase --chromium-arg and can you point me to the correct syntax? I can't figure it out.

Help appreciated, thank you :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionSomeone is looking for answers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions