Antwerp UI Test Automation Guide

April 4, 2023 ยท View on GitHub

When automating tests, one of the challenges is to keep the test resilient to code changes. Using data attributes can help you with that, by creating unique selectors for your tests.

Using unique data attributes with Antwerp UI

It's not possible to add unique data attributes to the Antwerp UI component library for the simple reason that the attribute won't be unique anymore when you use the component multiple times on the same page.

But in your app you can simply add a data attribute to each individual Antwerp UI component so you can target the component that you want to test.

Example

The following example shows the Antwerp UI datepicker with the unique qa data attribute id-1234.

<aui-datepicker
    [attr.data-qa]="id-1234"
    autocomplete="off"
    formControlName="inputDate"
    id="input-datepicker"
    name="input-datepicker"
    placeholder="dd/mm/jjjj"
    [range]="dateRange">
</aui-datepicker>

Which will result in:

<aui-datepicker data-qa="id-1234" autocomplete="off" formcontrolname="inputDate" ...>
...
</aui-datepicker>

Branding classes

Since you probably want to target a specific element or a subcomponent, selecting the parent component won't be enough. You can however target these elements and subcomponents based on their CSS classes in combination with the unique data attribute of the parent component.

Example

In this example the calendar of the datepicker component can be opened or closed by toggling the <span> tag, which is nested in the datepicker with data attribute data-qa="id-1234" and CSS class aui-flyout-action.

<aui-datepicker ... data-qa="id-1234" ...>
...
    <div ...>
        <input type="text" name="input-datepicker" ...>
        <span class="aui-flyout-action ...">...</span>
    </div>
...
</aui-datepicker>

Overview

To help you locate a specific element of a component, we've made an overview of all Antwerp UI components and the CSS classes they use. When an element doesn't have a class set, you can still target it by selecting the element type or its custom attribute.

ComponentClassElement / AttributeDescription
Autocompleteaui-flyout-actioninputtext input field
aui-selectable-listulselectable list
m-selectable-list__item> liselectable list item
Datepickerno classnameinputtext input field
aui-flyout-actionspanopen/close toggle
m-datepicker__navdivnavigation bar
fa-angle-left> button > iprevious
fa-angle-right> button > inext
m-datepicker__title> buttonview toggle
m-datepicker__calendartbodycalendar field
no classname> td > buttoncalendar element, depending on the selected view: day, month, year
Filter (checkbox)a-listulfilter list
no classname> lifilter element
no classname> > inputcheckbox
Filter (input)no classnameinputtext input field
Filter (select)no classname> selectselect
Flyoutaui-flyout-actionbuttonopen/close toggle
m-flyout__contentcontentcontent of the flyout
no classnameauiflyoutcloseclose button in content field
Footeraui-footerfooterfooter wrapper
o-footer> divsubfooter wrapper
Headero-headerheaderheader wrapper
o-header__menu-items> divheader element wrapper
o-header__menu-item> > divheader element
Logoo-header__logoalogo link
Mapo-leafletdivmap component wrapper
o-leaflet__content> divmap pane
o-leaflet__wrapper> divLeaflet map wrapper
o-leaflet__controls> > divLeaflet action buttons wrapper
Modalm-overlayaui-modal-overlayoverlay
m-modal> divmodal
m-modal__header> > divmodal header wrapper
m-modal__close> > > buttonclose button
m-modal__footer> > divmodal footer wrapper
no classname> > > buttonmodal action button(s)
Pagination (default)m-paginationulpagination wrapper
m-pagination__prev> lielement to previous page
m-pagination__next> lielement to next page
Pagination (items per page)aui-items-per-pagedivpagination wrapper
no classname> selectselect
Range sliderm-range-slider__innerdivrange slider selection wrapper
m-range-slider__bar> divrange slider selection bar
m-range-slider__handle> spanrange slider selection button
Search filteraui-flyout-actionbuttonopen/close toggle
m-search-filter__searchbuttonopen/close toggle
no classnamebuttonopen/close toggle
m-search-filter__results-titlebuttonopen/close toggle
a-list> ullist
m-search-filter__results-item> > lilist item
a-input__checkbox> > > divcheckbox wrapper
no classname> > > > inputcheckbox
Selectable listm-selectable-listulselectable list
m-selectable-list__itemliselectable list item
Tablea-tabletabletable wrapper
Time pickerm-timepickerdivselect boxes wrapper
no classnameformcontrolname hours / minuteshour / minute selection
Uploadm-uploaddivupload input field wrapper
m-upload__input> inputinput field
a-upload-queue__wrapperaui-upload-queuefiles to upload and upload button wrapper
m-upload__files> ullist of files to upload
m-upload__filename> > spanname of file to upload
m-upload__error> > spanerror message for faulty file
a-button> buttonupload button