• +43 660 1453541
  • contact@germaniumhq.com

Germanium 1.7.12 Is Released




Germanium 1.7.12 Is Released

This version introduces the parent_node() and child_nodes() utility functions. These functions allow for easy fetching of nodes which would otherwise be harder to access in plain WebDriver.

Internally the tests that test Germanium itself were cleaned up a bit.

In Action

Let’s assume you write an integration test using Germanium, and you decide to iterate over some nodes under another element that you already have. Here’s how you can do it.

parent_node() is pretty obvious, since it has only one parameter, named selector:

1
parent = parent_node('.child-element')

Awesome? Pretty awesome, since we can use selectors not just elements, but let’s see further.

The child_nodes() function has yet another parameter named only_elements that by default is True. Why that? Let’s find out.

For example for the given HTML:

1
2
3
4
<div id="parent">
<div id="child1">..</div>
<div id="child2">..</div>
</div>

When calling:

1
2
items = child_nodes("#parent")
assert len(items) == 2

This will return a list of 2 elements, with the child1 and child2, since only_elements is set by default to True.

This is what anyone would expect.

Instead, setting the only_elements to False, the call will return 5 elements (!), 4 elements on IE (?!?), since there are 3 (2 on IE) whitespace nodes in the #parent div:

  1. Before the #child1 (this one is dropped by IE in certain circumstances, <sarcasm>good job IE!</sarcasm>),
  2. Between #child1 and #child2,
  3. And after #child2.
1
2
items = child_nodes('#parent', only_elements=False)
assert len(items) == 5 # 4 on IE

This is actually what the browsers return. Text nodes are also elements in the DOM tree, so they will be returned. Imagine how mental would be to try testing with indexes, since the first text node might or might not be there.

Thus you don’t need to call some fancy JS, or write trippy if statements, since Germanium will do it for you. Also using Germanium you can enjoy the full selectors and locators support that Germanium offers, so even as you can see in the current example, you don’t need to find first the element, and only then get its children.

So keep testing with Germanium you awesome you!