This small chunk of code will help you to take a screenshot of entire screen on any platform. It is especially helpful in test automation frameworks to add "take a screenshot on failure" functionality.
captureScreen method accepts the filename of the image to be produced in PNG format including the full path (absolute or relative to the working directory), e.g. "out/screenshots/myscreen.png"