1

I'm using Sahi for Test Automation of web application. I have to write a script for sahi for uploading a file. But unfortunately I don't know the way. Can anybody please help me?

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
vinod
  • 1,115
  • 4
  • 13
  • 24

4 Answers4

3

File upload can be a complex thing depending upon any validations you do on the upload. For a starter, you can try out the following:

Synatx:

_setFile(element, filePath [, actionURL])

eg: _setFile(_file("id"), "C:\abc\efg.jpg", "formSubmit.jsp");

If there are javascript validations on the file field, you can try this hack. Before submitting the file, change the field’s type to “text”, and then set its value. Eg.

// set the file
_setFile(_file("file"), "scripts/demo/uploadme.txt");
// Change the "type" attribute of file field
if (_isIE()){
_call(_file("file").outerHTML = _file("file").outerHTML.replace(/type=['"]?file['"]?/, "type=text"));
}else{
_call(_file("file").type = "text");
}
// Set the value into the textbox
_setValue(_textbox("file"), "scripts/demo/uploadme.txt");

This works for most of the cases. If you still get any error, you can post it here.

Thanks, Vivek

Vivek V Dwivedi
  • 2,510
  • 2
  • 28
  • 39
0

Note that as of Sahi 4.3, there is a _setFile2 function that automatically handles js validations and does this input type conversion.

COil
  • 7,201
  • 2
  • 50
  • 98
0

I've solved using the function setFile2, with internally changes the type of field to text

maxshuty
  • 9,708
  • 13
  • 64
  • 77
xruizs
  • 1
  • There is already an answer on here posted over two years ago that mentions that function. Do you have anything to add to that answer? – skrrgwasme Oct 21 '15 at 15:57
0

You can use the following

_setFile(_file("id"), "C:\\abc\\efg.jpg");

Not sure if you need anything more complex?

Abe Petrillo
  • 2,368
  • 23
  • 34
  • i need more complex because the file upload is not converting to text box – vinod Feb 23 '12 at 10:59
  • 1
    You need more detail in your question, and some example code of where things are going wrong. It's impossible to decipher what your question is – Abe Petrillo Feb 23 '12 at 11:11