FAQ
Hi

I'm not sure if this is the right place for this, but since Selenium is
involved I'm hoping someone can offer some advice!

Our test framework uses a combination of Selenium, Concordion and JUnit to
run browser based tests. Due to the way the framework was designed, each
'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

The problem we have with this is that Selenium opens a new browser instance
for every *Test.java file that JUnit runs, and closes it again at the end
of the test. We have around 1900 tests, each in their own class, which
means Selenium opening and closing Firefox over 1900 times for a full test
run. This wastes a huge amount of time essentially doing nothing (our test
suite currently takes around 8 hours for a full run).

I was hoping to use @BeforeClass to get Selenium to open a browser once,
then re-use that for every test in the suite, then using @AfterClass to
close the browser again at the end. But both @BeforeClass/@AfterClass
assume that methods marked with @Test all reside in the same class file,
which makes sense up to a point (though having 1900 @Test methods inside a
single class would be unwieldy).

The problem is, with our test suite, there's only a single @Test method in
each class file, so @BeforeClass/@AfterClass doesn't make any difference
and the browser still opens/closes with every test file.

Firstly, how do you work around this, or are you stuck in the same position
with hundreds of individual browser executions when running a suite? Or is
there a way to get JUnit to run some code before and after all of the
testing has happened (and obviously within the same JVM instance as the
tests themselves, so the WebDriver instance can be kept statically and
shared across all tests)?

I'd be grateful for any suggestions you have - our framework is due for a
complete rewrite anyway, its a few years old and breaking apart at the
seams, but without any time or resource to rewrite it any suggestions for
code improvements which reduce the running time would be greatly
appreciated!

