Refactor tests to remove duplicate code and show intent
Refactor to use pexpect instead of external expect script.