Jesse Smothermon
Jesse Smothermon

Reputation: 1051

Selenium using conditional statements

I just started looking into selenium for automated testing for the past few days and am getting pretty stuck. I've been looking for documentation on this but haven't found anything very helpful but maybe one of you have found something interesting, if so I'd love to read it.

Anyway, here's the problem: I need to open up a website. This website takes in some parameters which takes the browser to another site, however if the parameters are invalid then the next site will display a message saying "An error has occurred".

If the second site doesn't error out like this we want to store a few arbitrary values and echo them later. If the site does error out we want to mark the error and move on. Right now, if the second site is invalid selenium stops running.

The only way it seems to do this is to have an if-else statement though I haven't found any mention of one in selenium. I have read somewhere that you can create some javascript on your own and then input that into selenium. The problem there is that I don't know how to actually input the javascript into selenium.

I hope that wasn't too confusing.

Thank you,

Jesse Smothermon

Upvotes: 6

Views: 7932

Answers (3)

merrickc
merrickc

Reputation: 11

I am fairly new to selenium too, but I think what you want to do is use the Selenium IDE and export to visual studio or something. When you use selenium with visual studio (C#) you have complete control over the flow of the test. its much more easier to program something like that. but at the same time, you need to configure it with Nunit or selenium RC.

Also out there is a selenium extension called "Flow Control". I have not used it, but I believe it will allow the Selenium IDE to do if/else/etc

Upvotes: 1

Jesse Smothermon
Jesse Smothermon

Reputation: 1051

My coworker found it. code below:

<tr>
<td>storeEval</td>
<td>(selenium.isElementPresent("variable_looked_at")?selenium.getText("variable_looked_at"):"N/A")</td>
<td>Address</td>
</tr>

Thanks,

Jesse Smothermon

Upvotes: 7

Kinexus
Kinexus

Reputation: 12904

As a unit test, if the second site has failed, the unit test has failed. Perhaps rather than looking for a conditional processing of your unit test, fix the problem that causes the test to fail.

That may sound a little harsh and forgive me if it does, but it sounds illogical to me that you would want to take this approach.

Upvotes: 0

Related Questions