How to use Selenium to store values between tests

前端 未结 2 1997
遥遥无期
遥遥无期 2021-01-05 23:25

Selenium has the ability to temporarily store data items and then later retrieve them in subsequent tests, e.g.

storeText | @id=\'ctl00_ContentPlaceHolder1_F         


        
相关标签:
2条回答
  • 2021-01-05 23:42

    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.

    0 讨论(0)
  • 2021-01-05 23:43

    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..

    0 讨论(0)
提交回复
热议问题