0
votes

public class LogIntoapp {

@Test
public static void main() {


    Login();
    AddAccountData();
}

In my login method I have : System.setProperty("webdriver.chrome.driver","C:/drivers/chromedriver.exe"); WebDriver driver = new ChromeDriver();

So that when I call the AddAccountData I need to persist that driver to continue the navigation. I don't want to create a new web drive in my second method. Hopefully I'm not completely off base with this approach.

1

1 Answers

1
votes

I really recommend that you look up the page object pattern with regard to how you structure your tests, it will make this much more scalable as you go on I would suggest something like: http://code.google.com/p/selenium/wiki/PageObjects but if you google for that name then you will find lots of excellent resources.

You might want to ignore my advice and just have your tests continue to work. Well the easiest way will be to have your login method return the driver you created.

public WebDriver Login(){
    //your current code here

    return driver;
}

then in your test you would have:

WebDriver driver = Login();

AddAccountData(driver);

basically you would pass the driver in to each method.

I would really recommend my first approach though with page objects.

While I'm here a few other things are worth noting, you have your test as public static void main, that although is the normal entry point for an application this is not normally how tests are structures, it should just be a public void method and the name does not have to be main (in fact having it called so is confusing).

Secondly method names in Java by convention start with lowercase letters, following the conventions will help people follow your code easier as it gets more complicated.