Sunday, August 28, 2016

Speeding up UI Browser tests with Robot Framework

My current AWS demo project is a Cat Voting Booth.  It uses SocketIO/WebSockets, so in addition to server-side unit tests I've built a number of browser-level tests, using Robot Framework.

One feature people don't realize is that Robot can actually be quite speedy. Opening and closing a browser window is very slow, on the order of 1-2 seconds. Depending on the application, this can be done once, saving 1-2 seconds for *every* test!  For my Very Important Cat Voting Booth, this is the case.

Here's the magic bit:

*** Settings ***
Resource          resource.robot
Test Setup        Reset Votes
Suite Setup       Open Browser To Voting Page
Suite Teardown    Close All Browsers

*** Test Cases ***
Valid Page
    Votes Not Available

Register Up Vote
    Vote Up
    Element Text Should Be    vote-count-up    1
    Element Text Should Be    vote-count-down    0

Normally, Robot will open/close a browser on each test.  The above stanza says "Test Setup: Reset Votes", that is, it'll reset my database and *not* open a browser.  The suite-level setup is "Suite Setup: Open Browser", which means Robot will open a browser once and not per test.  Similarly the suite-level teardown closes all the (Robot-created) browsers.

I can run four (admittedly modest) browser-level tests, in a full real browser, in four seconds! This includes going back and forth to my Flask-SocketIO server, interacting with Redis, and other things.  I'm quite happy with this result.

As a heavy Test Driven Development (TDD) guy, with the above speed I can do full browser-level tests as TDD!  I don't have to wait until I absolutely *have* to run UI tests, they can be fast enough for running many times an hour, to give me very fast development feedback.

Full source code here: https://github.com/johntellsall/aws-realtime-metrics

Tuesday, August 23, 2016

Saturday, August 6, 2016

TIP: find specific Docker container without using "cut" or other Shell silliness

People on the Interwebs love doing things in a leaden, verbose, laborious, and dusty manner.  Like piping a command through egrep then cut and sed then awk, when just "awk" will do.

Take Docker. We often want to find out which container is running something specific. Once we find our container, we want to "exec" a shell into it, or we want to kill it.

Here's the best way that doesn't mess with cut/sed/awk:

$ docker ps --filter ancestor=web,status=running --quiet
8fbc117716c3

In the previous command I was looking for the container ID that is descended from my "web" image. I'm not interested in my database nor Redis nor anything else, I want my web container.

Here's how to use it in practice, by killing the web container:

$ docker rm -f $(docker ps --filter ancestor=web,status=running --quiet)
8fbc117716c3

Also, here's how to use the same technique to hop into the web container, and run a shell.  This I use constantly, so I can examine a container to see what's going on, what it's doing, or what it's not doing:

$ docker exec -it $(docker ps --filter ancestor=web,status=running --quiet) bash
root@23b5a26eb252:/#

TIP: use YouTube to learn quickly

I'm learning lots of Amazon Web Services topics via videos on YouTube.  There's a lot of material, but I can absorb the content faster than people speak.  Also, I often want to go back and listen to what they say a few times.

I use these YouTube keyboard shortcuts ALL the time:

space -- play/pause
f/esc -- enter/leave full screen mode
left/right arrows -- go back/forwards five seconds
</> -- slower/faster

We also have these keys:

up/down arrows -- increase/decrease volume
0-9 -- jump to spot in video, 0=beginning

It's really freeing to learn material 150% or 200% faster using these keyboard shortcuts.  Enjoy!

(Thanks to University of Michigan)