1

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.

ajayv
  • 641
  • 6
  • 21
  • 1
    It looks to me that your code is sync, so why don't you simply return `f.e` (that is not part of the example, so I don't know what's that)? – skypjack Oct 01 '15 at 06:38

1 Answers1

0

depends on you're module concept, but you can include it via requirejs, see http://karma-runner.github.io/0.8/plus/RequireJS.html

hypery2k
  • 1,681
  • 15
  • 20