Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Our UI tests are implemented with selenium. Despite the fact that this tool is really mature, those tests aren't as reproducible as ordinary unit-tests. Here's a list of hints that should help to write stable magnolia ui tests:

IssuePotential fixRemark
Element cannot be found although it's thereadd a delay Fix your xpath, or use one of the waitUntil methods.querying
fro
for an element (AbstractMagnoliaUITest#getElementByPath(By)) will explicitly try for 5 seconds - if the test triggers a long running action (e.g. activation) this can take even longer so we might have to add an additional, explicit delay
Element is found although it should be goneadd a delay Fix your xpath, or use one of the waitUntil methods.unlike in the case where we check for existence of an element we don't have any implicit or explicit delay here - if the element needs some time to go away (e.g. Overlay fadeout) we have to add an explicit delay. use {{waitUntil(elementIsGone()}}
Input field value cannot be queried with xpathdont use xpathinput[@class = 'classname' and @value = 'form input...'] could be changed to input[@class = 'classname] and use
WebElement.getAttribute(
a condition like {{waitUntil(attributeToBe(locator, "value", "form input..."))}} to query the input value.
Form validation fails, even if fields are properly enteredensure blur / changeafter filling an input with sendKeys, one should explicitly blur the field - i.e. click anywhere else - and allow some time for the change event to occur. Only then, pressing 'save changes' will be properly aware of the modifications.
Getting another element instead of the expected onescope XPath queriesmaking dead simple queries like //input[@class='v-textfield'] should be carefully considered, there may be more elements of same kind (inputs, buttons) currently loaded in the UI. Try to scope selectors at least to subApp level.
Querying for descendent elementsuse .// XPath prefixinvoking parent.findElement(By.xpath("//something")) doesn't query only for sub-elements of parent. To evaluate an XPath expression relative to parent WebElement, one needs to use the .// prefix instead.

If you find it hard to create XPath queries, you might find the following helpful:

...