Unfortunately, I don't have a choice in this case. I would agree that the if/else should not belong, however, with the way the actual logic of the pages is set up, they allow multiple purchases to be performed. If you purchase something on the site and you go back and purchase the same item, we verify that you really wanted to purchase the item again, same page, but there is a check box on the page. I have to check if that box is there, if it is, I need to do something with it, if it is not then I can ignore that section of logic.
I went with getElementByXPath and catch the error because it's closest to what I need. I would've preferred to have a method that didn't throw an error, so instead I just wrote one in my unit test that wrapped around that logic and returns a boolean to do what I want. thx timo On Fri, Jul 24, 2009 at 11:44 PM, Jevon Wright <je...@jevon.org> wrote: > Hi, > > Generally it's better to not have these sorts of if/else blocks in test > cases. If you are testing a whole lot of generated pages, then I think it's > better to write test cases for the generation code. > > In JUnit all test case methods assertXXX() should throw an > AssertionFailedError if the test fails (see TestCase.fail()) so you can > catch this if necessary. > > If you are just looking to see if an element exists, look at the > getElement() methods. > > Hope this helps! > Jevon > > On Fri, Jul 24, 2009 at 8:30 AM, Stand Trooper <standtroo...@gmail.com>wrote: > >> Ok, so I've been toying with this for a day or so without revelation, so >> I'm hoping that I can find the answer here. I've searched the cryptic >> archives and read javadocs and even played with a lot of different things. >> >> What I need to do is find out if an element is present before I move on. >> >> for example: >> if (elementExists("//d...@id='bob']")) { >> //perform action >> } >> >> or even an override to getElement that passes a boolean to not do the >> assertion, if the element doesn't exist it returns a null object. >> >> Right now, I have a series of interactions on forms that may cause errors >> that I'm testing, if an error displays, then an element will show up on the >> page. I'm doing about 295,000 automated tests right now and I'll be bumping >> that up to about 895k tests once these are done. I can't just do an >> assertTextPresent or assertTextNotPresent, I need to detect if something is >> there, if it is, then perform a specific action and move on without taking >> down the tests and having to start over. >> >> Is there anything like that that I can use? If not, that's ok, I'll have >> to write some code, unless someone has something quick in mind. >> >> thx >> >> timo >> StandTrooper >> >>
------------------------------------------------------------------------------
_______________________________________________ JWebUnit-users mailing list JWebUnit-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jwebunit-users