Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Graydon
erp5
Commits
2c76c717
Commit
2c76c717
authored
Aug 15, 2019
by
Yusei Tahara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_ui_test_core] Add setFile selenium command to upload a file without security error.
parent
04c2881a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
bt5/erp5_ui_test_core/SkinTemplateItem/portal_skins/erp5_ui_test_core/user-extensions.js.js
...Item/portal_skins/erp5_ui_test_core/user-extensions.js.js
+38
-0
No files found.
bt5/erp5_ui_test_core/SkinTemplateItem/portal_skins/erp5_ui_test_core/user-extensions.js.js
View file @
2c76c717
...
...
@@ -2,6 +2,44 @@
* Selenium extensions for the ERP5 project
*/
/**
* You can set file data to file input field without security error.
* After this command you must use pause command because this command
* is asynchronous.
* <tr>
* <td>setFile</td>
* <td>field_my_file</td>
* <td>/data.jpg myfilename.jpg</td>
* </tr>
* <tr>
* <td>pause</td>
* <td>10000</td>
* <td></td>
* </tr>
*/
Selenium
.
prototype
.
doSetFile
=
function
(
locator
,
url_and_filename
)
{
var
tmpArray
=
url_and_filename
.
split
(
'
'
,
2
);
var
url
=
tmpArray
[
0
];
var
fileName
=
tmpArray
[
1
];
if
(
!
fileName
)
{
throw
new
Error
(
'
file name must not be empty.
'
);
}
var
fileField
=
this
.
page
().
findElement
(
locator
);
fetch
(
url
)
.
then
(
function
(
response
){
if
(
!
response
.
ok
)
{
throw
new
Error
(
'
HTTP error, status =
'
+
response
.
status
);
}
return
response
.
blob
();
})
.
then
(
function
(
blob
){
var
dT
=
new
ClipboardEvent
(
''
).
clipboardData
||
// Firefox < 62 workaround exploiting https://bugzilla.mozilla.org/show_bug.cgi?id=1422655
new
DataTransfer
();
// specs compliant (as of March 2018 only Chrome)
dT
.
items
.
add
(
new
File
([
blob
],
fileName
));
fileField
.
files
=
dT
.
files
;
});
};
/**
* Checks the element referenced by `locator` is a float equals to `text`.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment