etaoin

cfleming 2020-06-26T03:31:40.027200Z

When using etaoin, what’s the best way to debug cases where an element can’t be found and I think it should be? In my case my tests work well up to a particular point, and then etaoin says it can’t find an element based on criteria that I’m sure are correct. I’m using the firefox driver.

cfleming 2020-06-26T03:45:43.028500Z

I managed to figure out my problem (apostrophe in the text I was trying to match) but my problem remains - when the xpath is invalid there seems to be no error of any kind. Is it possible to validate xpath in etaoin before using it?

2020-06-26T09:57:41.031100Z

@cfleming: I think the best way I’ve found is to drive your etaoin tests when writing them and debugging via a REPL with a headed browser. It makes browser testing a joy, when you can use the browser itself to see the DOM and you can watch the tests execute. Screenshot or println debugging via a browser is a nightmare.

1👍
2020-06-26T10:01:26.034800Z

e.g. I have a rich comment block at the bottom of each of my tests that contains:

(def driver (et/chrome (assoc h/default-driver-config
                                :headless false)))
And then a call to start my system/app in a test profile:
(def system (h/load-project-test-system :cogs (test-profile)))
The deftests then look like this:
(deftest my-tests
    (h/with-system system (h/load-project-test-system :customer-name (test-profile))
      (h/with-web-driver driver
         (some-test-scenario driver system))
         (some-other-test-scenario driver system))))

cfleming 2020-06-26T10:02:01.035900Z

Yeah, that’s what I came back to. In my tests I was closing my browser instance in a finally block, but for dev I just stopped doing that and then I can poke around when things don’t work. It’s a lovely experience all round.

cfleming 2020-06-26T10:02:20.036300Z

The xpath thing was annoying, but I can live with that.

2020-06-26T10:02:26.036500Z

Yeah

2020-06-26T10:02:39.037100Z

REPL driving browser tests is great — otherwise it’s a total nightmare. In the kaocha command line and ci we run them headless

cfleming 2020-06-26T10:02:50.037700Z

Yes, no doubt.

borkdude 2020-06-26T10:02:51.037800Z

There is also babashka integration for etaoin which allows you to use it in scripting: https://github.com/babashka/pod-babashka-etaoin

1👀
borkdude 2020-06-26T10:03:27.038900Z

(I've used this to create a file watcher and reload a browser to view my re-rendered asciidocs)

borkdude 2020-06-26T10:04:03.039600Z

In the JVM REPL I use the same workflow, define a global browser and then poke at it, until it works

cfleming 2020-06-26T10:04:47.040400Z

Yeah, that’s what I’ve been doing so far, especially once I ditched the closing in the finally block.

2020-06-26T10:05:41.041200Z

Yeah I was struggling with etaoin for a while until I figured that workflow out… Then it became much more pleasant.

borkdude 2020-06-26T10:05:59.041500Z

(btw, here's a demo of the filewatcher + etaoin thing: https://twitter.com/borkdude/status/1268270628039282690)

borkdude 2020-06-26T10:07:14.041900Z

@cfleming are you working on a web version of Cursive? 😉

cfleming 2020-06-26T10:08:28.042300Z

Haha, no, but my licensing is all CLJS on AWS.

2020-06-26T10:09:09.042400Z

:thumbsup: Neat

cfleming 2020-06-26T10:12:24.045200Z

The whole thing was a bit of a mess held together with blu-tack and sticky tape, and I’m tidying it all up.

2020-06-26T10:16:20.048700Z

Anyway I came here to ask a question… I’ve found that etaoin doesn’t really encourage you to make assertions, as you typically call et/wait-predicate or some variant for a condition to be true, and if the wait times out you get an exception not an assertion failure. If you then want to add an explicit assert it’s one or more extra lines essentially repeating the query from inside your wait, and wrapping them in an (is ,,,) form. This means I sometimes ignore making assertions; which I don’t particularly like; but for some tests I find the extra verbosity of writing the tests such that assert works properly is a bit annoying. I guess I could write some macros to dry this up… but I was wondering what other people were doing with regards to this.

cfleming 2020-06-26T10:17:10.049300Z

I’ve been using etoain since the day before yesterday, so this needs a pinch of salt obviously.

cfleming 2020-06-26T10:17:41.050100Z

But I’m not using a test framework at all, and I just have a script which I run. If there are no exceptions, then everything is good 🙂

cfleming 2020-06-26T10:18:37.051300Z

Actually, that’s not quite true, I have it broken down into a couple of functional groups, basically by the page under test. Those are top-level functions, and I just invoke those from comment blocks. So I can run separate parts of the tests separately.

borkdude 2020-06-26T10:19:49.052600Z

I actually did use deftest and then did all the etaoin stuff within a test. So when an exception happened, that test fails

borkdude 2020-06-26T10:19:54.052900Z

But no is - well, some, for like checking if a downloaded file exists, etc.

2020-06-26T10:20:11.053400Z

Ok so people are basically doing the same

2020-06-26T10:20:33.053900Z

Yeah quite a few tests do use is but many don’t.

cfleming 2020-06-26T10:21:30.055Z

FWIW I use a Swing GUI driver similar conceptually to etaoin to generate the screenshots for my docs, and I do the same there. I think it works well for this type of thing.

borkdude 2020-06-26T10:22:48.056200Z

We even used https://github.com/xebia/VisualReview to make visual diffs of screenshots, although that was often brittle.

2020-06-26T10:23:04.056800Z

I ran into an issue today though where kaocha annoyingly elides printing testing blocks if they don’t have any assertions in them, and clojure.test prints an error about deftest containing no assertions too 😞

borkdude 2020-06-26T10:23:31.057200Z

clojure.test doesn't do that by default though

2020-06-26T10:23:49.057700Z

ahh right enough it’s probably cider printing the later

borkdude 2020-06-26T10:23:49.057800Z

I did make a lib which does that: https://github.com/borkdude/missing.test.assertions

borkdude 2020-06-26T10:23:58.058200Z

yeah, cider does that for you

2020-06-26T10:25:27.059200Z

The thing I dislike about not explicitly making assertions is that it becomes hard to read what the test actually is without them… i.e. it doesn’t cleanly distinguish trying to get into a state from what the desired state should be.

borkdude 2020-06-26T10:26:45.059800Z

well, you could of course write (testing "foo" (etaoin/....) (is :succeeded))

2020-06-26T10:27:19.060100Z

that’s exactly what I’ve been doing as a work around

2020-06-26T10:35:15.063300Z

Anyway that’s useful to know I just popped in here to double check I wasn’t doing it wrong, after noticing kaocha wasn’t printing my assertions ( https://clojurians.slack.com/archives/CCY2V0U6A/p1593165322352600 )

borkdude 2020-06-26T10:55:48.064Z

@rickmoynihan Btw, maybe you could make an assert-expr multi-method implementation to deal with this

2020-06-26T10:56:17.064300Z

ahh that’s actually a good idea

borkdude 2020-06-26T10:57:42.065100Z

(is (working ....)) 😉