HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
349 stars 52 forks source link

How to enable device emulation mode? #79

Closed konstunn closed 3 years ago

konstunn commented 4 years ago

I need to test in 1024 x 768 fullscreen.

How can I do that?

ojii commented 4 years ago

I have no experience with this, but a quick glance at the documentation of chromedriver on how to do this, you should be able to pass the emulation mode as desired capabilities when instantiating the browser.

konstunn commented 4 years ago

I have managed to do this. I will post here a piece of code demonstrating this soon.

konstunn commented 4 years ago

Here is the code for chrome driver

from arsenic import services, browsers

service = services.Chromedriver(binary='chromedriver')

device_metrics = dict(width=1024, height=768, pixelRatio=1.0)

mobile_emulation = dict(deviceMetrics=device_metrics)

kwargs = {'goog:chromeOptions': dict(mobileEmulation=mobile_emulation)}

browser = browsers.Chrome(**kwargs)

async with get_session(service, browser) as session:
    await session.get('/')
konstunn commented 4 years ago

I suggest documenting this somewhere: FAQ, documentation, whatever.

Btw, we need such a strange kwarg as 'goog:chromeOptions' because mobileEmulation is considered as experimental capability, as far as I get it.

konstunn commented 4 years ago

I dont know why but now I can not manage to run chrome in headless mode. This is how I try to do this

from arsenic import services, browsers

service = services.Chromedriver(binary='chromedriver')

device_metrics = dict(width=1024, height=768, pixelRatio=1.0)

mobile_emulation = dict(deviceMetrics=device_metrics)

kwargs = {'goog:chromeOptions': dict(mobileEmulation=mobile_emulation)}

browser = browsers.Chrome(chromeOptions={'args': [
                '--headless',
                '--disable-gpu',
            ]},
            **kwargs
)

async with get_session(service, browser) as session:
    await session.get('/')
konstunn commented 4 years ago

This is how I managed to succeed to run device emulation and headless mode

from arsenic import services, browsers

service = services.Chromedriver(binary='chromedriver')

device_metrics = dict(width=1024, height=768, pixelRatio=1.0)

mobile_emulation = dict(deviceMetrics=device_metrics)

kwargs = {'goog:chromeOptions': dict(mobileEmulation=mobile_emulation,
                                             args=['--headless', '--disable-gpu']
                                             )
                  }

browser = browsers.Chrome(
            **kwargs
)

async with get_session(service, browser) as session:
    await session.get('/')
dimaqq commented 3 years ago

Please add PR to document these recipes! 🙏

konstunn commented 3 years ago

Where should we document it? Is README suitable enough for that?

dimaqq commented 3 years ago

Documentation source code is here: https://github.com/HDE/arsenic/tree/main/docs I guess either howto or possibly tutorial?

Docs are ultimately pushed to https://arsenic.readthedocs.io/en/latest/

konstunn commented 3 years ago

Here is the PR. Please have a look https://github.com/HDE/arsenic/pull/110

I have added the two recipes to browser-specific section "Supported browsers".

konstunn commented 3 years ago

The pull request is merged so we might close the issue. Can we?