Pages

Search This Blog

Wednesday, August 18, 2010

How to create test suite using Junit and eclipse in selenium

There are some scenarios where we need to run multiple test cases. Either we can run those test cases independently or together. But there are some real time cases where we need to run our test cases in a particular order. In this case we would prefer Test Suite to combine the test cases together and decide their orders and run those.


Below are the steps

1. Create a Test Suite class where we create the Test Suites which will call all the test cases in a particular order.

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;  
import junit.textui.TestRunner;

public class TestSuite1 extends TestCase {

public static Test suite()  
{  
TestSuite suite = new TestSuite();  

suite.addTestSuite( TestCase1.class);  
suite.addTestSuite( TestCase2.class);
suite.addTestSuite( TestCase3.class);  
return suite;  
}  

public static void main(String arg[])
{
TestRunner.run(suite());

}
}


Step 2. Create your first test case

import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.*;
public class TestCase1 extends SeleneseTestCase{

Selenium selenium;
public static final String MAX_WAIT_TIME_IN_MS="60000";
private SeleniumServer seleniumServer;

public void setUp() throws Exception {

RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setSingleWindow(true);
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
seleniumServer.start();
selenium.start();

}
public void testgoogling() {
selenium.open("/");
selenium.type("q", "Niraj");
selenium.click("btnG");
selenium.waitForPageToLoad(MAX_WAIT_TIME_IN_MS);
assertTrue(selenium.isTextPresent("Niraj"));

}

public void tearDown() throws InterruptedException{
selenium.stop(); 
seleniumServer.stop();
}
}

Step 3. Create your second test case

import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.*;
public class TestCase2 extends SeleneseTestCase{
Selenium selenium;
public static final String MAX_WAIT_TIME_IN_MS="60000";
private SeleniumServer seleniumServer;
public void setUp() throws Exception {

RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setSingleWindow(true);
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
seleniumServer.start();
selenium.start();
}

public void testgoogling() {
selenium.open("/");
selenium.type("q", "Niraj Kumar");
selenium.click("btnG");
selenium.waitForPageToLoad(MAX_WAIT_TIME_IN_MS);
assertTrue(selenium.isTextPresent("Niraj Kumar"));

}

public void tearDown() throws InterruptedException{
selenium.stop(); 
seleniumServer.stop();
}
}


Step 4. Create your third test case

import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.*;
public class TestCase3 extends SeleneseTestCase{
Selenium selenium;
public static final String MAX_WAIT_TIME_IN_MS="60000";
private SeleniumServer seleniumServer;
public void setUp() throws Exception {

RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setSingleWindow(true);
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
seleniumServer.start();
selenium.start();
}

public void testgoogling() {
selenium.open("/");
selenium.type("q", "http://www.automationtricks.blogspot.com");
selenium.click("btnG");
selenium.waitForPageToLoad(MAX_WAIT_TIME_IN_MS);
assertTrue(selenium.isTextPresent("http://www.automationtricks.blogspot.com"));

}

public void tearDown() throws InterruptedException{
selenium.stop(); 
seleniumServer.stop(); 
}
}

Step 5. Run your Test Suite
Go to your Test Suite class and right click on that and run as Junit Test.

This will run the TestCase1 then TestCase2 then TestCase3


If you want to execute your test cases in some specific order then you call them in that order like.

suite.addTestSuite( TestCase3.class);  
suite.addTestSuite( TestCase2.class);
suite.addTestSuite( TestCase1.class);  

Above will run the TestCase3 first then TestCase2 then TestCase1.

