This set up page is executed once, before any tests in this suite.
In it we configure which Java packages contain the logic for our fixtures, which browser we want to use for Selenium tests and we start this browser.
This means we do not have to do this in every test, which means easier maintenance and better performance.

Stopping the browser is done in SuiteTearDown, which is done after all tests in this suite are completed.

!***> Fixture code locations

|Import                           |
|nl.hsac.fitnesse.fixture.slim.web|

*!

The Selenium configuration below uses lines starting with ''|note'' to have configuration values present that are not currently used.
This allows us to switch to another browser by just adding ''|note'' to one line and removing it from another, instead of typing the entire line.

Furthermore this configuration is prepared for both running the browser on the same (development) machine running Fitnesse (with ''start driver for''), as remotely on a node in a Selenium Grid (with ''connect to driver for'').
The latter allows tests to be executed on different operating systems. This is also very useful to run tests as part of a continuous integration server (i.e. build server), when no browsers are installed on the server running the tests.
This configuration can be overridden by using system properties. This allows different configurations on the build server to test with different browsers, without requiring different wiki content, but only requiring a different build configuration. More details can be found in OverridingSeleniumSetup.

!define GRID_HUB {http://remote-selenium.local:4444/wd/hub}

!*> Define $mobileEmulation device attributes

|script           |map fixture                                                                                                                                                                      |
|set value        |!-Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19-!|for|userAgent               |
|set int value    |360                                                                                                                                                 |for|deviceMetrics.width     |
|set int value    |640                                                                                                                                                 |for|deviceMetrics.height    |
|set double value |3.0                                                                                                                                                 |for|deviceMetrics.pixelRatio|
|$mobileEmulation=|copy map                                                                                                                                                                         |
*!

!*> Define $chromeHeadlessProfile chrome profile

|script                 |map fixture            |
|set value              |headless   |for|args[0]|
|set value              |disable-gpu|for|args[1]|
|$chromeHeadlessProfile=|copy map               |
*!

!*> Define $ieCleanSession internet explorer profile

|script                                |map fixture                       |
|expand periods in names to nested maps|false                             |
|set boolean value                     |true|for|!-ie.ensureCleanSession-!|
|$ieCleanSession=                      |copy map                          |
*!

|script          |selenium driver setup                                                                                                                  |
|start driver for|chrome                                                                                                                                 |
|note            |start driver for     |!-MicrosoftEdge-!                                                                                                |
|note            |start driver for     |internet explorer                                                                                                |
|note            |start driver for     |firefox                                                                                                          |
|note            |start driver for     |safari                                                                                                           |
|note            |start driver for     |chrome mobile emulation|with profile          |!{deviceName:Apple iPhone 6}                                      |
|note            |start driver for     |chrome mobile emulation|with profile          |$mobileEmulation                                                  |
|note            |start driver for     |chrome                 |with profile          |$chromeHeadlessProfile                                            |
|note            |Starting internet explorer with a clean session is destructive, i.e. clears cookies, cache, history and saved form data ''globally''   |
|note            |start driver for     |internet explorer      |with profile          |$ieCleanSession                                                   |
|note            |connect to driver for|chrome                 |at                    |${GRID_HUB}                                                       |
|note            |connect to driver for|!-MicrosoftEdge-!      |at                    |${GRID_HUB}                                                       |
|note            |connect to driver for|internet explorer      |at                    |${GRID_HUB}                                                       |
|note            |connect to driver for|firefox                |at                    |${GRID_HUB}                                                       |
|note            |connect to driver at |${GRID_HUB}            |with capabilities     |!{browserName:internet explorer, platform:Windows 8.1, version:11}|
|note            |connect to driver at |${GRID_HUB}            |with json capabilities|{aut:"io.selendroid.testapp", emulator: true}                     |
|show            |driver description                                                                                                                     |
