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
27 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

What are the different Exit Codes while executing a Pytest code?

Hello Esha, while executing a Pytest code, ...READ MORE

answered Aug 22 in Selenium by Abha
• 22,870 points
11 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,090 points
554 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
888 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
550 views