Ferret v0.12.0

More stability

September 14, 2020 by Tim Voronov

Hello fellow miners,

We are happy to announce a new Ferret release - Ferret v0.12.0.

This release has a new useful module in the standard library - testing!
Let’s dig in. The full changelog you can find here.

What’s added

Assertion library

A new T namespace has been added to the standard library that provides some helpful methods for making assertions.
The functions can be used to test UI, validate data and ensure the correctnes of a script.

LET doc = DOCUMENT('https://github.com/', { driver: "cdp" }) T::TRUE(ELEMENT_EXISTS(doc, "#user[login]")) T::TRUE(ELEMENT_EXISTS(doc, "#user[email]")) T::TRUE(ELEMENT_EXISTS(doc, "#user[password]")) RETURN NONE

Read about available functions here.

New FRAMES function

A new helper function that finds HTML frames by a given property selector.

LET page = DOCUMENT('https://www.montferret.dev/fixtures/iframe/', { driver: 'cdp' }) LET frame = FRAMES(page, "url", "https://www.montferret.dev/") RETURN FIRST(frame).url

iFrame navigation handling

Finally, we can control navigation of nested iframes! Whenever your page has a nested iframe that performs some nested navigation, you can tell Ferret to wait for its completion.

LET page = DOCUMENT('https://www.montferret.dev/fixtures/iframe/', { driver: 'cdp' }) LET innerPage = FIRST(FRAMES(page, "url", "https://www.montferret.dev/")) T::NOT::NONE(innerPage) CLICK(innerPage, "#navbar-burger") WAIT_CLASS(innerPage, "#primary-nav", "is-active") CLICK(innerPage, "#blog") WAIT_NAVIGATION(page, { frame: innerPage }) // We need to get a new document that we have navigated to LET innerPage2 = FIRST(FRAMES(page, "url", "https://www.montferret.dev/blog/")) WAIT_ELEMENT(innerPage2, ".blog") LET item = ELEMENT(innerPage2, ".blog-post a") LET targetURL = item.attributes.href CLICK(item) WAIT_NAVIGATION(page, { frame: innerPage2 }) // We need to get a new document that we have navigated to LET innerPage3 = FIRST(FRAMES(page, "url", targetURL)) RETURN INNER_TEXT(innerPage3, ".content")

What’s changed

Removed property caching and tracking

This could be a breaking change, so, please, test your scripts. In previous versions, the CDP driver used aggressive caching and changes tracking on properties like .class, .attributes and etc., in order to redcue amount of calls to a browser, which led to high CPU usage when a runtime held a big amount of elements in memory.
To tackle the problem, the caching and tracking were removed and thus, every time element’s property is accessed, a latest value gets retrived from a browser, without any further caching. If something needs to be cahced, it’s user’s responsibility to chace it in local variable.