Two Browsers opened when running testng suite

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Two Browsers opened when running testng suite

Mark Southward
Hi,
I've tried to set up a simple scenario where my tests are in 2 classes
which extend a baseClass which invokes Firefox webdriver 2. This is in
anticipation of having lots more tests in other classes (albeit with a
little more code). This is run from within Eclipse.

A Firefox browser opens and before navigating to the "home page"
another browser opens. The tests seem to execute ok. I'm sure it will
be my code, I just can't see which bit(s), so if anyone can point it
out to me I would be very grateful!

Thanks for reading,

Mark

The testNG.xml file:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none" >
  <test name="Test" preserve-order="true">
    <classes>
          <class name="simple.FirstClass">
  <methods>
                        <include name="step1"/>
                        <include name="step2"/>
                </methods>
          </class>
          <class name="simple.SecondClass">
  <methods>
                        <include name="step3"/>
                        <include name="step4"/>
                </methods>
          </class>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->


The base class:-
package simple;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

public class BaseClass {
        WebDriver driver = new FirefoxDriver();

    @BeforeSuite
    public void setup() throws Exception {
    driver.get("http://www.google.com");
    }

    @AfterSuite
    public void tearDown() throws Exception {
    driver.quit();
        }
}

The 1st test class:-
package simple;

import org.testng.annotations.Test;

public class FirstClass extends BaseClass {

          @Test
          public void step1() {
                  System.out.println("***In step1");
          }

          @Test
          public void step2() {
                  System.out.println("***In step2");
          }
}

The 2nd class:-
package simple;

import org.testng.annotations.Test;

public class SecondClass extends BaseClass {

          @Test
          public void step3() {
                  System.out.println("***In step3");
          }

          @Test
          public void step4() {
                  System.out.println("***In step4");
          }
}

The output:-
***In step1
***In step2
***In step3
***In step4

===============================================
Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Two Browsers opened when running testng suite

vasikarla.raj
I guess you shud be implementing a singleton pattern to restrict single browser instance....

Thanks,
Raj

On May 31, 2012, at 1:35 PM, Mark Southward <[hidden email]> wrote:

> Hi,
> I've tried to set up a simple scenario where my tests are in 2 classes
> which extend a baseClass which invokes Firefox webdriver 2. This is in
> anticipation of having lots more tests in other classes (albeit with a
> little more code). This is run from within Eclipse.
>
> A Firefox browser opens and before navigating to the "home page"
> another browser opens. The tests seem to execute ok. I'm sure it will
> be my code, I just can't see which bit(s), so if anyone can point it
> out to me I would be very grateful!
>
> Thanks for reading,
>
> Mark
>
> The testNG.xml file:-
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
> <suite name="Suite" parallel="none" >
>  <test name="Test" preserve-order="true">
>    <classes>
>      <class name="simple.FirstClass">
>        <methods>
>            <include name="step1"/>
>            <include name="step2"/>
>        </methods>
>      </class>
>      <class name="simple.SecondClass">
>        <methods>
>            <include name="step3"/>
>            <include name="step4"/>
>        </methods>
>      </class>
>    </classes>
>  </test> <!-- Test -->
> </suite> <!-- Suite -->
>
>
> The base class:-
> package simple;
>
> import org.openqa.selenium.WebDriver;
> import org.openqa.selenium.firefox.FirefoxDriver;
> import org.testng.annotations.AfterSuite;
> import org.testng.annotations.BeforeSuite;
>
> public class BaseClass {
>    WebDriver driver = new FirefoxDriver();
>
>    @BeforeSuite
>    public void setup() throws Exception {
>        driver.get("http://www.google.com");
>    }
>
>    @AfterSuite
>    public void tearDown() throws Exception {
>        driver.quit();
>    }
> }
>
> The 1st test class:-
> package simple;
>
> import org.testng.annotations.Test;
>
> public class FirstClass extends BaseClass {
>
>      @Test
>      public void step1() {
>          System.out.println("***In step1");
>      }
>
>      @Test
>      public void step2() {
>          System.out.println("***In step2");
>      }
> }
>
> The 2nd class:-
> package simple;
>
> import org.testng.annotations.Test;
>
> public class SecondClass extends BaseClass {
>
>      @Test
>      public void step3() {
>          System.out.println("***In step3");
>      }
>
>      @Test
>      public void step4() {
>          System.out.println("***In step4");
>      }
> }
>
> The output:-
> ***In step1
> ***In step2
> ***In step3
> ***In step4
>
> ===============================================
> Suite
> Total tests run: 4, Failures: 0, Skips: 0
> ===============================================
>
>
> --
> You received this message because you are subscribed to the Google Groups "testng-users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to [hidden email].
> For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Two Browsers opened when running testng suite

