I'm using selenium IDE to record & replay some testcase. During this, i stored some values in variables.Now i've to load/write these variable's value into new file.How can i do it ? is it possible ?
It is definitely possible. You just need to create some javascript function using mozilla (firefox) addons API https://developer.mozilla.org/en-US/Add-ons, save this function in selenium core extension file http://www.seleniumhq.org/docs/08_user_extensions.jsp and add this extension into Selenium IDE.
Sample function to write text file:
// ==================== File Writer ====================
Selenium.prototype.doWriteData = function(textToSave, location)
{
var data = textToSave;
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(location);
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.writeString(data);
converter.close();
}
Read is simple to do as well, just add another function, something like "doReadData" more info here https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O
To add this script to Selenium-IDE, follow this instructions:
- Create your user extension and save it as user-extensions.js. While this name isn’t technically necessary, it’s good practice to keep things consistent.
- Open Firefox and open Selenium-IDE.
- Click on Tools, Options
- In Selenium Core Extensions click on Browse and find the user-extensions. js file. Click on OK.
- Your user-extension will not yet be loaded, you must close and restart Selenium-IDE.
- In your empty test, create a new command, your user-extension should now be an options in the Commands dropdown.
It's not possible using the Selenium IDE, but you can store using Selenium RC or Webdriver (Junit or Nunit).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With