Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewport options ignored if passed into a dictionary to PyleniumConfig #282

Closed
vincent-olivert-riera opened this issue Sep 1, 2022 · 3 comments
Labels
discussion Questions, Comments, Thoughts or Feelings

Comments

@vincent-olivert-riera
Copy link
Contributor

Similarly to the default pylenium.json that gets created with pylenium init, I would like to define a dictionary with all my config options for Pylenium. However, the options for the viewport seem to be ignored and a default resolution of 800x600 is used instead.

Example illustrating the issue:

$ ./venv/bin/python
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> CONFIG = {
...     "driver": {
...             "browser": "chrome",
...             "options": ["--headless"],
...             "local_path": "./chromedriver",
...     },
...     "viewport": {
...             "maximize": True,
...             "width": 2160,
...             "height": 3840,
...     },
... }
>>> from pylenium.config import PyleniumConfig
>>> from pylenium.driver import Pylenium
>>> py = Pylenium(PyleniumConfig(**CONFIG))
>>> py.visit("chrome://newtab")
[09/01/22 23:58:38] COMMAND  py.visit() - Visit URL: `chrome://newtab`                                           driver.py:361
<pylenium.driver.Pylenium object at 0xffffb4104f10>
>>> py.screenshot("shot.png")
[09/01/22 23:58:56] COMMAND  py.screenshot() - Save screenshot to: `shot.png`}                                   driver.py:700
'shot.png'
>>> exit()
$ identify shot.png 
shot.png PNG 800x600 800x600+0+0 8-bit sRGB 3265B 0.000u 0:00.000

A workaround is to not add the viewport options to the CONFIG dictionary and instead explicitly call py.viewport().

Example illustrating the workaround:

$ ./venv/bin/python
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> CONFIG = {
...     "driver": {
...             "browser": "chrome",
...             "options": ["--headless"],
...             "local_path": "./chromedriver",
...     },
... }
>>> from pylenium.config import PyleniumConfig
>>> from pylenium.driver import Pylenium
>>> py = Pylenium(PyleniumConfig(**CONFIG))
>>> py.viewport(2160, 3840)
[09/02/22 00:11:10] COMMAND  py.viewport() - Set viewport to width=2160, height=3840, orientation=portrait       driver.py:766
<pylenium.driver.Pylenium object at 0xffff84e47eb0>
>>> py.visit("chrome://newtab")
[09/02/22 00:11:23] COMMAND  py.visit() - Visit URL: `chrome://newtab`                                           driver.py:361
<pylenium.driver.Pylenium object at 0xffff84e47eb0>
>>> py.screenshot("shot.png")
[09/02/22 00:11:31] COMMAND  py.screenshot() - Save screenshot to: `shot.png`}                                   driver.py:700
'shot.png'
>>> exit()
$ identify shot.png 
shot.png PNG 2160x3840 2160x3840+0+0 8-bit sRGB 41143B 0.000u 0:00.000
@ElSnoMan ElSnoMan added the bug Something isn't working label Oct 18, 2022
ElSnoMan added a commit that referenced this issue Oct 18, 2022
@ElSnoMan
Copy link
Owner

ElSnoMan commented Oct 18, 2022

I haven't been able to reproduce this issue. If you want to change the dimensions of the browser window, make sure to set "maximize": false and then set the width and height to the desired numbers.

If maximize is true, then yes, it will maximize the window to whatever screen it's on and ignore the width and height.

See https://docs.pylenium.io/configuration/viewport 👀

pylenium.json is a convenient way to set things for all tests. However, you can always use py.viewport() to override the viewport settings as you please!

@ElSnoMan ElSnoMan added discussion Questions, Comments, Thoughts or Feelings and removed bug Something isn't working labels Oct 18, 2022
@vincent-olivert-riera
Copy link
Contributor Author

Thanks for taking time to answer this issue.

If you want to change the dimensions of the browser window, make sure to set "maximize": false and then set the width and height to the desired numbers.

If maximize is true, then yes, it will maximize the window to whatever screen it's on and ignore the width and height.

See https://docs.pylenium.io/configuration/viewport eyes

Oh, maybe that's the reason! I'll test it tonight and I'll come back with the result.

pylenium.json is a convenient way to set things for all tests. However, you can always use py.viewport() to override the viewport settings as you please!

Yes, that's what I'm currently doing as a workaround.

@vincent-olivert-riera
Copy link
Contributor Author

vincent-olivert-riera commented Oct 19, 2022

Confirmed, my problem was using "maximize": True, therefore my width and height options were ignored.

Setting "maximize": False fixes my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Questions, Comments, Thoughts or Feelings
Projects
None yet
Development

No branches or pull requests

2 participants