Tomek Kaczanowski-3
(a shot in the dark) make driver static perhaps?

--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com


2012/5/31 Raj <[hidden email]>:

> I guess you shud be implementing a singleton pattern to restrict single browser instance....
>
> Thanks,
> Raj
>
> On May 31, 2012, at 1:35 PM, Mark Southward <[hidden email]> wrote:
>
>> Hi,
>> I've tried to set up a simple scenario where my tests are in 2 classes
>> which extend a baseClass which invokes Firefox webdriver 2. This is in
>> anticipation of having lots more tests in other classes (albeit with a
>> little more code). This is run from within Eclipse.
>>
>> A Firefox browser opens and before navigating to the "home page"
>> another browser opens. The tests seem to execute ok. I'm sure it will
>> be my code, I just can't see which bit(s), so if anyone can point it
>> out to me I would be very grateful!
>>
>> Thanks for reading,
>>
>> Mark
>>
>> The testNG.xml file:-
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
>> <suite name="Suite" parallel="none" >
>>  <test name="Test" preserve-order="true">
>>    <classes>
>>      <class name="simple.FirstClass">
>>        <methods>
>>            <include name="step1"/>
>>            <include name="step2"/>
>>        </methods>
>>      </class>
>>      <class name="simple.SecondClass">
>>        <methods>
>>            <include name="step3"/>
>>            <include name="step4"/>
>>        </methods>
>>      </class>
>>    </classes>
>>  </test> <!-- Test -->
>> </suite> <!-- Suite -->
>>
>>
>> The base class:-
>> package simple;
>>
>> import org.openqa.selenium.WebDriver;
>> import org.openqa.selenium.firefox.FirefoxDriver;
>> import org.testng.annotations.AfterSuite;
>> import org.testng.annotations.BeforeSuite;
>>
>> public class BaseClass {
>>    WebDriver driver = new FirefoxDriver();
>>
>>    @BeforeSuite
>>    public void setup() throws Exception {
>>        driver.get("http://www.google.com");
>>    }
>>
>>    @AfterSuite
>>    public void tearDown() throws Exception {
>>        driver.quit();
>>    }
>> }
>>
>> The 1st test class:-
>> package simple;
>>
>> import org.testng.annotations.Test;
>>
>> public class FirstClass extends BaseClass {
>>
>>      @Test
>>      public void step1() {
>>          System.out.println("***In step1");
>>      }
>>
>>      @Test
>>      public void step2() {
>>          System.out.println("***In step2");
>>      }
>> }
>>
>> The 2nd class:-
>> package simple;
>>
>> import org.testng.annotations.Test;
>>
>> public class SecondClass extends BaseClass {
>>
>>      @Test
>>      public void step3() {
>>          System.out.println("***In step3");
>>      }
>>
>>      @Test
>>      public void step4() {
>>          System.out.println("***In step4");
>>      }
>> }
>>
>> The output:-
>> ***In step1
>> ***In step2
>> ***In step3
>> ***In step4
>>
>> ===============================================
>> Suite
>> Total tests run: 4, Failures: 0, Skips: 0
>> ===============================================
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "testng-users" group.
>> To post to this group, send email to [hidden email].
>> To unsubscribe from this group, send email to [hidden email].
>> For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups "testng-users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to [hidden email].
> For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Two Browsers opened when running testng suite

⇜Krishnan Mahadevan⇝
I dont think either the singleton nor the static approach is going to work. 
Am saying this because both of these approaches although would cause only 1 instance of webdriver it can have catastrophic results on the test itself because now both the classes would be working with the same webdriver which means they both try to perform different operations on the same browser. I think removal of @BeforeSuite and using @BeforeClass would be the right thing. 