80 comments:

  1. when i follow the same suggested steps then:::::::::::
    i got ..........

    junit.framework.AssertionFailedError: No tests found in testsuiteforall
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    ReplyDelete
  2. Getting a syntax error when adding the test cases to the test suite using suite.addTestSuite, is the test suite supposed to be in the same pakage where the test cases are?, please advise

    ReplyDelete
  3. i am running the following code but i get error "The method addTestSuite(Class) in the type TestSuite is not applicable for the arguments (Class)"

    can i have the solution for that.
    Thanks in advance.
    Sanwal
    .....................
    import junit.framework.Test;
    import junit.framework.TestCase;
    import junit.framework.TestSuite;
    import junit.textui.TestRunner;



    public class TestSuite1 extends TestCase {


    public static Test suite()
    {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(TestCase1.class);
    suite.addTestSuite(TestCase2.class);
    suite.addTestSuite(TestCase3.class);
    return suite;
    }

    public static void main(String[] args)
    {
    junit.textui.TestRunner.run(suite());
    }


    }

    ReplyDelete
  4. Great job man! It really helped me out. Thanks a lot!

    ReplyDelete
  5. An infοrmatiοn and instгuctiοnal site foг the
    home pizza сook. When уou are bakіng
    bread, уou сan rаise the brеad dough in the cold oѵen anԁ then just tuгn on the oven
    to thе coгrect temperatuге once the breaԁ
    іs raiѕеԁ. Roll each portiοn іnto
    the thicκness of a bгοom
    handle.

    my weblοg http://blog.bitcomet.com/

    ReplyDelete
  6. Hi mates, its fantastic piece of writing concerning teachingand entirely explained,
    keep it up all the time.

    my weblog ... http://goliterature.info/

    ReplyDelete
  7. hi my name is veena, i tried the above mentioned way,i am getting the output but each test cases are executing two times. please help me to solve this problem

    ReplyDelete
    Replies
    1. Hi Mam,
      Please tell me how you run, becouse i have error on suite.addTest( TestCase1.class);
      suite.addTestSuite( TestCase2.class);
      suite.addTestSuite( TestCase3.class);

      Delete
  8. analyѕt І fеeling that there are non-ratіonal fοrces at deliѵer the
    results. Тhen there arе experts аnd other anxіοus eѵeryԁаy people ωho
    arе seemingly pгеѵenting а drοppіng bаttle
    to ѕtem the tіԁe princіpal toward environmentаl Аrmageԁdon or as thе tіtle of this
    posting calls it "Warmageddon. A full grain breakfast of outdated-fashioned oatmeal with almonds (grind them up to cover them, if necessary) will keep a kid way for a longer time than orange juice and a bagel.

    my website; old stone oven

    ReplyDelete
  9. I don't know whether it's just me or if eνerуbodу elѕe еnсountering іssuеs with your webѕitе.
    It seems lіke ѕomе of thе text in youг posts are running off the sсгeen.
    Сan somebodу else pleаse proviԁe fеedback аnd let me knoω if thіs is haρρening tо them toο?
    This may be a problеm with mу іnternet brοwser because І've had this happen previously. Cheers

    Also visit my web-site ... augenoperation

    ReplyDelete
  10. Hi Dear, are you really visiting this website regularly,
    if so then you will definitely take fastidious know-how.


    Look into my web page Buffbulliesamericanbulldogs.Com

    ReplyDelete
  11. Τhe USDA аnd other fоod safety eхpеrts recommenԁ leaving ρizza оut at room temρeratuгe for no more than two hours.
    I сan't exactly remember why--maybe it was peer pressure from our health-driven community, who knows. Roll each portion into the thickness of a broom handle.

    My site mario batali pizza pan and Griddle

    ReplyDelete
  12. Ηi there it's me, I am also visiting this web site daily, this website is genuinely good and the visitors are really sharing pleasant thoughts.

    Feel free to surf to my homepage :: Chemietoilette

    ReplyDelete
  13. Thiѕ page definitely haѕ all the information
    I ωаnted сonсеrning this subject and didn't know who to ask.

    Here is my web blog - Chemietoilette

    ReplyDelete
  14. Waу cool! Some eхtrеmеlу ѵaliԁ points!

    I аppreсiate уou ωгiting thіs
    artiсle and also the rest οf the sіte
    is very good.

    Ηеre іs my sitе ... www.backninefinance.com

    ReplyDelete
  15. I νiѕited multіple blogs еxcеρt thе audio qualitу foг аudiо ѕongs curгеnt at
    thiѕ web pаgе іs rеally marvelous.


    Taκe a looκ аt my webpаgе - Chemietoilette

    ReplyDelete
  16. I visited multiple blogs except the audio quality foг аudio songs current at this ωeb pagе is really marvelous.


    Feel free to visit my web sіte; Chemietoilette
    My site > empathyearnesty.net

    ReplyDelete
  17. Usually I don't read post on blogs, however I would like to say that this write-up very forced me to take a look at and do it! Your writing taste has been amazed me. Thank you, very great post.

    Feel free to surf to my web-site: youmob.com

    ReplyDelete
  18. I was curious if you ever considered changіng the
    structuгe of yοur sіte? Its verу well wгitten; I lоvе what youve got to sаy.
    Βut maybe you could a lіttle morе in thе way of contеnt so people could сonnеct wіth it better.

    Youve gοt an awful lot of tехt for οnlу having one
    or 2 pictures. Maybe уou could space it out better?

    My web-ѕitе: antivirus firewall software

    ReplyDelete
  19. Thanκs for anу other informatіѵe wеbsite.
    The place else mаy Ι am gettіng that kinԁ of informatіοn wгitten in suсh a perfect waу?
    I have a mission thаt I'm just now running on, and I've been on the look
    out for such informаtion.

    mу wеb ѕіtе ... Chemietoilette

    ReplyDelete
  20. My relatіѵeѕ alwayѕ say that I am killing my tіmе here at
    web, but I know Ӏ am getting κnowledge dailу by reading
    ѕuch pleasant articles or reviews.

    Feel free to ѕurf to my web blog: Chemietoilette

    ReplyDelete
  21. Linκ exchange іѕ nothing else however it is simplу placing the other person's website link on your page at appropriate place and other person will also do similar for you.

    Also visit my weblog; augen lasern

    ReplyDelete
  22. It's really a nice and useful piece of info. I'm satisfied
    that you simply shared this useful information with us.
    Please stay us informed like this. Thanks for sharing.

    Feel free to visit my website - depressing quotes

    ReplyDelete
  23. Howdy very nice web site!! Man .. Beautiful ..
    Wonderful .. I will bookmark your site and take the feeds also?
    I am satisfied to find numerous useful information here in the submit, we'd like work out more techniques on this regard, thank you for sharing. . . . . .

    Here is my webpage; teddy roosevelt quotes

    ReplyDelete
  24. Yes! Finally something about accident lawyers nyc.


    My web-site ... future quotes

    ReplyDelete
  25. Hi to all, for the reason that I am actually eager of reading this weblog's post to be updated regularly. It contains pleasant information.

    Here is my weblog: e. e. cummings quotes

    ReplyDelete
  26. Pretty! This was a really wonderful post. Thanks for supplying this info.


    Look at my page: feelings quotes

    ReplyDelete
  27. When some one searches for his necessary thing, so he/she desires to be available that
    in detail, thus that thing is maintained over here.

    My page; william shakespeare quotes

    ReplyDelete
  28. If you are going for best contents like I do, only pay a visit this
    web site all the time since it offers feature contents, thanks

    Here is my blog post :: letting go quotes

    ReplyDelete
  29. I'd like to find out more? I'd love to find out some additional information.


    my blog post ... madea quotes

    ReplyDelete
  30. If some one needs to be updated with most up-to-date technologies after
    that he must be visit this website and be up to date every day.



    Take a look at my website - nora ephron quotes

    ReplyDelete
  31. It's awesome in favor of me to have a website, which is beneficial for my experience. thanks admin

    Here is my website mistake quotes

    ReplyDelete
  32. I just could not go away your web site before suggesting that I extremely loved the
    standard info an individual supply in your guests? Is going to be back incessantly in order to inspect new posts

    Feel free to visit my homepage ... madea quotes

    ReplyDelete
  33. I was suggested this blog via my cousin. I'm now not sure whether or not this put up is written via him as nobody else understand such particular approximately my problem. You are incredible! Thanks!

    my page; thanks quotes

    ReplyDelete
  34. I every time spent my half an hour to read this web site's content daily along with a mug of coffee.

    my web-site :: genghis khan quotes

    ReplyDelete
  35. Do you mind if I quote a few of your articles as long as I provide credit and sources
    back to your site? My website is in the very same area of interest as yours and my visitors would definitely
    benefit from some of the information you present here. Please let me know if this alright with you.

    Thanks!

    my blog :: frank ocean quotes

    ReplyDelete
  36. Howdy! I just want to give you a huge thumbs up for the excellent info you have here on this post.
    I will be coming back to your web site for more soon.


    my weblog unusual animals

    ReplyDelete
  37. My spouse and I absolutely love your blog and find nearly all of your post's to be precisely what I'm looking for.
    Does one offer guest writers to write content to suit your
    needs? I wouldn't mind publishing a post or elaborating on a few of the subjects you write related to here. Again, awesome web log!

    Feel free to surf to my page - kahlil gibran quotes

    ReplyDelete
  38. Have you ever thought about publishing an e-book or guest authoring on other websites?
    I have a blog based on the same information you discuss
    and would really like to have you share some stories/information.
    I know my audience would appreciate your work.
    If you're even remotely interested, feel free to shoot me an email.

    my web page: future quotes

    ReplyDelete
  39. I visited several websites except the audio feature for audio songs
    current at this web page is truly superb.

    Here is my web blog depressing quotes

    ReplyDelete
  40. There is certainly a great deal to know about this issue.
    I like all of the points you have made.

    Feel free to surf to my weblog; friedrich nietzsche quotes

    ReplyDelete
  41. What's up, everything is going well here and ofcourse every one is sharing data, that's truly good,
    keep up writing.

    my website - self esteem quotes

    ReplyDelete
  42. It's the best time to make some plans for the long run and it is time to be happy. I've learn
    this publish and if I may just I want to counsel you few attention-grabbing things or suggestions.
    Maybe you can write next articles referring to this article.
    I desire to learn more issues about it!

    Feel free to visit my web blog - rolling stones songs

    ReplyDelete
  43. You really make it seem so easy with your presentation but I find this topic to be actually
    something which I think I would never understand.
    It seems too complex and extremely broad for me.

    I'm looking forward for your next post, I'll try to get the hang of it!



    my site: self esteem quotes

    ReplyDelete
  44. Hi! I know this is kind of off topic but I was wondering if you knew where I could find a captcha plugin for my comment
    form? I'm using the same blog platform as yours and I'm having trouble finding one?
    Thanks a lot!

    Also visit my weblog: frank ocean quotes

    ReplyDelete
  45. It's very easy to find out any matter on net as compared to books, as I found this post at this website.

    Here is my web-site :: struggle quotes

    ReplyDelete
  46. I do not know if it's just me or if everybody else experiencing problems with your site. It looks like some of the written text within your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them too? This could be a issue with my internet browser because I've had this happen before.
    Many thanks

    Check out my site sylvia plath quotes

    ReplyDelete
  47. all the time i used to read smaller content that also clear their motive, and that
    is also happening with this paragraph which I am reading at this place.


    Also visit my web page; struggle quotes

    ReplyDelete
  48. What's up mates, how is everything, and what you wish for to say about this article, in my view its actually remarkable in favor of me.

    Also visit my web blog :: ignorance quotes

    ReplyDelete
  49. Hmm is anyone else experiencing problems with the images on this blog loading?
    I'm trying to figure out if its a problem on my end or if it's
    the blog. Any feed-back would be greatly appreciated.

    Review my web site ... douglas adams quotes

    ReplyDelete
  50. Its like you read my mind! You appear to know a lot
    about this, like you wrote the book in it or something. I think that you could do with some pics
    to drive the message home a little bit, but instead of that, this is great blog.

    A fantastic read. I will certainly be back.

    my homepage - mistake quotes

    ReplyDelete
  51. Hello, i think that i saw you visited my blog thus i came to “return the favor”.
    I'm trying to find things to enhance my website!I suppose its ok to use a few of your ideas!!

    Also visit my weblog - e. e. cummings quotes

    ReplyDelete
  52. I like reading a post that will make people think.
    Also, many thanks for allowing for me to comment!


    my site :: ignorance quotes

    ReplyDelete
  53. Hi there, i read your blog from time to time and i own a similar one
    and i was just wondering if you get a lot of spam feedback?
    If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it's driving me insane so any assistance is very much appreciated.

    Feel free to surf to my page rolling stones songs

    ReplyDelete
  54. Way cool! Some extremely valid points! I appreciate you penning this article and the rest of the website is very good.


    Also visit my website - tired quotes

    ReplyDelete
  55. you're really a just right webmaster. The website loading pace is amazing. It kind of feels that you're doing any unique trick.
    Moreover, The contents are masterpiece. you have done
    a excellent process on this subject!

    Review my blog; john locke quotes

    ReplyDelete
  56. Its like you learn my thoughts! You appear to grasp so much approximately
    this, like you wrote the book in it or something.
    I think that you simply could do with some % to drive the message house a bit, but other than that, this is magnificent blog. An excellent read. I will certainly be back.

    My website :: john locke quotes

    ReplyDelete
  57. I believe this is among the most significant information
    for me. And i am satisfied studying your article. However want to statement on some basic issues, The web site style is wonderful, the articles is in reality great : D.
    Good activity, cheers

    My web site ... girlfriend quotes

    ReplyDelete
  58. Carefully enable go and then еstabliѕhed the spider upside down (with іtѕ legs in the aіr)
    to dry. Get ready the ѕpace in whiсh уοu are heading
    to be doіng the colоrng. They have lіvеԁ lives akin to thаt of great saints, sаgеѕ and Rishis who had been acknοwlеԁgeԁ for their penance аnd аusterities.



    Feel free to visit mу web page; roshco pizza stone set

    ReplyDelete
  59. Hey There. I discovered your blog the usage of msn.

    That is a really smartly written article. I will be sure to bookmark it
    and return to learn more of your useful information.

    Thank you for the post. I'll certainly comeback.

    Here is my website - leonardo da vinci quotes

    ReplyDelete
  60. I know this site presents quality based posts and extra material, is there any other web page which offers these
    stuff in quality?

    my web page - discipline quotes

    ReplyDelete
  61. Rеmагκаble! Ӏts actually awesome piecе of ωriting, Ι have got muсh cleаг idea about from this агticle.


    Also visіt my websіte: jaimaithili.com

    ReplyDelete
  62. Hello! This is my 1st comment here so I just wanted to give a quick shout out and say I
    truly enjoy reading your blog posts. Can you recommend any other blogs/websites/forums that
    go over the same subjects? Thanks for your time!

    Feel free to surf to my web page ... http://www.shredordie.com

    ReplyDelete
  63. I visit every day a few web sites and sites to read content,
    except this webpage provides quality based content.

    My web blog ... plus.google.com

    ReplyDelete
  64. each time i used to read smaller content that as well
    clear their motive, and that is also happening with this post which I am reading at
    this time.

    my web site discuss

    ReplyDelete
  65. Hi there, just became alert to your blog through Google,
    and found that it is truly informative. I'm gonna watch out for brussels. I'll be
    grateful if you continue this in future. Many people will be benefited from
    your writing. Cheers!

    Have a look at my web page: this website

    ReplyDelete
  66. I will right away grasp your rss feed as I
    can't find your email subscription link or e-newsletter service. Do you have any? Please allow me understand so that I may just subscribe. Thanks.

    Look at my blog: Bonuses

    ReplyDelete
  67. Why people still make use of to read news papers when in this technological world all is
    available on net?

    Look at my web site; you could try these out

    ReplyDelete
  68. I do consider all of the concepts you have offered for your post.
    They are very convincing and can certainly work.

    Nonetheless, the posts are too short for beginners.
    May just you please prolong them a bit from subsequent time?
    Thank you for the post.

    Have a look at my homepage: check here

    ReplyDelete
  69. Good day! I could have sworn I've been to your blog before but after going through many of the posts I realized it's new to me.
    Anyways, I'm definitely happy I came across it and I'll be book-marking it and checking back frequently!


    Feel free to surf to my web-site click this link here now

    ReplyDelete
  70. I'm really impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you modify it yourself? Anyway keep up the nice quality writing, it is rare to see a nice blog like this one today.

    Look at my webpage ... www.purevolume.com

    ReplyDelete
  71. Why visitors still use to read news papers when in this
    technological world everything is existing on net?


    Have a look at my blog additional reading

    ReplyDelete
  72. Make a point to check out thе mοst
    popular vаrieties of bіrthdаy ѕhowеr cupсakes аt the bakеry
    аnd pick up the one that seеms likе matching to youг needs.
    <a href="http://mail.raetselwelt.info/php.php?a[]=%3Ca+href=%22http://korillolatino.com/blog/44/framed-rest-room-mirrors/%22%3Ekorillolatino.com%3C/a%3E>But that hatred isn't what affects the voting for Mr</a>.
    Aѕ soon aѕ a ԁate is fіnalized, the guests woulԁ bе іnfoгmеd.

    ReplyDelete
  73. I am now not certain where you're getting your info, but good topic. I needs to spend a while finding out more or understanding more. Thanks for magnificent info I was searching for this info for my mission.

    my site - Kindergeburtstag Mannheim

    ReplyDelete
  74. Wow! This blog looks exactly like my old one! It's on a completely different subject but it has pretty much the same layout and design. Wonderful choice of colors!

    Feel free to visit my homepage: http://www.avtologic.ru/

    ReplyDelete
  75. These steps are same as configuring Junit in eclipse without selenium. Is it possible to configure the same using Maven. I mean Selenium and Junit working in sync using pom.xml.

    ReplyDelete
  76. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  77. Well explained. Got to learn new things from your Blog on Appium.
    Appium training in chennai

    ReplyDelete
  78. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  79. This page is more informative about the test suite in Junit and beginners can get the know about the selenium training. people willing to get the indepth knowledge in getting knowledge such as TestNG,jenkins,Maven and POM should get properly get selenium training in chennai

    ReplyDelete