Sahi headless execution with Google Chrome

warning NOTE: We do not recommend headless execution. Troubleshooting scripts in a headless environment can be tricky. In many cases, failures happen in headless which do not happen in real browsers. Troubleshooting and fixing them may not be worthwhile since your customers are using real browsers.
warning If you are looking at headless execution for integration with your CI server, read our recommended Jenkins/CI setup without headless playback.
infoCaution: Headless mode is available on Mac and Linux in Chrome 59+. Windows support is coming in Chrome 60+. To check what version of Chrome you have, open chrome://version. (A headless browser runs without a user interface)

For Windows:

  1. Download the latest version of Google Chrome from https://www.google.com/chrome/
  2. Click "Configure" link on the Dashboard, and, add
  3. <browserType>
    	<name>chromeHL</name>
    	<displayName>ChromeHL</displayName>
    	<icon>chrome.png</icon>
    	<path>$ProgramFiles (x86)\Google\Chrome\Application\chrome.exe</path>
    	<options>--no-default-browser-check --user-data-dir=$userDir/browser/chrome/profiles/sahi$threadNo
    	--proxy-server=127.0.0.1:$port --disable-popup-blocking
    	--headless --disable-gpu --no-sandbox --remote-debugging-port=9222</options>
    	<processName>chrome.exe</processName>
    	<capacity>5</capacity>
    </browserType>
  4. Save and restart Sahi.
  5. To run a test in Chrome headless: Click on "Bin" on the dashboard (or navigate to Sahi/userdata/bin on a command prompt) and run the command
  6. testrunner.bat sahitests/sahi_demo.sah http://sahi.co.in/demo/ chromeHL

For Linux:

  1. To install chrome, open terminal and enter the following command
  2. sudo apt-get install libxss1 libappindicator1 libindicator7
    wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo dpkg -i google-chrome*.deb
  3. If error messages pop up after running the command "sudo dpkg -i google-chrome*.deb" then run the command
  4. sudo apt-get install -f
  5. and then re-run the previous command. The error messages mentioned should include something similar to "google-chrome-stable depends on [lib-example]; however; Package [lib-example] is not installed."
  6. To check if completed, just type (without quotes): "google-chrome --version" and it must appear Google Chrome 59 or above.
  7. Click "Configure" link on Dashboard, and, if not present, add
  8. <browserType>
    	<name>chromeHL</name>
    	<displayName>ChromeHL</displayName>
    	<icon>chrome.png</icon>
    	<path>/usr/bin/google-chrome</path>
    	<options>--no-default-browser-check --user-data-dir=$userDir/browser/chrome/profiles/sahi$threadNo
    	--proxy-server=127.0.0.1:$port --disable-popup-blocking
    	--headless --disable-gpu --no-sandbox --remote-debugging-port=9222</options>
    	<processName>chrome</processName>
    	<capacity>5</capacity>
    </browserType>
  9. Save and restart Sahi.
  10. To run a test in Chrome headless: Open terminal, navigate to Sahi/userdata/bin and run the command
  11. sh testrunner.sh sahitests/sahi_demo.sah http://sahi.co.in/demo/ chromeHL

For Mac:

  1. To check Google Chrome version, Open terminal and type (without quotes): "google-chrome --version" and it must appear Google Chrome 59 or above.
  2. Click "Configure" link on Dashboard, and, if not present, add
  3. <browserType>
    	<name>chromeHL</name>
    	<displayName>ChromeHL</displayName>
    	<icon>chrome.png</icon>
    	<path>open -n -a "Google Chrome.app"</path>
    	<options>--args --no-default-browser-check --no-first-run --user-data-dir=$userDir/browser/chrome/profiles/sahi$threadNo
    	--proxy-server=127.0.0.1:$port --disable-popup-blocking
    	--headless --disable-gpu --no-sandbox --remote-debugging-port=9222</options>
    	<processName>"Google Chrome"</processName>
    	<capacity>5</capacity>
    	<force>true</force>
    </browserType>
  4. Save and restart Sahi.
  5. To run a test in Chrome headless: Open terminal, navigate to Sahi/userdata/bin and run the command
  6. sh testrunner.sh sahitests/sahi_demo.sah http://sahi.co.in/demo/ chromeHL
This will run the Sahi script without opening a browser.