Mink icon indicating copy to clipboard operation
Mink copied to clipboard

Default browser window size in configuration

Open gonzalovilaseca opened this issue 10 years ago • 19 comments

It would be great to have a default browser window size that can be defined in configuration, otherwise I have to add an extra step in every Behat scenario of the kind: 'And I set browser window size to "1024" x "768"'

gonzalovilaseca avatar May 08 '14 09:05 gonzalovilaseca

I think you should post to the https://github.com/Behat/MinkExtension instead, since it's MinkExtension that invokes Mink on behalf of Behat.

@stof , repo description says it's extension for Behat 2.4, is that correct? If so, then where MinkExtension for Behat 3.x lives?

aik099 avatar May 08 '14 09:05 aik099

Done thxs!

gonzalovilaseca avatar May 08 '14 09:05 gonzalovilaseca

Well, the default browser size is not something supported by drivers out there in a general way. And forcing a call to resizeWindow when starting or resetting the driver does not look like a clean implementation IMO.

Looking at the description, I assume you are using Mink inside your Behat suite. In this case, it is very easy to resize at the beginning of scenarios without writing a step explicitly: put the logic in a @BeforeScenario and @BeforeOutlineExample hook.

stof avatar May 08 '14 09:05 stof

@aik099 the readme talks about Behat 3. The description requires admin access to update it so I was not able to change it. Now I can, but I was not thinking about it anymore when receiving these rights.

stof avatar May 08 '14 09:05 stof

I think mentioning any versions in repo description is bad idea, because when releasing new version it's easy to forgot to update it there as well.

aik099 avatar May 08 '14 09:05 aik099

@aik099 I changed it to 2.4+, which is true

stof avatar May 08 '14 10:05 stof

I'm currently doing it in @BeforeScenario, but then every time I create a new context file I have to remember to resize the window, it's an extra step that could be avoided with configuration. The call to resizeWindow should only be done if there is a default size defined, sorry but I don't see why it's not a clean implementation.

gonzalovilaseca avatar May 08 '14 10:05 gonzalovilaseca

@BeforeScenario does not require putting anything in the feature file

stof avatar May 08 '14 10:05 stof

I don't use Behat, but now I totally understand that scenario name set via @BeforeScenario will prepend it's steps to every executed scenario in suite.

aik099 avatar May 08 '14 10:05 aik099

@aik099 @BeforeScenario is not adding steps. It is about running code before running the steps (there is other hooks before each steps or before the feature, and so on)

stof avatar May 08 '14 10:05 stof

Sorry, I meant context file. Another added step is that I mix both selenium and goutte scenarios in same feature file, so in @BeforeScenario I also have to check if the browser supports resizing, checking this adds a dependency on Selenium Driver, as if I change the javascript_session configuration parameter I should also have to change the context file.

gonzalovilaseca avatar May 08 '14 10:05 gonzalovilaseca

@gonzalovilaseca well, if we put this in a config file, we would also have to do the same check. And IMO, this does not belong to the core of MinkExtension. Adding it in a hook is very easy (and it the size itself can be configurable through the config file btw) and I don't think it is common enough (most projects don't care about the size at which the browser runs, as it is the first time this feature is requested)

stof avatar May 08 '14 10:05 stof

Ok. I guess you will start to see it more often as more responsive projects are built. The problem I found was that in my browser it worked ok, but mink, having a default 800x600 screen hid the texts and displayed icons. Only through a screenshot I was able to find what was going on.

gonzalovilaseca avatar May 08 '14 10:05 gonzalovilaseca

@gonzalovilaseca how did you solved the case when same scenarios were needed to be run on different browser window sizes?

aik099 avatar May 08 '14 11:05 aik099

@aik099 Didn't arrive to that point yet, but it doesn't seem easy

gonzalovilaseca avatar May 08 '14 18:05 gonzalovilaseca

@aik099 Didn't arrive to that point yet, but it doesn't seem easy

If you come up with anything or need help, then I'm right here as any other community member.

aik099 avatar May 08 '14 19:05 aik099

how did you solved the case when same scenarios were needed to be run on different browser window sizes?

This could be possible when using Behat 3 as you can create several suites using the same scenarios (in this case, we would put the window size as a suite setting, to allow having a different size persuite). In Behat 2, the only thing you can do is use config profiles and launch Behat several times (running all profiles)

stof avatar May 11 '14 07:05 stof

default:
  suites:
    something:
      paths: ...
      mink_javascript_session: selenium1280


 extensions:
    BehatTests\MinkExtension:
      base_url:  'https://set-from-env-look-at-BehatTests\\MinkExtension'

      sessions:
        selenium:
          selenium2:
            browser: chrome
            wd_host: "host.docker.internal:4444/wd/hub"

        selenium1280:
          selenium2:
            browser: chrome
            wd_host: "host.docker.internal:4444/wd/hub"
            capabilities:
              chrome:
                switches: ["--window-size=1280,900"]

pscheit avatar Aug 25 '20 03:08 pscheit

for the newer selenium2driver this does not work anymore - its missing prefs. We need to workaround that part:

in your selenium server you get this error:

from invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: cannot parse prefs
from invalid argument: must be a dictionary

workaround in behat.yaml

        selenium1280:
          selenium2:
            browser: chrome
            wd_host: "host.docker.internal:4444/wd/hub"
            capabilities:
              chrome:
                switches: ["window-size=1280,900"]
                prefs:
                  intl:

(just create anything under prefs, that would require prefs to be an associative array)

pscheit avatar May 30 '22 06:05 pscheit