tags:

views:

142

answers:

2

I'm a Selenium n00b... it's clear how easy it is to run a test and verify a particular response, but how can I take a value from one response and use it in the next test?

an example might be a contact creation form...

  1. type in name/email and click submit
  2. response arrives with new ContactID
  3. grab the ContactID that was returned and put it into "get" textbox and click "submit"
  4. response arrives with contact details
  5. verfy the name/email match the first set

how might I go about doing this in Selenium?

+2  A: 

(This answer is still correct I think if you interpret "test" as "test case". For another, totally different answer see below.)

You don't do this. Each test should be independent from all other tests. For your second test, just repeat the steps in the first test. This way, you can reproduce test success and failures in a reliable way.

If you have many tests which all start from a certain application state which requires many steps to reach, just write a private helper method to reach that state.

The alternative: All steps you describe can be put into a single test. There is no reason not to have several asserts in one test.

Moritz Both
ok well then it seems we're just haggling over the definition of "test"... when you say "in your second test, just repeat steps in first test", I don't get it. If I repeat the steps, then I'm still running two tests...? but we're just calling it "2nd test"?
Nick Franceschina
This was a complete misunderstanding - funny ;-) I thought when you say "test", you mean "test case", but that's wrong: You mean assertion within a single test case. Usually people mean "test case" when they say "test" at least in my neighborhood. See my second answer which is completely different.
Moritz Both
+1  A: 

And now something completely different:

Now I understand when you say "test", you mean a single assertion within one test case. So you want to use a value returned from a request as input for another request in the same test case.

Assuming you use selenium ide: To do this, use one of the "store..." commands in selenium ide and store the value into a variable. The contactID can be found using a matching selector with the storeText command. For example:

command: storeText
target: selector for element containing contactId
value: contactId

Then, use variable substitution and the type command to insert that text somewhere else.

command: type
target: selector for target input box
value: ${contactId}

Hope this helps :)

Moritz Both
Thanks Moritz!!
Nick Franceschina