faaxm / spix

UI test automation library for QtQuick/QML Apps
MIT License
184 stars 47 forks source link

DRAFT: Add new searchItem method #62

Closed ctmbl closed 1 year ago

ctmbl commented 2 years ago

This PR introduces searchItem method which allow the client to find and get every (almost complete) path in the Qt tree leading to a specific item (searched by objectName/id as Spix already does). It is used like thise : s.searchItem("mainWindow/<searched item>")

Here is an example from the RemoteCtrl example : image

Use Cases

I'm well aware that Spix doesn't require a full path to an item to interact with it, yet searchItem can have many other use cases. I personally use it mainly in two ways but I'm sure one can find many others !

The problem I highlight here isn't the fact that Spix will strip tooCommonObjectName without searching for other occurence, nor the fact that FindChildItem uses depth-first tree search. It's just that paths containing too common object names present a risk that a test crash while it shouldn't. Knowing that, one should just avoid to copy/paste the complete path returned by searchItem into its test unit, because too complete path aren't robust against design changes, neither are paths containing too common objectName/ID (which aren't always unique because of the reusing of own defined Qt/QML items.

The second important point is that searchItem doesn't take in account the possibility of accessing an item stored as property of another (introduces by PR #2) but I didn't see this feature used in the examples so I figured that it wasn't a big deal.

Feedback

This is a first version of this method, I would greatly appreciate any help/remark you could make about the feature in itself as well as the implementation !