I tried the below code but multiple instances are being created

0 votes
I m using A.java for initializing the driver to use for test classes.I have used @BeforeCLass
   public class A{

        static WebDriver driver;

        @BeforeClass
        public void returnDriver(){
            driver = //I used other method to initiate and return the driver to here 
        }
    }

Extending Above class to Test classes

public class A1 extends A{

    public A1(){
        returnDriver();
    }
    @Test
    public void a(){
    }
    @Test
    public void b(){
    }

public class B1 extends A{

    public B1(){
        returnDriver();
    }
    @Test
    public void a1(){
    }
    @Test
    public void b1(){
    }

When I execute the code, by default multiple browser instances starts running 

Mar 29, 2018 in Selenium by QueenBee
• 1,810 points
10 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Remove the driver initialization from @BeforeClass/ returnDriver() method and move it to class level.
Use @AfterClass annotation and close the browser.
Use @BeforeSuite instead of @BeforeClass
Use any of the above methods.
answered Mar 29, 2018 by DragonLord999
• 8,360 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
465 views
0 votes
1 answer

How should I configure the chromedriver.exe in eclipse

Use the page factory pattern, working example: public ...READ MORE

answered Mar 27, 2018 in Selenium by Atul
• 5,470 points
2,230 views
+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
3,955 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
60 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
432 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
49 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.