Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Acceptance testing/Browsers: Difference between revisions

From MoodleDocs
No edit summary
m (Protected "Acceptance testing/Browsers": Developer Docs Migration ([Edit=Allow only administrators] (indefinite)))
 
(33 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Template:Migrated|newDocId=/general/development/tools/behat/browsers/}}
This page complements [[Acceptance testing]] providing info about how to run the acceptance tests suite in different browsers.
This page complements [[Acceptance testing]] providing info about how to run the acceptance tests suite in different browsers.


Line 9: Line 10:
* Safari - https://code.google.com/p/selenium/wiki/SafariDriver
* Safari - https://code.google.com/p/selenium/wiki/SafariDriver
* Internet Explorer - https://code.google.com/p/selenium/wiki/InternetExplorerDriver
* Internet Explorer - https://code.google.com/p/selenium/wiki/InternetExplorerDriver
* Microsoft Edge - https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
* PhantomJS (Webkit) - http://phantomjs.org/
* PhantomJS (Webkit) - http://phantomjs.org/
* IPhone - https://code.google.com/p/selenium/wiki/IPhoneDriver
* IPhone - https://code.google.com/p/selenium/wiki/IPhoneDriver
Line 16: Line 18:
=== PhantomJS ===
=== PhantomJS ===


PhantomJS is different as it is a headless browser as it is quite faster than other drivers, it doesn't need a GUI to run and can execute JS, it doesn't even need to be used through Selenium (you can do it though) and you can do it
PhantomJS is different as it is a headless browser as it is quite faster than other drivers, it doesn't need a GUI to run and can execute JS, it doesn't even need to be used through Selenium (you can do it though, but it's not officially supported) and you can do it


* Download PhantomJS: http://phantomjs.org/download.html
* Download PhantomJS: http://phantomjs.org/download.html
Line 38: Line 40:


== Compatibility ==
== Compatibility ==
Not all the drivers can execute all of Moodle's step definitions; we tagged the step definitions that are using feature not supported by all browsers or that should be considered:
Not all the drivers can execute all of Moodle's step definitions; we tagged the step definitions that are using features not supported by all browsers and also limitations that some browsers have; refer to the following table to know which browsers can run which tags:


{| class="wikitable"
{| class="wikitable"
|
|
|File uploads (@_only_local)
|File uploads (@_file_upload)
|Browser dialogs (@_alerts)
|Browser dialogs (@_alert)
|Switch window (@_switch_window)
|Switch window (@_switch_window)
|Switch frame (@_switch_iframe)
|Switch frame (@_switch_iframe)
|Bugs in chrome (@skip_chrome_zerosize)
|Bug in phantomjs (@_bug_phantomjs)
|-
|-
|Firefox
|Firefox
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
Line 56: Line 62:
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:red">No</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:red">NO (see MDL-71108)</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|-
|-
Line 63: Line 71:
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:red">No</span>
|<span style="color:red">No</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|-
|-
Line 69: Line 79:
|<span style="color:red">No</span>
|<span style="color:red">No</span>
|<span style="color:red">No</span>
|<span style="color:red">No</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|-
|-
|PhantomJS
|PhantomJS
|<span style="color:red">No</span>
|<span style="color:red">No</span>
|<span style="color:red">No</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:#0f0">Yes</span>
|<span style="color:red">No</span>
|<span style="color:red">No</span>
|<span style="color:#0f0">Yes</span>
|}
|}


== Moodle configuration ==
Note that, to skip some tag, you must prepend it with the <tt>~</tt> (logical NOT) character. Examples:
You need to tell behat what browser do you want to run and where it is. The best option could be to use behat profiles (http://docs.behat.org/guides/7.config.html#profiles).


The profiles can be specified in config.php through $CFG->behat_config like all other behat.yml specific configurations.
* Run all tests but <tt>@_alert</tt> ones: <tt>--tags '~@_alert'</tt>
* Run all chrome tests but <tt>@skip_chrome_zerosize</tt> ones: <tt>--tags '@javascript&&~@skip_chrome_zerosize'</tt>


This is an example of $CFG->behat_config to run behat in multiple environments (Windows, Linux and OSx) to cover all the supported browsers. Note that we are using multiple servers so we skip the tests that involves files uploads when using a remote server.
== Working combinations of OS+Browser+selenium ==
As OS, Browsers and Selenium keeps updating, some combination of OS+Browser+Selenium will not work on specific moodle version.


    // Note that in this case $linuxip is the local server.
We try to support the latest version of these combinations but they are not always BC and hence may not work with older releases. Please refer to [[Acceptance testing/Browsers/Working combinations of OS+Browser+selenium]] to ensure you have correct combination of them to run acceptance test.
    // Set servers IPs.
    $linuxip = '127.0.0.1';
    $windowsip = '192.168.xxx.xxx';
    $osxip = '192.168.xxx.xxx';
    $CFG->behat_config = array(
        'phantomjs-linux' => array(
            'filters' => array(
                'tags' => '~@_switch_window&&~@_only_local'
            ),
          'extensions' => array(
              'Behat\MinkExtension\Extension' => array(
                  'selenium2' => array(
                      'wd_host' => 'http://' . $linuxip . ':4444/wd/hub'
                  )
              )
          )
        ),
        'chrome-linux' => array(
            'filters' => array(
                'tags' => '~@_switch_window'
            ),
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'chrome',
                        'wd_host' => 'http://' . $linuxip . ':4444/wd/hub'
                    )
                )
            )
        ),
        'chrome-osx' => array(
            'filters' => array(
                'tags' => '~@_switch_window&&~@_only_local'
            ),
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'chrome',
                        'wd_host' => 'http://' . $osxip . ':4444/wd/hub'
                    )
                )
            )
        ),
        'chrome-win' => array(
            'filters' => array(
                'tags' => '~@_switch_window&&~@_only_local'
            ),
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'chrome',
                        'wd_host' => 'http://' . $windowsip . ':4444/wd/hub'
                    )
                )
            )
        ),
        'firefox-linux' => array(
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'firefox',
                        'wd_host' => 'http://' . $linuxip . ':4444/wd/hub'
                    )
                )
            )
        ),
        'firefox-osx' => array(
            'filters' => array(
                'tags' => '~@_only_local'
            ),
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'firefox',
                        'wd_host' => 'http://' . $osxip . ':4444/wd/hub'
                    )
                )
            )
        ),
        'firefox-win' => array(
            'filters' => array(
                'tags' => '~@_only_local'
            ),
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'firefox',
                        'wd_host' => 'http://' . $windowsip . ':4444/wd/hub'
                    )
                )
            )
        ),
        'safari-osx' => array(
            'filters' => array(
                'tags' => '~@_alerts&&~@_switch_window&&~@_only_local'
            ),
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'safari',
                        'wd_host' => 'http://' . $osxip . ':4444/wd/hub'
                    )
                )
            )
        ),
        'ie-win' => array(
            'filters' => array(
                'tags' => '~@_switch_window&&~@_only_local'
            ),
            'extensions' => array(
                'Behat\MinkExtension\Extension' => array(
                    'selenium2' => array(
                        'browser' => 'iexplore',
                        'wd_host' => 'http://' . $windowsip . ':4444/wd/hub'
                    )
                )
            )
        )
    );


[[Category:Quality Assurance]]
[[Category:Quality Assurance]]
[[Category:Behat]]

Latest revision as of 05:57, 8 July 2022

Important:

This content of this page has been updated and migrated to the new Moodle Developer Resources. The information contained on the page should no longer be seen up-to-date.

Why not view this page on the new site and help us to migrate more content to the new site!

This page complements Acceptance testing providing info about how to run the acceptance tests suite in different browsers.

Drivers

There are Selenium drivers (http://docs.seleniumhq.org/projects/webdriver/) to run acceptance tests in different browsers:

Each driver should be downloaded and Selenium .jar should be started specifying the path to the driver; depending on the driver there could be other requirements.

PhantomJS

PhantomJS is different as it is a headless browser as it is quite faster than other drivers, it doesn't need a GUI to run and can execute JS, it doesn't even need to be used through Selenium (you can do it though, but it's not officially supported) and you can do it

Note that 4444 is the default port used by Selenium so you must specify another one if you want to run them together and specify the port in $CFG->behat_config.

Examples

 # Selenium in Linux (firefox by default + chrome)
 java -jar /opt/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/opt/chromedriver
 # Selenium in OSx (firefox & safari by default + chrome)
 java -jar /Users/moodle/Downloads/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/Users/moodle/Downloads/chromedriver
 # Selenium in Windows (started using git bash) (firefox by default + chrome + internet explorer)
 java -jar /c/seleniumdrivers/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/c/seleniumdrivers/chromedriver.exe -Dwebdriver.ie.driver=/c/seleniumdrivers/IEDriverServer.exe
 # PhantomJS
 /path/to/your/phantomjs/bin/phantomjs --webdriver=4444

Compatibility

Not all the drivers can execute all of Moodle's step definitions; we tagged the step definitions that are using features not supported by all browsers and also limitations that some browsers have; refer to the following table to know which browsers can run which tags:

File uploads (@_file_upload) Browser dialogs (@_alert) Switch window (@_switch_window) Switch frame (@_switch_iframe) Bugs in chrome (@skip_chrome_zerosize) Bug in phantomjs (@_bug_phantomjs)
Firefox Yes Yes Yes Yes Yes Yes
Chrome Yes Yes Yes Yes NO (see MDL-71108) Yes
Internet Explorer Yes Yes No Yes Yes Yes
Safari Yes No No Yes Yes Yes
PhantomJS No No Yes Yes Yes No

Note that, to skip some tag, you must prepend it with the ~ (logical NOT) character. Examples:

  • Run all tests but @_alert ones: --tags '~@_alert'
  • Run all chrome tests but @skip_chrome_zerosize ones: --tags '@javascript&&~@skip_chrome_zerosize'

Working combinations of OS+Browser+selenium

As OS, Browsers and Selenium keeps updating, some combination of OS+Browser+Selenium will not work on specific moodle version.

We try to support the latest version of these combinations but they are not always BC and hence may not work with older releases. Please refer to Acceptance testing/Browsers/Working combinations of OS+Browser+selenium to ensure you have correct combination of them to run acceptance test.