Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load/write data into a newfile using selenium IDE?

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 ?

like image 249
Jackie James Avatar asked Sep 15 '25 00:09

Jackie James


2 Answers

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:

  1. 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.
  2. Open Firefox and open Selenium-IDE.
  3. Click on Tools, Options
  4. In Selenium Core Extensions click on Browse and find the user-extensions. js file. Click on OK.
  5. Your user-extension will not yet be loaded, you must close and restart Selenium-IDE.
  6. In your empty test, create a new command, your user-extension should now be an options in the Commands dropdown.
like image 193
tomm Avatar answered Sep 17 '25 19:09

tomm


It's not possible using the Selenium IDE, but you can store using Selenium RC or Webdriver (Junit or Nunit).

like image 26
Sonu Avatar answered Sep 17 '25 20:09

Sonu