How to customize screen resolution with saucelabs (selenium, behat3.0 mink) capabilities

断了今生、忘了曾经 提交于 2021-01-28 22:58:12

问题


This is my behat.yml file :

firefox:                  
 suites:  
    firefox:  
      contexts:  
        -FeatureContext
  extensions:  
    Behat\MinkExtension:
      javascript_session: selenium2
      base_url: https://example.com
      selenium2:
        wd_host: username:pwd@ondemand.saucelabs.com/wd/hub
        browser: firefox
        capabilities: {'platform':'OS X 10.10', 'browser':'firefox', 'version':'42.0', "screen-resolution":"1280x1024"}

Which is giving error "

[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized option "screen-resolution" under "testwork.mink.sessions.selenium2.selenium2.capabilities"

I have tried this https://groups.google.com/forum/#!topic/behat/kApbLIiAkOg, but I am also getting exactly same error.

If I configure SauceLabsDriver then only I will get all (https://github.com/Behat/MinkExtension/blob/master/doc/index.rst#sessions) - special flavor of the Selenium2Driver

The above document is suggesting modify your behat.yml profile:

default:
    extensions:
        Behat\MinkExtension:
            sessions:
                my_session:
                    sauce_labs: ~

But no idea how to implementing this. Any idea? How to change behat.yml file with saucelabs to use all those customization parameters.


回答1:


Although this is for behat 2, could you please try Resizing browser window size with behat2.

class FeatureContext extends MinkContext
{
    /**
     * @BeforeScenario
     */
    public function resizeWindow()
    {
        $this->getSession()->resizeWindow(1440, 900, 'current');
    }
}



回答2:


Using resize with @BeforeScenario hook can be not optimal. Another way is to use a scenario step

  /**
   * @Given /^I set browser window size to "([^"]*)" x "([^"]*)"$/
   */
  public function iSetBrowserWindowSizeToX($width, $height) {
    $this->getSession()->resizeWindow((int)$width, (int)$height, 'current');
  }

And if needed to maximize it back

  /**
   * @Given /^I maximize browser window size$/
   */
  public function iSetBrowserWindowSizeToX($width, $height) {
    $this->getSession()->resizeWindow((int)$width, (int)$height, 'current');
  }


来源:https://stackoverflow.com/questions/34425759/how-to-customize-screen-resolution-with-saucelabs-selenium-behat3-0-mink-capa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!