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 ?
问题:
回答1:
It's not possible using the Selenium IDE, but you can store using Selenium RC or Webdriver (Junit or Nunit).
回答2:
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.
回答3:
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.
回答4:
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
回答5:
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.
回答6:
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
回答7:
You can use 'file logging' for this, try below plugin
https://addons.mozilla.org/en-US/firefox/addon/file-logging-selenium-ide/
Steps:
- Install Addon
- Set Log Level to 'Info'
- Navigate to 'Options -> FileLogging' in IDE and provide path (
D:\Users\jmatthew\Desktop\Selenium\Log1.csv
) - Use command
storeText | id=abcd.aa | value
- Use command
echo | ${value}
- Read the CSV file using
VLOOKUP
for matching results contain 'echo'