The other way would be to move the instantiation part to a separate class, have the instantiation done in a beforeinvocation, save the newly created object in a ThreadLocal variable and then query this variable in the test method. 

On Friday, June 1, 2012, Tomek Kaczanowski wrote:
(a shot in the dark) make driver static perhaps?

--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com


2012/5/31 Raj <<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;vasikarla.raj@gmail.com&#39;)">vasikarla.raj@...>:
> I guess you shud be implementing a singleton pattern to restrict single browser instance....
>
> Thanks,
> Raj
>
> On May 31, 2012, at 1:35 PM, Mark Southward <[hidden email]> wrote:
>
>> Hi,
>> I've tried to set up a simple scenario where my tests are in 2 classes
>> which extend a baseClass which invokes Firefox webdriver 2. This is in
>> anticipation of having lots more tests in other classes (albeit with a
>> little more code). This is run from within Eclipse.
>>
>> A Firefox browser opens and before navigating to the "home page"
>> another browser opens. The tests seem to execute ok. I'm sure it will
>> be my code, I just can't see which bit(s), so if anyone can point it
>> out to me I would be very grateful!
>>
>> Thanks for reading,
>>
>> Mark
>>
>> The testNG.xml file:-
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
>> <suite name="Suite" parallel="none" >
>>  <test name="Test" preserve-order="true">
>>    <classes>
>>      <class name="simple.FirstClass">
>>        <methods>
>>            <include name="step1"/>
>>            <include name="step2"/>
>>        </methods>
>>      </class>
>>      <class name="simple.SecondClass">
>>        <methods>
>>            <include name="step3"/>
>>            <include name="step4"/>
>>        </methods>
>>      </class>
>>    </classes>
>>  </test> <!-- Test -->
>> </suite> <!-- Suite -->
>>
>>
>> The base class:-
>> package simple;
>>
>> import org.openqa.selenium.WebDriver;
>> import org.openqa.selenium.firefox.FirefoxDriver;
>> import org.testng.annotations.AfterSuite;
>> import org.testng.annotations.BeforeSuite;
>>
>> public class BaseClass {
>>    WebDriver driver = new FirefoxDriver();
>>
>>    @BeforeSuite
>>    public void setup() throws Exception {
>>        driver.get("http://www.google.com");
>>    }
>>
>>    @AfterSuite
>>    public void tearDown() throws Exception {
>>        driver.quit();
>>    }
>> }
>>
>> The 1st test class:-
>> package simple;
>>
>> import org.testng.annotations.Test;
>>
>> public class FirstClass extends BaseClass {
>>
>>      @Test
>>      public void step1() {
>>          System.out.println("***In step1");
>>      }
>>
>>      @Test
>>      public void step2() {
>>          System.out.println("***In step2");
>>      }
>> }
>>
>> The 2nd class:-
>> package simple;
>>
>> import org.testng.annotations.Test;
>>
>> public class SecondClass extends BaseClass {
>>
>>      @Test
>>      public void step3() {
>>          System.out.println("***In step3");
>>      }
>>
>>      @Test
>>      public void step4() {
>>          System.out.println("***In step4");
>>      }
>> }
>>
>


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Two Browsers opened when running testng suite

Jeff-351
In reply to this post by Mark Southward

Seems to be working as it should....what is the behavior you want?  TestNG will instantiate your test classes (creating two browser instances...one for each test class) before it starts running tests. 

If you don't want the browsers started by simply instantiating the classes, move the driver initialization code into the @BeforeClass method.

On May 31, 2012 2:35 PM, "Mark Southward" <[hidden email]> wrote:
Hi,
I've tried to set up a simple scenario where my tests are in 2 classes
which extend a baseClass which invokes Firefox webdriver 2. This is in
anticipation of having lots more tests in other classes (albeit with a
little more code). This is run from within Eclipse.

A Firefox browser opens and before navigating to the "home page"
another browser opens. The tests seem to execute ok. I'm sure it will
be my code, I just can't see which bit(s), so if anyone can point it
out to me I would be very grateful!

Thanks for reading,

Mark

