2020-10-10

Web Components Selenium test automation

The one of strengths of Web Components is shadow DOM. It allows to insulate the css rules scoping to own content, allows efficient memory use by sharing DOM, etc... But for QA folks it could make a challenge as usual CSS and XPath selectors would not work anymore. There is a way around.

Elements in Shadow DOM are not available via direct CSS or XPath. Instead you could use JS selector via "Copy JS path":

In this case the full selector is

full selector
document.querySelector("#container-a593f6c588 > div > div > div > div > div > shopping-list")
.shadowRoot.querySelector("div.padded > vaadin-combo-box")
.shadowRoot.querySelector("#input")
.shadowRoot.querySelector("#vaadin-text-field-label-0")

which could be shortened to 

trimmed selector
document.querySelector("shopping-list")
.shadowRoot.querySelector("vaadin-combo-box")
.shadowRoot.querySelector("#input")
.shadowRoot.querySelector("#vaadin-text-field-label-0")


For simplification in styles tables the series of CSS selectors and shadowRoot could be swapped with :shadow-root pseudoselector. CSS handler in this case should convert the string bello to JS above:

pseudo selector :shadow-root
jkp-shop-plans :shadow-root vaadin-combo-box :shadow-root #input :shadow-root #vaadin-text-field-label-0

the "Element locator" css should sniff for ":shadow-root" sub-string and replace with JS sequence above returning JS object. WebDriver has a By.js locator only in JS webdriver implementation. In Java you have to simulate it yourself. Fortunately that is easy via js Executor:

  1. String javascript = "document.querySelector('vaadin-combo-box').shadowRoot.querySelector('#input').shadowRoot.querySelector('#vaadin-text-field-label-0')";  
  2. JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;  
  3. WebElement element = (WebElement) jsExecutor.executeScript(javascript); 



2020-08-22

Semantic theming - fonts in typography

The main purpose of typography is to make the consumption of various kind of content ergonomic: first distinctive and recognizable, then easy to read and comprehend.

The kind of content defines the semantic categories for font characteristics set usually reflected in the purpose of content: 

  • reading - text, headers, tips,... - Roboto, SourceSansPro
  • script/code presentation - monospaced
  • initialism  - lone symbol/ mini tags / acronyms - barley
  • iconized - letter in/as icon, badge
  • tag - icon label, tag without background/border
Each category most likely will use own set of typeface, font type and font properties like spacing, size, weight, etc. 

Lets go over each semantic typography category and explore the purpose and applicable properties.

READING - I guess it is self-explanatory. The sentences, paragraphs and pages of text should be easy to read for hours. Besides of font it defines ergonomics for eye and even neck: you do not want your reader to swing eyes and head righ-left while reading the multi line text. The newspaper columns are good samples or solving such problem. I still love the books with 2-column page layout.  

SCRIPT - is a special kind of text which I love to read. Here the even space distribution and positioning of particular keyword and elements matter. Most of scripts have special formatters associated. A source of "holy wars" which do not have any winner. Accounting the industry standards and personal taste make ideal presentation almost impossible. But in same time gives personalisation advantage. Since each type of script have own semantic vocabulary, we will keep it aside for now focusing on most common features of script typography. Monospace font, keywords coloring. The light/dark background mode has a special meaning here and important to support.

INITIALIZM - usually a few letters used as a tag. The first letters of name as replacement for face image is a good example. It is often surrounded by rounded background. Used in spaced visually separated often interactive (clickable), custom state-aware UX elements.  

ICONIZED - the letter in icon along with image based icons. As icon itself should be at least 2x larger of average font size to assure picture recognition, the iconized letter size should match the image-based icons. While the font requirements are pretty same as in initializm, the dimensions should align to iconography. 


TAG - while the tag in outlined border or background usually match the "label" styling, tags could be shown without border and background. In this case they have to be distinguished by font properties. There nothing special about that except the contrast to the text around. Usually by larger font weight and size. Icon label and buttons text, horizontal menu items without borders fit into same semantics of atomic often actionable UX element. As the word "tag" in beginning of this paragraph :)
Extra spacing is dimensional requirement for such elements.