Refactor login in tests into a helper.