The testNG.xml file:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none" >
 <test name="Test" preserve-order="true">
   <classes>
         <class name="simple.FirstClass">
               <methods>
                       <include name="step1"/>
                       <include name="step2"/>
               </methods>
         </class>
         <class name="simple.SecondClass">
               <methods>
                       <include name="step3"/>
                       <include name="step4"/>
               </methods>
         </class>
   </classes>
 </test> <!-- Test -->
</suite> <!-- Suite -->


The base class:-
package simple;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

public class BaseClass {
       WebDriver driver = new FirefoxDriver();

   @BeforeSuite
   public void setup() throws Exception {
       driver.get("http://www.google.com");
   }

   @AfterSuite
   public void tearDown() throws Exception {
       driver.quit();
       }
}

The 1st test class:-
package simple;

import org.testng.annotations.Test;

public class FirstClass extends BaseClass {

         @Test
         public void step1() {
                 System.out.println("***In step1");
         }

         @Test
         public void step2() {
                 System.out.println("***In step2");
         }
}

The 2nd class:-
package simple;

import org.testng.annotations.Test;

public class SecondClass extends BaseClass {

         @Test
         public void step3() {
                 System.out.println("***In step3");
         }

         @Test
         public void step4() {
                 System.out.println("***In step4");
         }
}

The output:-
***In step1
***In step2
***In step3
***In step4

===============================================
Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Two Browsers opened when running testng suite

Jeff-351
In reply to this post by ⇜Krishnan Mahadevan⇝

My phone is having sync issues...did my last response go through?

On May 31, 2012 7:17 PM, "Krishnan Mahadevan" <[hidden email]> wrote:
I dont think either the singleton nor the static approach is going to work. 
Am saying this because both of these approaches although would cause only 1 instance of webdriver it can have catastrophic results on the test itself because now both the classes would be working with the same webdriver which means they both try to perform different operations on the same browser. I think removal of @BeforeSuite and using @BeforeClass would be the right thing. 

The other way would be to move the instantiation part to a separate class, have the instantiation done in a beforeinvocation, save the newly created object in a ThreadLocal variable and then query this variable in the test method. 

On Friday, June 1, 2012, Tomek Kaczanowski wrote:
(a shot in the dark) make driver static perhaps?

--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com


2012/5/31 Raj <[hidden email]>:
> I guess you shud be implementing a singleton pattern to restrict single browser instance....
>
> Thanks,
> Raj
>
> On May 31, 2012, at 1:35 PM, Mark Southward <[hidden email]> wrote:
>
>> Hi,
>> I've tried to set up a simple scenario where my tests are in 2 classes
>> which extend a baseClass which invokes Firefox webdriver 2. This is in
>> anticipation of having lots more tests in other classes (albeit with a
>> little more code). This is run from within Eclipse.
>>
>> A Firefox browser opens and before navigating to the "home page"
>> another browser opens. The tests seem to execute ok. I'm sure it will
>> be my code, I just can't see which bit(s), so if anyone can point it
>> out to me I would be very grateful!
>>
>> Thanks for reading,
>>
>> Mark
>>
>> The testNG.xml file:-
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
>> <suite name="Suite" parallel="none" >
>>  <test name="Test" preserve-order="true">
>>    <classes>
>>      <class name="simple.FirstClass">
>>        <methods>
>>            <include name="step1"/>
>>            <include name="step2"/>
>>        </methods>
>>      </class>
>>      <class name="simple.SecondClass">
>>        <methods>
>>            <include name="step3"/>
>>            <include name="step4"/>
>>        </methods>
>>      </class>
>>    </classes>
>>  </test> <!-- Test -->
>> </suite> <!-- Suite -->
>>
>>
>> The base class:-
>> package simple;
>>
>> import org.openqa.selenium.WebDriver;
>> import org.openqa.selenium.firefox.FirefoxDriver;
>> import org.testng.annotations.AfterSuite;
>> import org.testng.annotations.BeforeSuite;
>>
>> public class BaseClass {
>>    WebDriver driver = new FirefoxDriver();
>>
>>    @BeforeSuite
>>    public void setup() throws Exception {
>>        driver.get("http://www.google.com");
>>    }
>>
>>    @AfterSuite
>>    public void tearDown() throws Exception {
>>        driver.quit();
>>    }
>> }
>>
>> The 1st test class:-
>> package simple;
>>
>> import org.testng.annotations.Test;
>>
>> public class FirstClass extends BaseClass {
>>
>>      @Test
>>      public void step1() {
>>          System.out.println("***In step1");
>>      }
>>
>>      @Test
>>      public void step2() {
>>          System.out.println("***In step2");
>>      }
>> }
>>
>> The 2nd class:-
>> package simple;
>>
>> import org.testng.annotations.Test;
>>
>> public class SecondClass extends BaseClass {
>>
>>      @Test
>>      public void step3() {
>>          System.out.println("***In step3");
>>      }
>>
>>      @Test
>>      public void step4() {
>>          System.out.println("***In step4");
>>      }
>> }
>>
>


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Two Browsers opened when running testng suite

