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 30, 2018 in Selenium by QueenBee
• 1,820 points
1,498 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 30, 2018 by DragonLord999
• 8,450 points

Related Questions In Selenium

0 votes
2 answers

I am trying to run the below code but java.lang.Illegalstate Exception is coming

You are facing this error because while ...READ MORE

answered Jun 21, 2019 in Selenium by Abha
• 28,140 points
1,043 views
0 votes
2 answers

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,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,130 views
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,910 points
7,209 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,865 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP