I have a website with a home page that requires a user to be authorized or logged in to see all pages of the website. If you try to access the home page, but you are not logged in, then the website sends you to a login page. The url of the page has two query parameters - some id to identify the client and the referring url. Once you login, you get access to the homepage. If you are on a page called pageABC
and your session gets timed out, then you'll be shown the login page. You will go back to the previous page after logging in.
How do I model this scenario in terms of page objects?
I already have a HomePageObj
which has a webdriver
instance. It also has a void get()
method which opens the homepage url. Should I model that page in one of the following ways or try something else ?
1 - Change void get()
to return a LoginPageObj
if user is redirected to login page, else return null
? Then, my tests can do a login if they get null
.
2 - Add a member variable called User
to each page object. If void get()
redirects to login page url, then use the credentials in User
object to automatically do the login and open the desired url?
3 - Should I have a BasePageObj
with a void get()
method which works in way I mentioned in point 2? Then, all pages will extend this BasePageObj
.
UPDATES :
Regarding point 3 - BasePageObj can have two variables "requiresLogin" & "doAutoLogin". If requiresLogin = true & doAutoLogin = true, then do the login automatically. Any flaws in this approach ?
Thanks.