Highlights of this release

Update from ScalaWebTest <= 1.0.4

The AEM module is the only one containing breaking changes.

The AemTweaks trait no longer forces users to extend the FormsLogin trait. In turn it is longer able to provide the correct configuration for the loginPath. The loginPath is now configured by the AuthorLogin trait, which extends the FormsLogin. Therefore we recommend to adapt your code from

            class MyAemSpec extends IntegrationFlatSpec with AemTeaks with FormLogin
             
to
            class MyAemSpec extends IntegrationFlatSpec with AemTeaks with AuthorLogin
             

Upgrade of ScalaTest, Selenium and Selenium HtmlUnit dependencies

In case you manage the ScalaTest, Selenium and Selenium HtmlUnit dependencies in your project, we recommend that you upgrade them to the same versions as ScalaWebTest depends on. In case you use Maven as build tool, we recommend to make use of the BOM (bill of materials) provided by ScalaWebTest

The all new JSON module

The all new JSON module extends the concept of gauges from HTML to JSON. It provides a readable and easy to write integration tests for JSON responses.

import org.scalatest.exceptions.TestFailedException
import org.scalawebtest.integration.ScalaWebTestBaseSpec
import org.scalawebtest.json.JsonGaugeBuilder._
import play.api.libs.json.{JsValue, Json}

class DijkstraJsonGaugeSpec extends ScalaWebTestBaseSpec {
  path = "/dijkstra.json"
  def dijkstra = Json.parse(webDriver.getPageSource)

  "The response for Dijkstra" should "contain the expected values" in {
    dijkstra fits values of
      """{
         "firstName": "Edsger",
         "name": "Dijkstra",
         "yearOfBirth": 1930,
         "theories": [
           "shortest path",
           "graph theory"
         ]
        }
      """
  }
}
 

The detailed documentation introduces all features, such as fitting by type, value and verifying array elements.

Gauges for single HTML elements

It is now possible to check single HTML elements with the HtmlElementGauge. Often trying to fit the complete document into the defined gauge isn't the most natural and efficient thing to do. Especially when a website contains multiple elements of the same kind, such as content cards, gallery images or items of a product list, finding all those elements first, and then trying to fit each element with the gauge, is better.

import org.scalatest.exceptions.TestFailedException
import org.scalawebtest.integration.ScalaWebTestBaseSpec
import org.scalawebtest.core.gauge.HtmlElementGauge

class ElementGaugeSpec extends ScalaWebTestBaseSpec with HtmlElementGauge {
  path = "/galleryOverview.jsp"

  def images = findAll(CssSelectorQuery("ul div.image_columns"))

  val imageGauge = <div class="columns image_columns">
    <a>
      <figure class="obj_aspect_ratio">
        <noscript>
          <img class="obj_full"></img>
        </noscript>
        <img class="obj_full lazyload" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-sizes="auto"></img>
      </figure>
    </a>
  </div>

  "The gallery" should "contain the expected HTML for every image" in {
    images.size should be > 5 withClue " - gallery didn't contain the expected amount of images"

    for (image <- images) {
      image fits imageGauge
    }
  }
 

Convenience traits providing gauge functions

ScalaWebTest now contains four traits, which provide the functions of the four different gauge types, namely HtmlGauge, HtmlElementGauge, JsonGauge and JsonGaugeFromResponse Its recommended to extend one of those traits, to avoid having to manually handle imports of the gauge functions, which one wants to use.

Upgrade of ScalaTest and Selenium dependencies

We upgraded our dependencies

  • ScalaTest from 3.3.0 to 3.3.1
  • Selenium from 2.53.1 to 3.3.0
  • Selenium HtmlUnit Driver from 2.52.0 (selenium-htmlunit-driver) to 2.25 (htmlunit-driver)