liveBook · Manning

Browser testing

As explained in Web Components in Action

Browser automation is the programmatic launching and control of web browsers to execute tests and report their results.

Browser automation launches test browsers from the terminal, loads the HTML, JavaScript, and CSS under test, and reports results back to the terminal. In Web Component Tester, Selenium handles this browser-control layer. section 13.2

A browser-testing setup separates three responsibilities:

  • Selenium launches and controls the browsers running the tests. section 13.2
  • Mocha organizes suites and tests, with setup and teardown hooks. section 13.2
  • Chai supplies assertions that compare actual values with expected results. section 13.2

Testing a slider component

A WCT test page loads the component, creates <wcia-slider value="50"></wcia-slider>, and checks its JavaScript property, HTML attribute, and rendered thumb position. Additional tests set values above and below the allowed range to expose missing maximum and minimum handling. section 13.2

Listing 13.2. WCT test file setup
<html>
<head>
  <script src="../../../../node_modules/web-component-tester/browser.js">
  </script>                                                               #1
  <script                                                                 #2
       type="module"
       src="../src/slider.js">
  </script>
   <style>
       wcia-slider {
           width: 500px;                                                  #3
       }
   </style>
</head>
<body>
<wcia-slider value="50"></wcia-slider>                                    #4
<script>
// tests go here                                                          #5
</script>
</body>
</html>

Inspect the minimal HTML test-page setup, including the WCT browser script, module under test, component fixture, and test location. section 13.2

How Web Components in Action covers it

How deep it goes
Explains the tool layers and demonstrates setup and assertions, but does not detail Selenium internals.
Examples
Uses WCT setup, slider fixtures, property and attribute assertions, rendered-position checks, and boundary-value failures.
What it assumes
Assumes HTML, JavaScript, CSS, and Web Component basics while introducing browser automation, test suites, hooks, and assertions.
What you can do after
Apply via Web Component Tester to run browser-based component suites and diagnose failures through assertions.
How it connects
Connects browser automation with Selenium, Web Component Tester, Mocha, Chai, assertions, and Web Components.

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.