Mark Southward
Thanks for the replies, found them thought provoking.

I've tried the static method and that did indeed only create one
instance of the browser.

I don't have a clear strategy (yet) for how I want this to work
because I (clearly) haven't got a grasp yet of "how it all fits
together". I'm new to Java, testNG, and selenium.

I hadn't realised that a browser will be created for each class (I was
following the blog example from the testNG website)- that could
potentially be a lot of browser instances!

I certainly don't want browsers, running functional tests, working
independantly, all pointing at my webservice at the same time.

At the moment, it seems like having the startup in @BeforeClass is the
way to go.

Jeff - yes, your response came through, thanks.

Thanks,

Mark

On Jun 1, 2:42 am, Jeff <[hidden email]> wrote:

> My phone is having sync issues...did my last response go through?
> On May 31, 2012 7:17 PM, "Krishnan Mahadevan" <
>
>
>
>
>
>
>
> [hidden email]> wrote:
> > I dont think either the singleton nor the static approach is going to
> > work.
> > Am saying this because both of these approaches although would cause only
> > 1 instance of webdriver it can have catastrophic results on the test itself
> > because now both the classes would be working with the same webdriver which
> > means they both try to perform different operations on the same browser. I
> > think removal of @BeforeSuite and using @BeforeClass would be the right
> > thing.
>
> > The other way would be to move the instantiation part to a separate class,
> > have the instantiation done in a beforeinvocation, save the newly created
> > object in a ThreadLocal variable and then query this variable in the test
> > method.
>
> > On Friday, June 1, 2012, Tomek Kaczanowski wrote:
>
> >> (a shot in the dark) make driver static perhaps?
>
> >> --
> >> Regards / Pozdrawiam
> >> Tomek Kaczanowski
> >>http://practicalunittesting.com
>
> >> 2012/5/31 Raj <[hidden email]>:
> >> > I guess you shud be implementing a singleton pattern to restrict single
> >> browser instance....
>
> >> > Thanks,
> >> > Raj
>
> >> > On May 31, 2012, at 1:35 PM, Mark Southward <[hidden email]>
> >> wrote:
>
> >> >> Hi,
> >> >> I've tried to set up a simple scenario where my tests are in 2 classes
> >> >> which extend a baseClass which invokes Firefox webdriver 2. This is in
> >> >> anticipation of having lots more tests in other classes (albeit with a
> >> >> little more code). This is run from within Eclipse.
>
> >> >> A Firefox browser opens and before navigating to the "home page"
> >> >> another browser opens. The tests seem to execute ok. I'm sure it will
> >> >> be my code, I just can't see which bit(s), so if anyone can point it
> >> >> out to me I would be very grateful!
>
> >> >> Thanks for reading,
>
> >> >> Mark
>
> >> >> The testNG.xml file:-
> >> >> <?xml version="1.0" encoding="UTF-8"?>
> >> >> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
> >> >> <suite name="Suite" parallel="none" >
> >> >>  <test name="Test" preserve-order="true">
> >> >>    <classes>
> >> >>      <class name="simple.FirstClass">
> >> >>        <methods>
> >> >>            <include name="step1"/>
> >> >>            <include name="step2"/>
> >> >>        </methods>
> >> >>      </class>
> >> >>      <class name="simple.SecondClass">
> >> >>        <methods>
> >> >>            <include name="step3"/>
> >> >>            <include name="step4"/>
> >> >>        </methods>
> >> >>      </class>
> >> >>    </classes>
> >> >>  </test> <!-- Test -->
> >> >> </suite> <!-- Suite -->
>
> >> >> The base class:-
> >> >> package simple;
>
> >> >> import org.openqa.selenium.WebDriver;
> >> >> import org.openqa.selenium.firefox.FirefoxDriver;
> >> >> import org.testng.annotations.AfterSuite;
> >> >> import org.testng.annotations.BeforeSuite;
>
> >> >> public class BaseClass {
> >> >>    WebDriver driver = new FirefoxDriver();
>
> >> >>    @BeforeSuite
> >> >>    public void setup() throws Exception {
> >> >>        driver.get("http://www.google.com");
> >> >>    }
>
> >> >>    @AfterSuite
> >> >>    public void tearDown() throws Exception {
> >> >>        driver.quit();
> >> >>    }
> >> >> }
>
> >> >> The 1st test class:-
> >> >> package simple;
>
> >> >> import org.testng.annotations.Test;
>
> >> >> public class FirstClass extends BaseClass {
>
> >> >>      @Test
> >> >>      public void step1() {
> >> >>          System.out.println("***In step1");
> >> >>      }
>
> >> >>      @Test
> >> >>      public void step2() {
> >> >>          System.out.println("***In step2");
> >> >>      }
> >> >> }
>
> >> >> The 2nd class:-
> >> >> package simple;
>
> >> >> import org.testng.annotations.Test;
>
> >> >> public class SecondClass extends BaseClass {
>
> >> >>      @Test
> >> >>      public void step3() {
> >> >>          System.out.println("***In step3");
> >> >>      }
>
> >> >>      @Test
> >> >>      public void step4() {
> >> >>          System.out.println("***In step4");
> >> >>      }
> >> >> }
>
> > --
> > Thanks & Regards
> > Krishnan Mahadevan
>
> > "All the desirable things in life are either illegal, expensive, fattening
> > or in love with someone else!"
> > My Scribblings @http://wakened-cognition.blogspot.com/
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email].
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Two Browsers opened when running testng suite

