How to use Selenium to store values between tests
Selenium has the ability to temporarily store data items and then later retrieve them in subsequent tests, e.g.
storeText | @id='ctl00_ContentPlaceHolder1_FormView1' | someValue
This works well within a single test and also between tests in the same Test Suite when a value needs to be carried forward across test boundaries. Unfortunately it doesn't work between Test Suites (which开发者_开发知识库 is a requirement for our application that includes a number of workflows referring to the same object). How can Selenium be used to store values across Test Suite boundaries?
It's possible to store values from a Selenium Test into the browser's Local Storage using javascript, e.g. if previously a value had been stored to someValue:
getEval | this.browserbot.getUserWindow().localStorage.setItem("someValue",storedVars['someValue'])
assertEval | this.browserbot.getUserWindow().localStorage.getItem("someValue") | ${someValue}
storeEval | this.browserbot.getUserWindow().localStorage.getItem("assetLabel") | someValue
In this case, this.browserbot.getUserWindow() returns the window of the application. This will store someValue into Local Storage from where it can subsequently be retrieved back into the Selenium stored variables.
You could also implement the persistence in the code that's running your Selenium tests. If you're using RC, this would be fairly trivial. (ie, just straight database queries to insert/update and then retrieve).
If you're using Selenese and don't have access to an API for persistence, you could also whip up a quick and dirty little webpage to store the data in a database and then read it back for subsequent test runs. Obviously this isn't ideal, but it should work if you can't access a persistence store directly from your tests..
精彩评论