A Scala project to take full size screenshot of a webpage in different dimensions.
This project was build as a demo for the post "A Scala script to take full size webpage screenshots for different screen dimensions" that I published on my personal blog. You can always refer to the post if you want to find more information about this project.
- Scala (2.13.1)
- sbt (1.3.13)
- ChromeDriver (81.0.4044.69)
-
Download the project by executing the following commands:
git clone -b source https://github.com/diamantidis/scala-screenshots.git cd scala-screenshots
-
If you want to install the script globally, the repo contains a Makefile with a target to install. This target use sbt-native-packager to generate an archive and then create a symlink to
/usr/local/bin
.make install
-
Otherwise, you can use SBT to run the program from the project directory. See Usage section.
-
To configure the program, create a
json
file with the following format:{ "host": "the host", "urls": [ "a url to take screenshot for" ], "dimensions": [ { "width": 1920, "height": 1080 } ] }
For more details about this file, refer to the section Configuration.
-
Run
- From project directory With SBT:
sbt "run --config config.json"
- From any directory, after installing using
make install
:scala-screenshots --config config.json
- From project directory With SBT:
-
Run tests
sbt clean test
-
Run tests with coverage
sbt clean coverage test coverageReport
-
Run
scalafmt
tasksbt scalafmtAll
To configure Scala-screenshot
, create a json file and pass it as a value for the --config
argument. The following parameters can be configured:
-
Parameters
host
: The host of the website.urls
: A list of strings with the urls to take screenshots for.dimensions
: A list ofDimension
objects. Each object should have awidth
and aheight
key with a numeric value. The script will take screenshot for each of these dimensions.
-
An example:
{ "host": "https://diamantidis.github.io", "urls": [ "2020/04/19/scala-script-for-fullsize-screenshots-for-different-screen-dimensions" ], "dimensions": [ { "width": 1920, "height": 1080 }, { "width": 414, "height": 896 } ] }
This project is licensed under the terms of the MIT license. See the LICENSE file.