Thanks
Ian

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/45EiaysS_WMJ.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Search Discussions

  • Mark Collin at May 17, 2012 at 1:52 pm
    Looks like a job for reflection.



    This may provide some pointers:



    https://github.com/Ardesco/Ebselen/blob/master/ebselen-tests/src/main/java/c
    om/lazerycode/ebselen/SeleniumJUnitRunner.java



    Short Link
    <https://github.com/Ardesco/Ebselen/blob/master/ebselen-tests/src/main/java/
    com/lazerycode/ebselen/SeleniumJUnitRunner.java>



    Basically I'm using reflection to get test names from a java class and build
    up a test suite which I can then run. You should be able to tweak this a
    bit and pull tests out from multiple classes.



    The code may be a bit messy, I haven't looked at it for quite some time. It
    could probably do with a bit of a refactor J



    From: selenium-users@googlegroups.com
    On Behalf Of ikent
    Sent: 17 May 2012 14:25
    To: selenium-users@googlegroups.com
    Subject: [selenium-users] Selenium, Concordion and JUnit



    Hi



    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!



    Our test framework uses a combination of Selenium, Concordion and JUnit to
    run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).



    The problem we have with this is that Selenium opens a new browser instance
    for every *Test.java file that JUnit runs, and closes it again at the end of
    the test. We have around 1900 tests, each in their own class, which means
    Selenium opening and closing Firefox over 1900 times for a full test run.
    This wastes a huge amount of time essentially doing nothing (our test suite
    currently takes around 8 hours for a full run).



    I was hoping to use @BeforeClass to get Selenium to open a browser once,
    then re-use that for every test in the suite, then using @AfterClass to
    close the browser again at the end. But both @BeforeClass/@AfterClass assume
    that methods marked with @Test all reside in the same class file, which
    makes sense up to a point (though having 1900 @Test methods inside a single
    class would be unwieldy).



    The problem is, with our test suite, there's only a single @Test method in
    each class file, so @BeforeClass/@AfterClass doesn't make any difference and
    the browser still opens/closes with every test file.



    Firstly, how do you work around this, or are you stuck in the same position
    with hundreds of individual browser executions when running a suite? Or is
    there a way to get JUnit to run some code before and after all of the
    testing has happened (and obviously within the same JVM instance as the
    tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?



    I'd be grateful for any suggestions you have - our framework is due for a
    complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!



    Thanks

    Ian

    --
    You received this message because you are subscribed to the Google Groups
    "Selenium Users" group.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/selenium-users/-/45EiaysS_WMJ.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/selenium-users?hl=en.

    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Krishnan Mahadevan at May 17, 2012 at 2:50 pm
    Would this thread help ?

    http://stackoverflow.com/questions/82949/before-and-after-suite-execution-hook-in-junit-4-x#177069


    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive, fattening
    or in love with someone else!"


    On Thu, May 17, 2012 at 7:22 PM, Mark Collin
    wrote:
    Looks like a job for reflection.****

    ** **

    This may provide some pointers:****

    ** **


    https://github.com/Ardesco/Ebselen/blob/master/ebselen-tests/src/main/java/com/lazerycode/ebselen/SeleniumJUnitRunner.java
    ****

    ** **

    Short Link<https://github.com/Ardesco/Ebselen/blob/master/ebselen-tests/src/main/java/com/lazerycode/ebselen/SeleniumJUnitRunner.java>
    ****

    ** **

    Basically I’m using reflection to get test names from a java class and
    build up a test suite which I can then run. You should be able to tweak
    this a bit and pull tests out from multiple classes.****

    ** **

    The code may be a bit messy, I haven’t looked at it for quite some time.
    It could probably do with a bit of a refactor J****

    ** **

    *From:* selenium-users@googlegroups.com [mailto:
    selenium-users@googlegroups.com] *On Behalf Of *ikent
    *Sent:* 17 May 2012 14:25
    *To:* selenium-users@googlegroups.com
    *Subject:* [selenium-users] Selenium, Concordion and JUnit****

    ** **

    Hi****

    ** **

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!****

    ** **

    Our test framework uses a combination of Selenium, Concordion and JUnit to
    run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).****

    ** **

    The problem we have with this is that Selenium opens a new browser
    instance for every *Test.java file that JUnit runs, and closes it again at
    the end of the test. We have around 1900 tests, each in their own class,
    which means Selenium opening and closing Firefox over 1900 times for a full
    test run. This wastes a huge amount of time essentially doing nothing (our
    test suite currently takes around 8 hours for a full run).****

    ** **

    I was hoping to use @BeforeClass to get Selenium to open a browser once,
    then re-use that for every test in the suite, then using @AfterClass to
    close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).****

    ** **

    The problem is, with our test suite, there's only a single @Test method in
    each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.****

    ** **

    Firstly, how do you work around this, or are you stuck in the same
    position with hundreds of individual browser executions when running a
    suite? Or is there a way to get JUnit to run some code before and after all
    of the testing has happened (and obviously within the same JVM instance as
    the tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?****

    ** **

    I'd be grateful for any suggestions you have - our framework is due for a
    complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!****

    ** **

    Thanks****

    Ian****

    --
    You received this message because you are subscribed to the Google Groups
    "Selenium Users" group.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/selenium-users/-/45EiaysS_WMJ.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/selenium-users?hl=en.****

    --
    You received this message because you are subscribed to the Google Groups
    "Selenium Users" group.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/selenium-users?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Raju at May 17, 2012 at 7:34 pm
    Try this, This might help.

    Step 1:-

    Create a SUITE class and call all tests from there, Example

    package TestPkg1;
    import org.junit.runner.RunWith;
    import org.junit.runners.Suite;
    //Specify a runner class.
    @RunWith(Suite.class)
    //Specify an array of test classes.
    @Suite.SuiteClasses( {
    LogInToTheApplication.class,
    <----------------------- Here only Browser Open and log In should
    present
    TestScript1.class,
    <----------------------- This is actualt Test case, Keep only @Test
    methods, remove @Before method from here and move to the 1st class,
    but You need to refer same webdriver instance here
    TestScript2.class,
    ..... etc etc etc
    TearDown.class
    <------------------------- only Browse close.

    }
    )
    public class _RunSuite
    {
    }

    Step2 -

    In Test Scripts remove @Before and @After methods

    Second method -

    If you feel doing above changes is difficult in all 1900 test scripts,
    then you can do another way, Remove ( or keep a check to skip ) all
    @After 's in all test scripts, and add a check in @Before method
    before assigning the browser, check If webdriver browser instance is
    already active ( not null ) then do not assign the browser again, if
    it not active then assign the browser.


    Actually correct way is to implement both first method and second
    method together so that it will be more robust.


    Thanks
    Raju




    On May 17, 9:25 am, ikent wrote:
    Hi

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!

    Our test framework uses a combination of Selenium, Concordion and JUnit to
    run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

    The problem we have with this is that Selenium opens a new browser instance
    for every *Test.java file that JUnit runs, and closes it again at the end
    of the test. We have around 1900 tests, each in their own class, which
    means Selenium opening and closing Firefox over 1900 times for a full test
    run. This wastes a huge amount of time essentially doing nothing (our test
    suite currently takes around 8 hours for a full run).

    I was hoping to use @BeforeClass to get Selenium to open a browser once,
    then re-use that for every test in the suite, then using @AfterClass to
    close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).

    The problem is, with our test suite, there's only a single @Test method in
    each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.

    Firstly, how do you work around this, or are you stuck in the same position
    with hundreds of individual browser executions when running a suite? Or is
    there a way to get JUnit to run some code before and after all of the
    testing has happened (and obviously within the same JVM instance as the
    tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?

    I'd be grateful for any suggestions you have - our framework is due for a
    complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!

    Thanks
    Ian
    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Ikent at May 18, 2012 at 6:55 am
    Thank you all

    I'll have a play around with it today and see what I can come up with, I
    think refactoring everything to use suite classes looks like the better
    option - thankfully since everything inherits from the same base class,
    removing the existing @Before and @Afters should be relatively easy.

    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/csxTo_29rw4J.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Varun Menon at May 18, 2012 at 12:45 pm
    I went through all the replies that are posted and all of them requires you
    to tweak your code, or create a suite for your classes.
    As your requirement is to start the browser at the start of the suite and
    use the same across all your tests. I thought of the following solution:

    - Create a static instance of your selenium object.
    - In the before method just check that selenium object is initialized and
    the browser is open, if false initialize the selenium object and open the
    browser.
    - Dont destroy the selenium object in after method.

    I haven't implemented the above solution, but I think it fulfills your
    requirement. The only problem that I see is selenium object is not
    destroyed at the end of your suite execution.

    Varun
    http://imaginea.github.com/bot-bot/

    On Thursday, May 17, 2012 6:55:23 PM UTC+5:30, ikent wrote:

    Hi

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!

    Our test framework uses a combination of Selenium, Concordion and JUnit to
    run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

    The problem we have with this is that Selenium opens a new browser
    instance for every *Test.java file that JUnit runs, and closes it again at
    the end of the test. We have around 1900 tests, each in their own class,
    which means Selenium opening and closing Firefox over 1900 times for a full
    test run. This wastes a huge amount of time essentially doing nothing (our
    test suite currently takes around 8 hours for a full run).

    I was hoping to use @BeforeClass to get Selenium to open a browser once,
    then re-use that for every test in the suite, then using @AfterClass to
    close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).

    The problem is, with our test suite, there's only a single @Test method in
    each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.

    Firstly, how do you work around this, or are you stuck in the same
    position with hundreds of individual browser executions when running a
    suite? Or is there a way to get JUnit to run some code before and after all
    of the testing has happened (and obviously within the same JVM instance as
    the tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?

    I'd be grateful for any suggestions you have - our framework is due for a
    complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!

    Thanks
    Ian
    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/b04Y8EJlgS4J.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Krishnan Mahadevan at May 18, 2012 at 12:49 pm
    In short it sounds as if your recommendation is moving towards a Singleton
    class which provides a mechanism to create (via the first call to the
    createInstance() method in the Singleton and destroy the Selenium
    instance using :
    http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)
    so
    that the JVM automatically takes care of ensuring that the selenium
    instance is destroyed as well ?

    Although am not vouching for it as a good design... but just an ugly hack
    to a problem !

    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive, fattening
    or in love with someone else!"

    On Fri, May 18, 2012 at 6:15 PM, Varun Menon wrote:

    I went through all the replies that are posted and all of them requires
    you to tweak your code, or create a suite for your classes.
    As your requirement is to start the browser at the start of the suite and
    use the same across all your tests. I thought of the following solution:

    - Create a static instance of your selenium object.
    - In the before method just check that selenium object is initialized and
    the browser is open, if false initialize the selenium object and open the
    browser.
    - Dont destroy the selenium object in after method.

    I haven't implemented the above solution, but I think it fulfills your
    requirement. The only problem that I see is selenium object is not
    destroyed at the end of your suite execution.

    Varun
    http://imaginea.github.com/bot-bot/

    On Thursday, May 17, 2012 6:55:23 PM UTC+5:30, ikent wrote:

    Hi

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!

    Our test framework uses a combination of Selenium, Concordion and JUnit
    to run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

    The problem we have with this is that Selenium opens a new browser
    instance for every *Test.java file that JUnit runs, and closes it again at
    the end of the test. We have around 1900 tests, each in their own class,
    which means Selenium opening and closing Firefox over 1900 times for a full
    test run. This wastes a huge amount of time essentially doing nothing (our
    test suite currently takes around 8 hours for a full run).

    I was hoping to use @BeforeClass to get Selenium to open a browser once,
    then re-use that for every test in the suite, then using @AfterClass to
    close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).

    The problem is, with our test suite, there's only a single @Test method
    in each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.

    Firstly, how do you work around this, or are you stuck in the same
    position with hundreds of individual browser executions when running a
    suite? Or is there a way to get JUnit to run some code before and after all
    of the testing has happened (and obviously within the same JVM instance as
    the tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?

    I'd be grateful for any suggestions you have - our framework is due for a
    complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!

    Thanks
    Ian
    --
    You received this message because you are subscribed to the Google Groups
    "Selenium Users" group.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/selenium-users/-/b04Y8EJlgS4J.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/selenium-users?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Varun Menon at May 18, 2012 at 1:27 pm
    Hi Krishnan,

    I also accepts that Singleton pattern and use of static variables is not a
    good approach in few scenarios while developing a automation framework, ex
    parallel execution.
    As the current framework is using Junit and a sequential execution the hack
    fits in.

    The approach of creating a suite is a good one, the only thing to watch
    will be adding 1900 test classes at runtime using reflection to the suite.

    Regards
    Varun

    On Friday, May 18, 2012 6:19:54 PM UTC+5:30, Krishnan wrote:

    In short it sounds as if your recommendation is moving towards a Singleton
    class which provides a mechanism to create (via the first call to the
    createInstance() method in the Singleton and destroy the Selenium
    instance using :
    http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread) so
    that the JVM automatically takes care of ensuring that the selenium
    instance is destroyed as well ?

    Although am not vouching for it as a good design... but just an ugly hack
    to a problem !

    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive, fattening
    or in love with someone else!"

    On Fri, May 18, 2012 at 6:15 PM, Varun Menon wrote:

    I went through all the replies that are posted and all of them requires
    you to tweak your code, or create a suite for your classes.
    As your requirement is to start the browser at the start of the suite and
    use the same across all your tests. I thought of the following solution:

    - Create a static instance of your selenium object.
    - In the before method just check that selenium object is initialized and
    the browser is open, if false initialize the selenium object and open the
    browser.
    - Dont destroy the selenium object in after method.

    I haven't implemented the above solution, but I think it fulfills your
    requirement. The only problem that I see is selenium object is not
    destroyed at the end of your suite execution.

    Varun
    http://imaginea.github.com/bot-bot/

    On Thursday, May 17, 2012 6:55:23 PM UTC+5:30, ikent wrote:

    Hi

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!

    Our test framework uses a combination of Selenium, Concordion and JUnit
    to run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

    The problem we have with this is that Selenium opens a new browser
    instance for every *Test.java file that JUnit runs, and closes it again at
    the end of the test. We have around 1900 tests, each in their own class,
    which means Selenium opening and closing Firefox over 1900 times for a full
    test run. This wastes a huge amount of time essentially doing nothing (our
    test suite currently takes around 8 hours for a full run).

    I was hoping to use @BeforeClass to get Selenium to open a browser once,
    then re-use that for every test in the suite, then using @AfterClass to
    close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).

    The problem is, with our test suite, there's only a single @Test method
    in each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.

    Firstly, how do you work around this, or are you stuck in the same
    position with hundreds of individual browser executions when running a
    suite? Or is there a way to get JUnit to run some code before and after all
    of the testing has happened (and obviously within the same JVM instance as
    the tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?

    I'd be grateful for any suggestions you have - our framework is due for
    a complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!

    Thanks
    Ian
    --
    You received this message because you are subscribed to the Google Groups
    "Selenium Users" group.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/selenium-users/-/b04Y8EJlgS4J.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/selenium-users?hl=en.

    On Friday, May 18, 2012 6:19:54 PM UTC+5:30, Krishnan wrote:

    In short it sounds as if your recommendation is moving towards a Singleton
    class which provides a mechanism to create (via the first call to the
    createInstance() method in the Singleton and destroy the Selenium
    instance using :
    http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread) so
    that the JVM automatically takes care of ensuring that the selenium
    instance is destroyed as well ?

    Although am not vouching for it as a good design... but just an ugly hack
    to a problem !

    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive, fattening
    or in love with someone else!"

    On Fri, May 18, 2012 at 6:15 PM, Varun Menon wrote:

    I went through all the replies that are posted and all of them requires
    you to tweak your code, or create a suite for your classes.
    As your requirement is to start the browser at the start of the suite and
    use the same across all your tests. I thought of the following solution:

    - Create a static instance of your selenium object.
    - In the before method just check that selenium object is initialized and
    the browser is open, if false initialize the selenium object and open the
    browser.
    - Dont destroy the selenium object in after method.

    I haven't implemented the above solution, but I think it fulfills your
    requirement. The only problem that I see is selenium object is not
    destroyed at the end of your suite execution.

    Varun
    http://imaginea.github.com/bot-bot/

    On Thursday, May 17, 2012 6:55:23 PM UTC+5:30, ikent wrote:

    Hi

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!

    Our test framework uses a combination of Selenium, Concordion and JUnit
    to run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

    The problem we have with this is that Selenium opens a new browser
    instance for every *Test.java file that JUnit runs, and closes it again at
    the end of the test. We have around 1900 tests, each in their own class,
    which means Selenium opening and closing Firefox over 1900 times for a full
    test run. This wastes a huge amount of time essentially doing nothing (our
    test suite currently takes around 8 hours for a full run).

    I was hoping to use @BeforeClass to get Selenium to open a browser once,
    then re-use that for every test in the suite, then using @AfterClass to
    close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).

    The problem is, with our test suite, there's only a single @Test method
    in each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.

    Firstly, how do you work around this, or are you stuck in the same
    position with hundreds of individual browser executions when running a
    suite? Or is there a way to get JUnit to run some code before and after all
    of the testing has happened (and obviously within the same JVM instance as
    the tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?

    I'd be grateful for any suggestions you have - our framework is due for
    a complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!

    Thanks
    Ian
    --
    You received this message because you are subscribed to the Google Groups
    "Selenium Users" group.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/selenium-users/-/b04Y8EJlgS4J.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/selenium-users?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/nv2-f6dXTXsJ.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Krishnan Mahadevan at May 18, 2012 at 1:29 pm
    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive, fattening
    or in love with someone else!"


    On Fri, May 18, 2012 at 6:57 PM, Varun Menon wrote:

    Hi Krishnan,

    I also accepts that Singleton pattern and use of static variables is not a
    good approach in few scenarios while developing a automation framework, ex
    parallel execution.
    As the current framework is using Junit and a sequential execution the
    hack fits in.

    The approach of creating a suite is a good one, the only thing to watch
    will be adding 1900 test classes at runtime using reflection to the suite.
    Am assuming that the loading of so many classes at runtime via Reflection
    is also going to be done sequentially since you did mention about
    "Sequential execution". Is that a fair statement ?


    Regards
    Varun

    On Friday, May 18, 2012 6:19:54 PM UTC+5:30, Krishnan wrote:

    In short it sounds as if your recommendation is moving towards a
    Singleton class which provides a mechanism to create (via the first call to
    the createInstance() method in the Singleton and destroy the Selenium
    instance using : http://docs.oracle.com/**javase/1.5.0/docs/api/java/**
    lang/Runtime.html#**addShutdownHook(java.lang.**Thread)<http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)> so
    that the JVM automatically takes care of ensuring that the selenium
    instance is destroyed as well ?

    Although am not vouching for it as a good design... but just an ugly hack
    to a problem !

    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive,
    fattening or in love with someone else!"

    On Fri, May 18, 2012 at 6:15 PM, Varun Menon wrote:

    I went through all the replies that are posted and all of them requires
    you to tweak your code, or create a suite for your classes.
    As your requirement is to start the browser at the start of the suite
    and use the same across all your tests. I thought of the following solution:

    - Create a static instance of your selenium object.
    - In the before method just check that selenium object is initialized
    and the browser is open, if false initialize the selenium object and open
    the browser.
    - Dont destroy the selenium object in after method.

    I haven't implemented the above solution, but I think it fulfills your
    requirement. The only problem that I see is selenium object is not
    destroyed at the end of your suite execution.

    Varun
    http://imaginea.github.com/**bot-bot/<http://imaginea.github.com/bot-bot/>

    On Thursday, May 17, 2012 6:55:23 PM UTC+5:30, ikent wrote:

    Hi

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!

    Our test framework uses a combination of Selenium, Concordion and JUnit
    to run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

    The problem we have with this is that Selenium opens a new browser
    instance for every *Test.java file that JUnit runs, and closes it again at
    the end of the test. We have around 1900 tests, each in their own class,
    which means Selenium opening and closing Firefox over 1900 times for a full
    test run. This wastes a huge amount of time essentially doing nothing (our
    test suite currently takes around 8 hours for a full run).

    I was hoping to use @BeforeClass to get Selenium to open a browser
    once, then re-use that for every test in the suite, then using @AfterClass
    to close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).

    The problem is, with our test suite, there's only a single @Test method
    in each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.

    Firstly, how do you work around this, or are you stuck in the same
    position with hundreds of individual browser executions when running a
    suite? Or is there a way to get JUnit to run some code before and after all
    of the testing has happened (and obviously within the same JVM instance as
    the tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?

    I'd be grateful for any suggestions you have - our framework is due for
    a complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!

    Thanks
    Ian
    --
    You received this message because you are subscribed to the Google
    Groups "Selenium Users" group.
    To view this discussion on the web visit https://groups.google.com/d/**
    msg/selenium-users/-/**b04Y8EJlgS4J<https://groups.google.com/d/msg/selenium-users/-/b04Y8EJlgS4J>
    .
    To post to this group, send email to selenium-users@googlegroups.**com<selenium-users@googlegroups.com>
    .
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@**googlegroups.com<selenium-users%2Bunsubscribe@googlegroups.com>
    .
    For more options, visit this group at http://groups.google.com/**
    group/selenium-users?hl=en<http://groups.google.com/group/selenium-users?hl=en>
    .

    On Friday, May 18, 2012 6:19:54 PM UTC+5:30, Krishnan wrote:

    In short it sounds as if your recommendation is moving towards a
    Singleton class which provides a mechanism to create (via the first call to
    the createInstance() method in the Singleton and destroy the Selenium
    instance using : http://docs.oracle.com/**javase/1.5.0/docs/api/java/**
    lang/Runtime.html#**addShutdownHook(java.lang.**Thread)<http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)> so
    that the JVM automatically takes care of ensuring that the selenium
    instance is destroyed as well ?

    Although am not vouching for it as a good design... but just an ugly hack
    to a problem !

    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive,
    fattening or in love with someone else!"

    On Fri, May 18, 2012 at 6:15 PM, Varun Menon wrote:

    I went through all the replies that are posted and all of them requires
    you to tweak your code, or create a suite for your classes.
    As your requirement is to start the browser at the start of the suite
    and use the same across all your tests. I thought of the following solution:

    - Create a static instance of your selenium object.
    - In the before method just check that selenium object is initialized
    and the browser is open, if false initialize the selenium object and open
    the browser.
    - Dont destroy the selenium object in after method.

    I haven't implemented the above solution, but I think it fulfills your
    requirement. The only problem that I see is selenium object is not
    destroyed at the end of your suite execution.

    Varun
    http://imaginea.github.com/**bot-bot/<http://imaginea.github.com/bot-bot/>

    On Thursday, May 17, 2012 6:55:23 PM UTC+5:30, ikent wrote:

    Hi

    I'm not sure if this is the right place for this, but since Selenium is
    involved I'm hoping someone can offer some advice!

    Our test framework uses a combination of Selenium, Concordion and JUnit
    to run browser based tests. Due to the way the framework was designed, each
    'test' has its own *Test.java file (e.g. /src/spec/SomeWebTest.java) which
    all inherit from the same class (e.g. /src/spec/BaseWebTest.java).

    The problem we have with this is that Selenium opens a new browser
    instance for every *Test.java file that JUnit runs, and closes it again at
    the end of the test. We have around 1900 tests, each in their own class,
    which means Selenium opening and closing Firefox over 1900 times for a full
    test run. This wastes a huge amount of time essentially doing nothing (our
    test suite currently takes around 8 hours for a full run).

    I was hoping to use @BeforeClass to get Selenium to open a browser
    once, then re-use that for every test in the suite, then using @AfterClass
    to close the browser again at the end. But both @BeforeClass/@AfterClass
    assume that methods marked with @Test all reside in the same class file,
    which makes sense up to a point (though having 1900 @Test methods inside a
    single class would be unwieldy).

    The problem is, with our test suite, there's only a single @Test method
    in each class file, so @BeforeClass/@AfterClass doesn't make any difference
    and the browser still opens/closes with every test file.

    Firstly, how do you work around this, or are you stuck in the same
    position with hundreds of individual browser executions when running a
    suite? Or is there a way to get JUnit to run some code before and after all
    of the testing has happened (and obviously within the same JVM instance as
    the tests themselves, so the WebDriver instance can be kept statically and
    shared across all tests)?

    I'd be grateful for any suggestions you have - our framework is due for
    a complete rewrite anyway, its a few years old and breaking apart at the
    seams, but without any time or resource to rewrite it any suggestions for
    code improvements which reduce the running time would be greatly
    appreciated!

    Thanks
    Ian
    --
    You received this message because you are subscribed to the Google
    Groups "Selenium Users" group.
    To view this discussion on the web visit https://groups.google.com/d/**
    msg/selenium-users/-/**b04Y8EJlgS4J<https://groups.google.com/d/msg/selenium-users/-/b04Y8EJlgS4J>
    .
    To post to this group, send email to selenium-users@googlegroups.**com<selenium-users@googlegroups.com>
    .
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@**googlegroups.com<selenium-users%2Bunsubscribe@googlegroups.com>
    .
    For more options, visit this group at http://groups.google.com/**
    group/selenium-users?hl=en<http://groups.google.com/group/selenium-users?hl=en>
    .
    --
    You received this message because you are subscribed to the Google Groups
    "Selenium Users" group.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/selenium-users/-/nv2-f6dXTXsJ.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to
    selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/selenium-users?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
  • Ikent at May 24, 2012 at 7:13 am
    I ended up going with a mixture of your suggestions:

    - I've moved tests into suites instead of using file inclusion patterns
    in Maven
    - I've created a BrowserUtil class with static methods to retrieve a
    browser instance (it takes care of creating a new instance or returning an
    existing instance as appropriate)
    - I've made all Suite classes inherit from a BaseSuite class
    - The BaseSuite class has an @AfterClass annotated method which calls a
    cleanUp method on the BrowserUtil class, calling quit() on any remaining
    browser instances, which gets called just once at the very end of a test
    run (since they're now executed by JUnit in one go)

    This seems to do the trick - its not ideal (inclusion patterns let us be
    lazy about which tests to run, test suites mean we have to be more
    explicit), but I think its a good short-term solution until we get around
    to that rewrite!

    Thanks again for all your help :)

    --
    You received this message because you are subscribed to the Google Groups "Selenium Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/hRuhu_B2nnkJ.
    To post to this group, send email to selenium-users@googlegroups.com.
    To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupselenium-users @
categoriesselenium
postedMay 17, '12 at 1:25p
activeMay 24, '12 at 7:13a
posts10
users5
websiteseleniumhq.org

People

Translate

site design / logo © 2022 Grokbase