Verify and Continue a verification point....

405 views
Skip to first unread message

Manjunath Bellur

unread,
Jun 24, 2009, 5:52:15 AM6/24/09
to testng...@googlegroups.com
Hi, 
   I am using Selenium RC and TestNG. I have a testcase written to verify multiple point in a page. 

public class Testthepage {

@Beforeclass (alwaysRun = true)
public void setUp () {
  openUI.setUP ()
}

@Test
public void verifyUI () {

   selenium.open (<URL>);
   assertTrue (selenium.isElementPresent ("id=txtfiled"));
   assertTrue (selenium.isElementPresent ("id=submit"));
   assertTrue (selenium.isElementPresent ("id=drpdwn1"));
   assertTrue (selenium.isElementPresent ("id=radiobtn"));

}

@Test
public void Verify () {
....
..... etc
}

}


My test case steps are below. 
   a) Open the Page (<some URL>)
   b) Verify Text Field "t1" is prensent
   c) Verify button "go" is present. 
   d) Verify dropdown "dr1" present. 
   e) Verify radio "rd1" present. 

Now if the first verification fails (Verification point b ) the other Verification c to e will not get executed. My requirement is to make sure even though the first verification point fails it should continue with other assert statements, however the whole testcases should show as Failed. How do I make this work using TestNG. 

Please help me on solving this problem. 

Thanks and Regards,
Manjunath 

konstantin

unread,
Jun 24, 2009, 12:09:18 PM6/24/09
to testng-users
Manjunath,
you can do this way:

boolean isTxtfiledPresent = selenium.isElementPresent ("id=txtfiled");
...
boolean isRadiobtnPresent = selenium.isElementPresent ("id=radiobtn");

assertTrue("isTxtfiledPresent = "+isTxtfiledPresent+...,
isTxtfiledPresent && .. && isRadiobtnPresent);

Konstantin

Cédric Beust ♔

unread,
Jun 24, 2009, 12:23:19 PM6/24/09
to testng...@googlegroups.com
Yes, that's the best way.  You might want to add a message to this approach so that the final assert will fail with an error that will tell you exactly which boolean was false...

--
Cedric


2009/6/24 konstantin <konstanti...@gmail.com>



--
Cédric


Manjunath Bellur

unread,
Jun 25, 2009, 2:48:45 AM6/25/09
to testng...@googlegroups.com
Thanks Konstantin and Cedric, 
      This is a nice idea.  However every testcase having this kind of verification would have many boolean variables declared, which may be cumbersome and confusing. 

Cedric : Would that be a good idea to extend the current assert* statements to Verify and Continue.  assert* can take an extra parameter (TRUE or FALSE (default to False)). This means the execution of next steps will continue if TRUE is passed, else would come out of testcases. However in both the cases if any step has failed the whole testcase is marked as Failed. 

If you agree with this, will be eagerly waiting for the next version of TestNG. :)

Let me know your thoughts, 

Thanks and Regards,
Manjunath
    

2009/6/24 Cédric Beust ♔ <cbe...@google.com>

konstantin

unread,
Jun 25, 2009, 8:05:17 AM6/25/09
to testng-users
You can do this in your project. assert* - just static method which
call fail() in some condition. So you can define these conditions,
make your own assertCollectionTrue(Collection<Boolean>) or something
like this.

On 25 июн, 10:48, Manjunath Bellur <manjunath.bel...@gmail.com> wrote:
> Thanks Konstantin and Cedric,       This is a nice idea.  However every
> testcase having this kind of verification would have many boolean variables
> declared, which may be cumbersome and confusing.
>
> Cedric : Would that be a good idea to extend the current assert* statements
> to Verify and Continue.  *assert** can take an extra parameter (TRUE or
> FALSE (default to False)). This means the execution of next steps will
> continue if TRUE is passed, else would come out of testcases. However in
> both the cases if any step has failed the whole testcase is marked as
> Failed.
>
> If you agree with this, will be eagerly waiting for the next version of
> TestNG. :)
>
> Let me know your thoughts,
>
> Thanks and Regards,
> Manjunath
>
> 2009/6/24 Cédric Beust ♔ <cbe...@google.com>
>
>
>
> > Yes, that's the best way.  You might want to add a message to this approach
> > so that the final assert will fail with an error that will tell you exactly
> > which boolean was false...
>
> > --
> > Cedric
>
> > 2009/6/24 konstantin <konstantin.a.sa...@gmail.com>
> > ***Cédric
> > *- Скрыть цитируемый текст -
>
> - Показать цитируемый текст -

Cédric Beust ♔

unread,
Jun 25, 2009, 11:05:57 AM6/25/09
to testng...@googlegroups.com
Yes, like Konstantin is saying, it's probably preferable for you to write these extended assert methods for the cases you need.  There are a lot of assert methods in the TestNG classes and I don't think that adding a boolean to all of them (or duplicating the existing methods) is worth it.

But I'm thinking of a more general system that might be of assistance to you in order to solve the kind of problem you're encountering, I'll try to find some time to write a blog post about it and I'll let you know.

--
Cedric
--
Cédric


Cédric Beust ♔

unread,
Jun 25, 2009, 12:28:30 PM6/25/09
to testng...@googlegroups.com, manjunat...@gmail.com
The blog post is up:

http://beust.com/weblog/archives/000514.html

Comments welcome.

--
Cédric




2009/6/25 Cédric Beust ♔ <cbe...@google.com>

Manjunath Bellur

unread,
Jun 26, 2009, 11:54:46 AM6/26/09
to Cédric Beust ♔, testng...@googlegroups.com
Hi Cedric, 
   Thanks for the blog. I would have the assertsoft as mentioned by you. However, it would be good if the Framework itself provides this feature. Like me, many other will also be or may face the same problem. :).  

Thanks and Regards
Manjunath

2009/6/25 Cédric Beust ♔ <cbe...@google.com>

Cédric Beust ♔

unread,
Jun 26, 2009, 12:15:56 PM6/26/09
to Manjunath Bellur, testng...@googlegroups.com
Hi Manjunath,

Noted.  Be sure to read the comments, a few people have already chimed in and offered improvements on the original idea.  I'll wait to see how this unfolds before deciding what TestNG could provide.

--
Cédric



2009/6/26 Manjunath Bellur <manjunat...@gmail.com>

Manjunath Bellur

unread,
Jun 26, 2009, 1:15:41 PM6/26/09
to Cédric Beust ♔, testng...@googlegroups.com
Sure, Thanks for the help :). If you decide on implementing in TestNG itself, just let me know and I will be ready to grab the next version of TestNG. 

Thanks and Regards
Manjunath


2009/6/26 Cédric Beust ♔ <cbe...@google.com>
Reply all
Reply to author
Forward
0 new messages