vinod
vinod

Reputation: 1115

sahi script for choosing and uploading a file

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?

Upvotes: 1

Views: 2676

Answers (4)

xruizs
xruizs

Reputation: 1

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

Upvotes: 0

COil
COil

Reputation: 7606

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

Upvotes: 0

Vivek V Dwivedi
Vivek V Dwivedi

Reputation: 2615

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

Upvotes: 3

Abe Petrillo
Abe Petrillo

Reputation: 2447

You can use the following

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

Not sure if you need anything more complex?

Upvotes: 0

Related Questions