The website I’m trying to test is full of custom html-elements and therefore makes extensive use of the shadow dom. This makes it difficult to use locators. So I came up with the following workaround (which I’m still not quite happy with).
In short, I setup a utils.feature
where I define a JS-Function that returns the string of the actual function that I want.
@ignore
Feature:
Scenario:
# we compose a function using another function (the one above)
* def setupFindAnywhere =
"""
function setupFindAnywhere() {
let findAnywhere = function(selector, domParent) {
//code that traverses both DOM and ShadowDom and returns found element
}
}
return findAnywhere + ''; //returns the function as a string
}
"""
* def setupText = call setupFindAnywhere # this is now a string of just the function
* script('let findAnywhere = ' + setupText) # injects the function into the browser
And then in my actual test.feature
:
Feature: does stuff
Background:
* ... stuff
* call read('classpath:utils.feature') # sets up 'findAnywhere' in the browser
Scenario: stuff
* ... stuff
# because the browser knows `findAnywhere` I can just call it.
* script('findAnywhere("tbody > tr", document).click();')
This seems like a quite round-about way of doing this so I was wondering if there’s cleaner methods to interact with ShadowDom. Because otherwise I see myself quickly re-writing a lot of the pre-existing functions and that kind of defeats the purpose of a testing framework.