Search code examples
symfonygoogle-chromeseleniumbehat

Symfony2 + Behat + Selenium2 mobile test not working


Trying to set behat tests for mobile devices in a Symfony2 Project.

I'm running selenium standalone server with chromedriver

This is my config file behat.yml

 default:
  suites:
    default:
      contexts:
        - FeatureContext:
          simpleArg: '%%kernel.environment%%'
          session:   '@session'
      mink_session: default
      mink_javascript_session: selenium_chrome_mobile_session

  extensions:
    Behat\Symfony2Extension: ~
    Behat\MinkExtension:
      base_url: http://frontend.local
      show_cmd: open -a Google\ Chrome %s
      sessions:
        default:
          symfony2: ~
        selenium2:
          selenium2:
            wd_host: http://127.0.0.1:4444/wd/hub
        selenium_chrome_mobile_session:
          selenium2:
            browser: chrome
            capabilities:
              extra_capabilities:
                chromeOptions:
                  mobileEmulation:
                    deviceName: "Google Nexus 5"
        selenium_chrome_session:
          selenium2:
            browser: chrome
            capabilities:
              extra_capabilities:
                chromeOptions:
                  args:
                    - "--start-maximized"
                    - "--test-type"

    emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
      name: html
      renderer: Twig,Behat2
      file_name: behat_report
      print_args: true
      print_outp: true
      loop_break: true

  formatters:
    html:
      output_path: %paths.base%/web

chrome_mobile:
  extensions:
    Behat\MinkExtension:
      default_session: selenium_chrome_mobile_session

chrome:
  extensions:
    Behat\MinkExtension:
      default_session: selenium_chrome_session

The website is adaptative (not responsive) and when I run the mobile features, the response is the one made for desktop browsers.

What I'm missing in my behat.yml?


Solution

  • For some reason running behat with profile doesn't work for chrome sessions

    behat -p chrome_mobile -f pretty
    

    Instead I added a tag with the session to execute. Like this:

    Feature: This is my feature
    
    @mink:selenium_chrome_session
    Scenario: This is first scenario
    When I am in homepage
    

    It works now