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
14 views

1 answer to this question.

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,380 points

Related Questions In Selenium

0 votes
2 answers
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,050 points
677 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,530 points
2,983 views
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,050 points
246 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
617 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
234 views