Phantom.js finite-state automation