Sumit Terkhedkar

Hi,

I am a bit late in this game, but it seems I am facing the same issue.
Is there anyone here found out the working solution?

I tried all of the mentioned solutions but none of them are working for me.. It is still opening a browser window per test class.

Any help appreciated.

Thanks for reading :)

On Friday, June 1, 2012 at 1:49:03 PM UTC+5:30, Mark Southward wrote:
Thanks for the replies, found them thought provoking.

I've tried the static method and that did indeed only create one
instance of the browser.

I don't have a clear strategy (yet) for how I want this to work
because I (clearly) haven't got a grasp yet of "how it all fits
together". I'm new to Java, testNG, and selenium.

I hadn't realised that a browser will be created for each class (I was
following the blog example from the testNG website)- that could
potentially be a lot of browser instances!

I certainly don't want browsers, running functional tests, working
independantly, all pointing at my webservice at the same time.

At the moment, it seems like having the startup in @BeforeClass is the
way to go.

Jeff - yes, your response came through, thanks.

Thanks,

Mark

On Jun 1, 2:42 am, Jeff <[hidden email]> wrote:

> My phone is having sync issues...did my last response go through?
> On May 31, 2012 7:17 PM, "Krishnan Mahadevan" <
>
>
>
>
>
>
>
> krishnan.mahadevan1...@gmail.com> wrote:
> > I dont think either the singleton nor the static approach is going to
> > work.
> > Am saying this because both of these approaches although would cause only
> > 1 instance of webdriver it can have catastrophic results on the test itself
> > because now both the classes would be working with the same webdriver which
> > means they both try to perform different operations on the same browser. I
> > think removal of @BeforeSuite and using @BeforeClass would be the right
> > thing.
>
> > The other way would be to move the instantiation part to a separate class,
> > have the instantiation done in a beforeinvocation, save the newly created
> > object in a ThreadLocal variable and then query this variable in the test
> > method.
>
> > On Friday, June 1, 2012, Tomek Kaczanowski wrote:
>
> >> (a shot in the dark) make driver static perhaps?
>
> >> --
> >> Regards / Pozdrawiam
> >> Tomek Kaczanowski
> >><a href="http://practicalunittesting.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fpracticalunittesting.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF76Gj3SI1S0RUdA420-QsE96wKyg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fpracticalunittesting.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF76Gj3SI1S0RUdA420-QsE96wKyg&#39;;return true;">http://practicalunittesting.com
>
> >> 2012/5/31 Raj <[hidden email]>:
> >> > I guess you shud be implementing a singleton pattern to restrict single
> >> browser instance....
>
> >> > Thanks,
> >> > Raj
>
> >> > On May 31, 2012, at 1:35 PM, Mark Southward <[hidden email]>
> >> wrote:
>
> >> >> Hi,
> >> >> I've tried to set up a simple scenario where my tests are in 2 classes
> >> >> which extend a baseClass which invokes Firefox webdriver 2. This is in
> >> >> anticipation of having lots more tests in other classes (albeit with a
> >> >> little more code). This is run from within Eclipse.
>
> >> >> A Firefox browser opens and before navigating to the "home page"
> >> >> another browser opens. The tests seem to execute ok. I'm sure it will
> >> >> be my code, I just can't see which bit(s), so if anyone can point it
> >> >> out to me I would be very grateful!
>
> >> >> Thanks for reading,
>
> >> >> Mark
>
> >> >> The testNG.xml file:-
> >> >> <?xml version="1.0" encoding="UTF-8"?>
> >> >> <!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
> >> >> <suite name="Suite" parallel="none" >
> >> >>  <test name="Test" preserve-order="true">
> >> >>    <classes>
> >> >>      <class name="simple.FirstClass">
> >> >>        <methods>
> >> >>            <include name="step1"/>
> >> >>            <include name="step2"/>
> >> >>        </methods>
> >> >>      </class>
> >> >>      <class name="simple.SecondClass">
> >> >>        <methods>
> >> >>            <include name="step3"/>
> >> >>            <include name="step4"/>
> >> >>        </methods>
> >> >>      </class>
> >> >>    </classes>
> >> >>  </test> <!-- Test -->
> >> >> </suite> <!-- Suite -->
>
> >> >> The base class:-
> >> >> package simple;
>
> >> >> import org.openqa.selenium.WebDriver;
> >> >> import org.openqa.selenium.firefox.FirefoxDriver;
> >> >> import org.testng.annotations.AfterSuite;
> >> >> import org.testng.annotations.BeforeSuite;
>
> >> >> public class BaseClass {
> >> >>    WebDriver driver = new FirefoxDriver();
>
> >> >>    @BeforeSuite
> >> >>    public void setup() throws Exception {
> >> >>        driver.get("<a href="http://www.google.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com&#39;;return true;" onclick="this.href=&#39;http://www.google.com&#39;;return true;">http://www.google.com");
> >> >>    }
>
> >> >>    @AfterSuite
> >> >>    public void tearDown() throws Exception {
> >> >>        driver.quit();
> >> >>    }
> >> >> }
>
> >> >> The 1st test class:-
> >> >> package simple;
>
> >> >> import org.testng.annotations.Test;
>
> >> >> public class FirstClass extends BaseClass {
>
> >> >>      @Test
> >> >>      public void step1() {
> >> >>          System.out.println("***In step1");
> >> >>      }
>
> >> >>      @Test
> >> >>      public void step2() {
> >> >>          System.out.println("***In step2");
> >> >>      }
> >> >> }
>
> >> >> The 2nd class:-
> >> >> package simple;
>
> >> >> import org.testng.annotations.Test;
>
> >> >> public class SecondClass extends BaseClass {
>
> >> >>      @Test
> >> >>      public void step3() {
> >> >>          System.out.println("***In step3");
> >> >>      }
>
> >> >>      @Test
> >> >>      public void step4() {
> >> >>          System.out.println("***In step4");
> >> >>      }
> >> >> }
>
> > --
> > Thanks & Regards
> > Krishnan Mahadevan
>
> > "All the desirable things in life are either illegal, expensive, fattening
> > or in love with someone else!"
> > My Scribblings @<a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="z7Og1wZoPm4J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
> > To unsubscribe from this group, send email to
> > <a href="javascript:" target="_blank" gdf-obfuscated-mailto="z7Og1wZoPm4J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
> > For more options, visit this group at
> ><a href="http://groups.google.com/group/testng-users?hl=en" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;">http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.