Replies: 2 comments 5 replies
-
From a learning perspective, I'd argue that it's better to have BigTest users only use one paradigm to write BigTest, so this is great! I'm just not too sure about the generic Also, as we approach a more public release I think that all API change discussions should consider as well how we migrate from what we have. Can we create a codemod that works for most cases? or will it be a painful task for everyone to upgrade to the new API? At Folio, for instance, how much work do we need to put to migrate all the Interactors to a new syntax? |
Beta Was this translation helpful? Give feedback.
-
The new API allows more flexibility for people to write things. Is it valid to invoke a method multiple times? For instance, if I apply I made a little example to see if I get it: let linkInteractor = createInteractor<HTMLLinkElement>('link')
.selector('a')
.actions({
click: perform(element => { element.click() })
})
.filters({
title: (element) => element.title,
href: (element) => element.href,
id: (element) => element.id,
visible: {
apply: (element) => element.clientHeight > 0,
default: true
},
})
.actions({
hover: perform((element) => { element.hover() }) // don't know how to do this actually
})
let navlinkInteractor = linkInteractor
.selector('.nav-link')
.filter({
active: (element) => element.attr['aria-active-link']
}) If that's correct, would it be valid to say: export default test('BigTest')
.step(
Page.visit('/'),
NavlinkInteractor('About').click())
.assertion(NavlinkInteractor('About').is('active')); |
Beta Was this translation helpful? Give feedback.
-
When working on folio, we ran into situations where we wanted to extend existing interactors. This proved to be not easy. While working with this, I discovered an alternative API for creating interactors, which has some advantages over the current API. This API uses a builder pattern, similar to our test suite DSL. All of the concepts are the same, there is only a slight syntactic difference:
To compare, the current API looks like this:
The new API could look like this:
Or we could take the opportunity to simplify action definition:
And then we could add a more general
define
which would work for composite actions, as well as assertions:Interestingly, I think it is possible to implement this API backwards compatibly! However, there are some slight disadvantages to implementing this with backwards compatibility, which lead me to think that we should deprecate the existing API.
Advantages
There are two main advantages to this API:
Easier extensions
A challenge with interactors right now is that we ship some built in interactors, but extending them is difficult. This new API makes it very straight-forward!
There is no special API for extending interactors, it's just the normal flow, and each intermediate step is itself extensible.
Self references
In an action, it is currently not possible to reference another action or filter on the interactor passed to the function as an argument (in TypeScript, this is purely a type issue), the builder API makes it possible to define to previously defined actions and filters
Challenges
A desirable feature would be to have a method to narrow the type of element. For example, we could create a base interactor for all
HTMLElement
interactors which implements theid
andtitle
filters, and then use this as a starting point for other interactors:On the surface, this seems like it should work, but we once again run into issues of variance. The types of actions and filters
Actions<E>
andFilters<E>
end up with a contravariant type parameterE
, and so we cannot substitute aActions<HTMLLinkElement>
for aActions<HTMLElement>
. I think this is solvable, but it will definitely require backwards-incompatible changes to the types. Basically we should stop carrying forward the types of the action definitions, and instead carry forward the types of their implementations. These are not parameterized over the element type, and so will not run into this problem.I've added a partial implementation here: #735
Beta Was this translation helpful? Give feedback.
All reactions