Jackie James
Jackie James

Reputation: 853

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 ?

Upvotes: 4

Views: 19586

Answers (8)

tim-montague
tim-montague

Reputation: 17442

Yes it's possible to write variables stored in Selenium IDE to a file.

Selenium IDE v4

For the Selenium IDE v4 electron desktop application you would create an NPM package.

Example below: https://github.com/SeleniumHQ/selenium-ide/blob/trunk/packages/side-example-suite/src/plugins/custom-click/index.ts

import { PluginShape } from '@seleniumhq/side-api'

/**
 * This is a demo plugin that takes the default click command, adds a new "customClick" command,
 * and replaces recordings of the default click command with the custom one.
 * This plugin also adds a hook that logs the command before it is executed.
 */

const plugin: PluginShape = {
  commands: {
    customClick: {
      name: 'custom click',
      description:
        'This command should replace the standard click command when recording',
      target: {
        name: 'locator',
        description: 'The target of the original recorded click',
      },
      execute: async (command, driver) => {
        await driver.doClick(command.target!, command.value!, command)
      },
    },
  },
  hooks: {
    onAfterCommand: (input) => {
      console.log('After command', input)
    },
    onBeforeCommand: (input) => {
      console.log('Before command', input)
    },
    async onLoad(api) {
      console.log('Loading example plugin!')
      api.channels.onSend.addListener((channel, command) => {
        if (channel === 'example-plugin') {
          console.log('Message received', channel, command)
        }
      })
      console.log('Loaded example plugin!')
    },
  },
}

export default plugin

Selenium IDE v3

For the outdated Selenium IDE v3 browser extension still available on the Chrome and Firefox add-on stores, you would create another browser extension which communicates via event handlers.

  1. Create a plugin folder side_logger
  2. Create a Web Extension manifest file side_logger/manifest.json
{
  "manifest_version": 2,
  "name": "Selenium IDE Logger",
  "version": "0.0.1",
  "description": "Write log data to file",
}

Note: "manifest_version": 3, is not supported by Selenium IDE

The old Selenium IDE v3 website explains further
https://www.selenium.dev/selenium-ide/docs/en/plugins/plugins-getting-started

Selenium IDE v3 - File Logger plugin

Selenium IDE v3 only supports plugins developed in the outdated Web Extensions v2 standard. Chrome and Firefox extension stores stopped supporting the Web Extension v2 standard in 2022, and removed all web extensions that did not move to the Web Extension v3 standard in 2024.

The File Logger plugin, which could write data from Selenium IDE v3 to a file, no longer exists on the Chrome and Firefox extension stores.

Upvotes: 1

tomm
tomm

Reputation: 302

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.

Upvotes: 5

Aj Matthew
Aj Matthew

Reputation: 11

You can use 'file logging' for this, try below plugin

https://addons.mozilla.org/en-US/firefox/addon/file-logging-selenium-ide/

Steps:

  1. Install Addon
  2. Set Log Level to 'Info'
  3. Navigate to 'Options -> FileLogging' in IDE and provide path (D:\Users\jmatthew\Desktop\Selenium\Log1.csv)
  4. Use command storeText | id=abcd.aa | value
  5. Use command echo | ${value}
  6. Read the CSV file using VLOOKUP for matching results contain 'echo'

Upvotes: 0

solar
solar

Reputation: 1

here you can find the answer how to read variables from CSV file (you should arrach .js file in the selenium IDE options as extension and at that page is also example how to use it)

http://openselenium.com/?p=19

Upvotes: -1

user3441270
user3441270

Reputation: 1

It is not possible using selenium IDE, you need to use selenium webdriver where you can code language to do read/write operation to a file.

Upvotes: 0

ssebastian
ssebastian

Reputation: 19

Try to use storeEval command,it evaluates java script snippets and refer the tips posted in http://www.tek-tips.com/viewthread.cfm?qid=1171273.

Let me know the result. -Thanks

Upvotes: 0

Sonu
Sonu

Reputation: 139

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

Upvotes: 4

Hari Reddy
Hari Reddy

Reputation: 3858

I do not know if selenium IDE is sufficient to achieve what you are trying to do but if you can export the recorded test case to any language like java and then you can easily modify the exported code to write the variables you have stored to any file using the inbuilt capabilities of languages such as java.

Upvotes: 0

Related Questions