I am writing galen test in javascript. I found that most of the test were written have these lines of codes are common.
var loginPage = new LoginPage(driver).waitForIt();
loginPage.waitForLoginLink();
console.log("before precondition");
var guestUser = accountTemplate.guest(); //guest user login
loginPage.loginAs(guestUser);
var homePage = new HomePage(driver).waitForIt();
I wanted to remove the repetition , I was thinking to use a global function and i will put these line of code there but what if i have to use some variable for example 'loginPage' later??
So , My question is what is the best way to avoid repeated work here.