Skip to content

hmrc/ui-test-runner

Repository files navigation

ui-test-runner

A helper library for UI testing at HMRC.

Usage

Declare dependency

Declare the library as a project dependency as follows:

"uk.gov.hmrc" %% "ui-test-runner" % "x.x.x" % Test

See an example.

Configuration

  • System property browser must be set in order to execute tests. Arguments chrome, edge and firefox are available.
  • System property environment must be set in order to execute tests. Arguments local, dev, qa and staging are typically available, but will depend on your project configuration. See an example.
  • System property accessibility.assessment is available to enable or disable the accessibility assessment. Arguments true and false are available, the default is true.
  • System property security.assessment is available to enable or disable the security assessment. Arguments true and false are available, the default is false.
  • System property browser.option.headless is available to enable or disable headless browser mode. Arguments true and false are available, the default is true.
  • System property browser.logging is available to enable browser console logs when using Chrome. Arguments true and false are available, the default is false.

Set system properties when executing tests as follows:

sbt -Dbrowser="<browser>" -Denvironment="<environment>" -Daccessibility.assessment="<accessibility.asessment>" -Dsecurity.assessment="<security.asessment>" -Dbrowser.option.headless=<browser.option.headless> "testOnly uk.gov.hmrc.ui.specs.*"

See an example.

Browser

Start

Start a new browser session as follows:

startBrowser()

See an example.

Stop

Stop an existing browser session as follows:

quitBrowser()

See an example.

Driver instance

Starting a new browser session returns an instance of RemoteWebDriver as an object. Use as follows:

Driver.instance.<command>

See an example.

Download directory

The default directory for file downloads is target/browser-downloads.

Screenshot on failure

Enable screenshot on failure with ScreenshotOnFailure trait as follows:

with ScreenshotOnFailure

See an example.

Test environment configuration

Test environment configuration is available. A configuration file is required to use it. See an example.

Create a url from a configuration file as follows:

val url: String = TestEnvironment.url("service") + "/path"

See an example.

Development

Tests

Run tests as follows:

sbt clean test

Scalafmt

Check all project files are formatted as expected as follows:

sbt scalafmtCheckAll scalafmtCheck

Format *.sbt and project/*.scala files as follows:

sbt scalafmtSbt

Format all project files as follows:

sbt scalafmtAll

License

This code is open source software licensed under the Apache 2.0 License.