1

I am new to cucumber testing as well as selenium testing.Please help me to run all cucumber test cases in single browser.As for now i am creating new WebDriver object in each cucumber step_def for feature file.

1
  • Provide some code snippet. Commented Feb 27, 2014 at 11:18

2 Answers 2

2

The solution is, Using / passing the same Web Driver object across your step_def. From your Question i assume, you have multiple Step Def files, If the stories are small and related put all of them in a single step_def file and have a single Web driver object. If it is not the case, invoke every step_def with a predefined Driver object that is globally declared in the configuration loader.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for help but could you elaborate more as i have defined one helper class where i have method to evoke browser and in all step_def i am calling that method to evoke browser.So where to define that browser so that i could gate that browser in all step_def.And i could not put all step_def in one.
Then its much simpler, have a initialize method(or a constructor) in your helper class to instantiate your driver object. Then have a getter for the same. Now you can call the getter wherever you want. Only thing is, Have your Helper class common to all your step_def. If you still need some help, better show your classes, so that we can suggest where you need to modify.
1

For using one browser to run all test cases use singleton design pattern i.e make class with private constructor and define class instance variable with a private access specifier.Create a method in that class and check that class is null or not and if it is null than create a new instance of class and return that instance to calling method.for example i am posting my code.

class OpenBrowserHelp { private WebDriver driver; private static OpenBrowserHelp browserHelp; private OpenBrowserHelp() { this.driver = new FirefoxDriver() driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().window().maximize(); } public static OpenBrowserHelp getOpenBrowserHelp() { if (null == browserHelp) { browserHelp = new OpenBrowserHelp(); } return browserHelp; } WebDriver getDriver() { return driver } void setDriver(WebDriver driver) { this.driver = driver } public void printSingleton() { System.out.println("Inside print Singleton"); } 

Now, where ever you need to create browser instance than use

 WebDriver driver = OpenBrowserHelp.getOpenBrowserHelp().getDriver(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.