Refactor key_page tests code