attester-launcher v0.4.0
attester-launcher
attester-launcher is a command line tool to automatically start and stop browsers for an attester campaign.
attester-launcher only works with attester version 2.4 and later.
Usage
attester-launcher is already included in attester. Once attester is installed, attester-launcher can be used directly from attester with the --launcher-config option, by specifying the configuration file to use. For example:
attester myCampaignConfig.yml --launcher-config launcherConfig.yml
attester-launcher can also be started separately to connect to an already running attester server. To use it that way, it is needed to install it from the npm repository:
npm install -g attester-launcher
Then it can be started with:
attester-launcher launcherConfig.yml --server http://127.0.0.1:7777
It is possible to specify multiple configuration files. In that case, configurations are merged, and values from the last configuration files specified in the command line can override values from previous configuration files.
Parameters from the configuration file can be overridden in the command line, for example: --server http://127.0.0.1:7777, or --maxInstances.Browser_Firefox 0.
Configuration file format
attester-launcher expects one or more configuration files, which specify which browsers to start and how.
Configuration files can be either in the JSON or the YAML format.
The format of a configuration file is recognized by the extension of the file. If it is .yml or .yaml, the file is parsed with the YAML parser, otherwise it is parsed with the JSON one.
For the value of any configuration parameter, it is possible to use the <%= env.ENVIRONMENT_VARIABLE_NAME %> syntax to include the value of an environment variable. It is also possible to refer to any other configuration value, for example: <%= maxInstances.Browser_Firefox %> or <%= server %>.
Here is a sample configuration file, in the YAML format:
# The launchers section defines named launchers, which can be used in the browsers section.
# It is mostly useful to define common properties for multiple browsers.
launchers:
MySauceLabsConfig:
# Launchers can inherit from one another.
# The parent launcher is defined in the $launcher property.
# The names of built-in launchers start with a $ (such as $saucelabs).
# Properties prefixed with a $ are generic properties (no matter which launcher is used).
# Properties without the $ prefix are processed by the specified launcher.
$launcher: '$saucelabs'
$connectingTimeout: 300000
$maxInstances: 5
capabilities:
tunnelIdentifier: <%= env.TRAVIS_JOB_NUMBER %>
recordVideo: false
# The browsers section defines how to start each browser defined in the campaign configuration.
# Each key in the map (here: IE, Firefox, Chrome and PhantomJS), must match the name of a browser
# in the campaign configuration (otherwise, it will be ignored).
browsers:
IE:
# This configuration extends MySauceLabsConfig, which is defined in the launchers section
$launcher: 'MySauceLabsConfig'
capabilities:
browserName: internet explorer
platform: Windows 7
version: 11.0
Firefox:
# 2 different configurations for Firefox: a remote one from SauceLabs and a local one
# with $webdriver:
- $launcher: 'MySauceLabsConfig'
capabilities:
browserName: firefox
platform: Linux
- $launcher: '$webdriver'
$tags:
- LocalBrowser
capabilities:
browserName: firefox
Chrome:
- $launcher: 'MySauceLabsConfig'
capabilities:
browserName: chrome
platform: Linux
- $launcher: '$webdriver'
$tags:
- LocalBrowser
capabilities:
browserName: chrome
PhantomJS:
$launcher: '$phantomjs'
$maxInstances: 8
maxInstances:
Launcher_MySauceLabsConfig: 5
Browser_Firefox: 5
Tag_LocalBrowser: 1Global properties
serverAddress of the attester server to connect to. Defaults tohttp://127.0.0.1:7777. If attester-launcher is started from attester, this value is automatically set by attester in the command line (which overrides any value defined in a configuration file).launchersMap defining named launchers with their configuration. Each key in the map is the name of a launcher which can then be used as the value of the$launcherproperty of a launcher configuration. Each value in the map is a launcher configuration, as described in the Launchers properties section.browsersMap defining which launchers to use for each browser defined in the attester campaign. Each key in the map must match the name of a browser in the campaign configuration (otherwise, it will be ignored). Each value in the map is either a launcher configuration, or an array of launcher configurations.minTasksPerBrowserMinimum number of tasks per browser instance. It is used as a limit to never start more browsers than the number of remaining tasks divided by this number. It is used at the time new browser instances are started, it is not used to stop already started browser instances.maxInstancesMap defining the maximum number of concurrent browser instances for different kinds of browsers. Each value in the map is a number. Each key in the map is a string which must use one of the following prefix:Launcher_: each key prefixed withLauncher_defines the maximum number of concurrent browser instances for the corresponding launcher name (that launcher name should be a built-in launcher or should correspond to a key inside thelaunchersmap). All descendant launchers are included in the count.Browser_: each key prefixed withBrowser_defines the maximum number of concurrent browser instances for the corresponding browser name (that browser name should correspond to a key inside thebrowsersmap, and the name of a browser in the campaign configuration).Tag_: each key prefixed withTag_defines the maximum number of concurrent browser instances for launchers whose configuration contains the corresponding tag in the$tagsproperty.Any: theAnykey defines the total maximum number of concurrent browser instances.
Launchers properties
Launchers can be configured through different properties. Properties prefixed with a $ are generic properties, common to all launchers. Properties without the $ prefix are processed by the specified launcher.
Common properties
$launcherName of a parent launcher to inherit from. It can be either a built-in launcher or a launcher defined in thelaunchersmap.$tagsArray of tags. Each tag is a string, which creates an independent counter of browser instances which can be used in themaxInstancesmap documented in the previous section.$maxInstancesMaximum number of concurrent browser instances which can be started by this launcher. Defaults to 1. Note that this property does not include descendant launchers in the count. For example, ifMySauceLabsConfigis defined in thelauncherssection with its$maxInstancesproperty set to 5, and if theFirefoxandChromebrowsers both inherit fromMySauceLabsConfig, then the 5 instances of Firefox are counted independently of the 5 instances of Chrome, so there can be a total of 10 instances ofMySauceLabsConfigif we count all descendant launchers. To limit the total number of descendants of a named launcher, it is possible to use the generalmaxInstancesmap documented at the previous section, with itsLauncher_prefix (but not this$maxInstanceslauncher property).$connectionRetriesSpecifies the maximum number of times a launcher is allowed to fail connecting its browser to the attester server. Defaults to 3. Once this threshold is reached, the launcher is disabled. As for the$maxInstancesproperty, the number of failures is counted independently in each launcher, not taking into account descendant launchers.$connectingTimeoutSpecifies the maximum number of milliseconds to wait between the time a launcher is started and the time the browser successfully connects to the attester server. Defaults to 120000 ms (2 min). When this timeout is reached, the browser is closed.$disconnectedTimeoutSpecifies the maximum number of milliseconds to wait between the time a launcher is disconnected and the time it reconnects. Defaults to 100 ms. When this timeout is reached, the browser is closed. When a browser is disconnected, there is usually not much hope that it will reconnect, which explains why the default value is so low, but there are some use cases in which it can be interesting to define a higher value.$idleTimeoutSpecifies the maximum number of milliseconds to wait between the time a browser is idle and the time it gets more tasks to execute. Defaults to 100 ms. When this timeout is reached, the browser is closed. When a browser is idle, there is usually not much hope that it will get more tasks to execute, which explains why the default value is so low. However, it can happens in case another browser of the same type gets disconnected while executing a task and if attester is configured to restart tasks when browsers are disconnected.$exitingTimeoutSpecifies the maximum number of milliseconds to wait between the time a browser is asked to close and the time it is reported by the launcher as closed. Defaults to 10000 ms (10s). When this timeout is reached, the browser is considered as closed even if the launcher did not report it, and the instances counters are updated so that it is possible to start another browser if needed.$urlExtraParametersSpecifies extra parameters to set in the URL opened in the browser. Especially, attester allows to add scripts in the page with thepluginparameter, so, for example,plugin=http://127.0.0.1:7778/robotcan be used to include the robot-server.
$process
The $process launcher allows to start a browser by executing a process specified in the command property.
The URL the browser should connect to is appended at the end of the arguments specified in commandArgs if it is not specified anywhere else in the command line (through ${ATTESTER-URL}).
The process is killed when the browser should stop.
Note that, on Windows, as stated in the Node.js documentation, killing the process means terminating it without notification.
commandPath to the executable file to start. This parameter can contain variables (cf the corresponding section below).commandArgsArray of string arguments to pass to the executable. Defaults to an empty array. The URL the browser should connect to is appended as the last parameter if it is not specified anywhere else in the command line (through${ATTESTER-URL}). This parameter can contain variables (cf the corresponding section below).
$phantomjs
The $phantomjs launcher allows to easily start PhantomJS, with a control script adapted to attester. It internally relies on the $process launcher to start PhantomJS.
phantomjsPathPath to the phantomjs executable. Defaults to the value of thePHANTOMJS_PATHenvironment variable if it is available, or the"phantomjs"string otherwise (which means phantomjs should be in the path). This parameter can contain variables (cf the corresponding section below).phantomjsArgsArray of string arguments to pass to the phantomjs executable. Defaults to an empty array. This parameter can contain variables (cf the corresponding section below).scriptArgsArguments to the phantomjs control script. Defaults to an empty array.- The
--local-consoleargument can be used to display logs (calls toconsole.log,console.error...) locally before sending them to the attester server. If this argument is not used, those logs are only sent to the attester server.
- The
$puppeteer
The $puppeteer launcher allows to start a browser with puppeteer or any compatible package (such as puppeteer-firefox).
Note that the puppeteer package is not declared as a dependency of attester-launcher and has to be installed separately.
puppeteerPathPath to the puppeteer-compatible package, passed to the node.jsrequirefunction. Defaults topuppeteer, which works out of the box ifpuppeteeris installed as a dependency of a package which also depends on attester-launcher.puppeteerOptionsArgument to be used when callingpuppeteer.launch. See here for a list of available options.robotIf set to a truthy value, aphantomJSRobotobject will be exposed on the rootwindowof the browser, containing asendEventmethod and akeysobject which allow to send input events (keyboard and mouse) to the web page. This API is compatible with the one provided when using the$phantomjslauncher.puppeteerKeyboardPathPath to a file similar to this one, containing the definition of available keys. This value is passed to the node.jsrequirefunction. Defaults topuppeteerPath + "/lib/USKeyboardLayout". It is only used in order to populate thephantomJSRobot.keysobject ifrobotis truthy.
$playwright
The $playwright launcher allows to start a browser with playwright or any compatible package (such as playwright-firefox).
Note that the playwright package is not declared as a dependency of attester-launcher and has to be installed separately.
playwrightPathPath to the playwright-compatible package, passed to the node.jsrequirefunction. Defaults toplaywright, which works out of the box ifplaywrightis installed as a dependency of a package which also depends on attester-launcher.browserName of the browser, such aschromium(the default),firefoxorwebkit. An object with that name must be exported by the playwright-compatible package and have alaunchmethod.launchOptionsArgument to be used when callingbrowserType.launch. See here for a list of available options.contextOptionsArgument to be used when callingbrowser.newPage. See here for a list of available options.robotIf set to a truthy value, aphantomJSRobotobject will be exposed on the rootwindowof the browser, containing asendEventmethod and akeysobject which allow to send input events (keyboard and mouse) to the web page. This API is compatible with the one provided when using the$phantomjslauncher.playwrightKeyboardPathPath to a file similar to this one, containing the definition of available keys. This value is passed to the node.jsrequirefunction. Defaults toplaywrightPath + "/lib/server/usKeyboardLayout.js". It is only used in order to populate thephantomJSRobot.keysobject ifrobotis truthy.
$webdriver
The $webdriver launcher allows to start a browser with Selenium WebDriver.
serverSelenium server to connect to. By default, no server is used, and local browsers are used.capabilitiesMap of desired capabilities. You can refer to the documentation. This parameter can contain variables (cf the corresponding section below).keepAliveDelayInterval (in milliseconds) at which a keep-alive command is sent. Defaults to -1, which disables the keep-alive feature. The command used to keep the browser alive isgetCurrentUrl.
$saucelabs
The $saucelabs launcher allows to start a browser on the Sauce Labs platform. It internally relies on the $webdriver launcher.
usernameSauce Labs user name to use to start a browser through the WebDriver API. Defaults to the value of theSAUCE_USERNAMEenvironment variable.accessKeySauce Labs access key, associated to the previoususernameparameter. Defaults to the value of theSAUCE_ACCESS_KEYenvironment variable.serverSelenium server to connect to. Defaults to the value of theSAUCE_SELENIUM_SERVERenvironment variable, orhttp://ondemand.saucelabs.com/wd/hubotherwise.capabilitiesMap of desired capabilities. In addition to standard capabilities supported by Selenium, Sauce Labs supports passing additional settings. Especially, when using a Sauce Connect tunnel, it can be useful to passtunnelIdentifierandparentTunnel.keepAliveDelayInterval (in milliseconds) at which a keep-alive command is sent. Defaults to -1, which disables the keep-alive feature. The command used to keep the browser alive isgetCurrentUrl.
$virtualbox
The $virtualbox launcher allows to use a web browser from a Virtual Box virtual machine. The configured virtual machine is cloned from the specified snapshot. The clone is then started and executes the specified command. When tests are finished, the virtual machine is powered off and deleted.
This launcher requires Virtual Box 5.0 or later.
vboxInstallPathPath to the directory containing Virtual Box. The directory should contain theVBoxManageexecutable file. If this parameter is not specified, the value from theVBOX_INSTALL_PATHor theVBOX_MSI_INSTALL_PATHenvironment variable is used.vmName of the virtual machine to use. The virtual machine will be cloned before being started, so that it is possible to start multiple instances of the same virtual machine.snapshotName of the snapshot to use when cloning the virtual machine.commandCommand to use inside the virtual machine to start the browser. This parameter can contain variables (cf the corresponding section below).commandArgsArguments to pass to the command. The URL the browser should connect to is appended as the last parameter if it is not specified anywhere else in the command line (through${ATTESTER-URL}). This parameter can contain variables (cf the corresponding section below).usernameName of user to use inside the virtual machine to start the command.passwordPassword to use inside the virtual machine.
$vboxrobot
The $vboxrobot launcher allows to use a web browser from a virtual machine managed by the vbox-robot server. The configured virtual machine is cloned from the specified snapshot. The clone is then started and executes the specified command. When tests are finished, the virtual machine is powered off and deleted.
serverAddress of the vbox-robot server. It should include authentication information if this is required to connect to the server.vmName of the virtual machine to use. The virtual machine will be cloned before being started, so that it is possible to start multiple instances of the same virtual machine.snapshotName of the snapshot to use when cloning the virtual machine.commandCommand to use inside the virtual machine to start the browser. This can be either a simple string, or an array in order to include command line arguments (which are then positioned beforecommandArgs). This parameter can contain variables (cf the corresponding section below).commandArgsArguments to add tocommand. The URL the browser should connect to is appended as the last argument if it is not specified anywhere else in the command line (through${ATTESTER-URL}). This parameter can contain variables (cf the corresponding section below).launcherOnlyIf set to true,commandis supposed to be only a launcher, which means that, when it exits, it does not mean the browser exited, so this does not cause the virtual machine to be stopped. Defaults to false (so the machine is stopped aftercommandstops running).pingCommandIf specified, this command will be executed repetitively until its return code is 0, beforecommandis started. This is useful especially to wait for the network to be connected in the virtual machine before starting the web browser. This can be either a simple string (if no argument needs to be passed) or an array (with command line arguments). The host name of the attester server is appended as the last argument if it is not used anywhere else in the command line (through${ATTESTER-HOSTNAME}). This parameter can contain variables (cf the corresponding section below).pingIntervalInterval (in milliseconds) between a unsuccessful ping command (returning a non-zero exit code) and the next execution of the ping command. Defaults to 1000 (which is one second).initCommandsArray of commands to execute just beforecommandand just afterpingCommand. These commands can be used to configure the virtual machine before starting the browser. Each command is expected to be an object with acommandproperty containing an array of string arguments (which can contain variables as described in the corresponding section).usernameName of user to use inside the virtual machine to startpingCommand,initCommandsandcommand.passwordPassword to use inside the virtual machine.closeOnFailedCalibrationIf set to true (which is the default), the virtual machine will be closed (powered off and deleted) when the calibration fails. This parameter can be set to false to let the virtual machine continue running when the calibration fails. Note that this parameter requires vbox-robot version 0.0.4 and later (it is ignored with earlier versions).
Variables
Some configuration properties of the launchers, such as command line parameters, can contain variables, as documented in the corresponding properties. The following variables are available in this case:
${ATTESTER-URL}The URL the browser should connect to.${ATTESTER-HOSTNAME}The host name part of${ATTESTER-URL}.${ATTESTER-SLAVEID}The unique identifier of the current slave, which is also included in${ATTESTER-URL}as theidparameter.
