Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #95 from bem/feature/send-file
Browse files Browse the repository at this point in the history
Add `sendFile` action
  • Loading branch information
Sergej Tatarincev committed Dec 2, 2014
2 parents 4e40f83 + 927208a commit 31c51b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Dev

* Add `sendFile` action which now should be used instead of
`sendKeys` to set a file to `input[type=file]` elements (@SevInf).
* Fail only single test if reference image is not found (@SevInf).

## 0.9.3 - 2014-11-07
Expand Down
2 changes: 2 additions & 0 deletions doc/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,7 @@ Full list of special keys (there are shortcuts for commonly used keys):
`NUMPAD8`, `NUMPAD9`, `MULTIPLY`, `ADD`, `SEPARATOR`, `SUBTRACT`, `DECIMAL`, `DIVIDE`, `F1`, `F2`, `F3`, `F4`, `F5`,
`F6`, `F7`, `F8`, `F9`, `F10`, `F11`, `F12`, `COMMAND``META`, `ZENKAKU_HANKAKU`.

* `sendFile(element, path)` - send file to the specified `input[type=file]` element. `path` must exist at
local system (the one which `gemini` is executed on).
* `focus(element)` - set a focus to a specified element.
* `setWindowSize(width, height)` - change browser window dimensions.
2 changes: 2 additions & 0 deletions doc/tests.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,7 @@
`NUMPAD8`, `NUMPAD9`, `MULTIPLY`, `ADD`, `SEPARATOR`, `SUBTRACT`, `DECIMAL`, `DIVIDE`, `F1`, `F2`, `F3`, `F4`, `F5`,
`F6`, `F7`, `F8`, `F9`, `F10`, `F11`, `F12`, `COMMAND``META`, `ZENKAKU_HANKAKU`.

* `sendFile(element, path)` - выбор файла в заданном элементе `input[type=file]`. `path` должен существовать
в локальной системе (там же, где запущен `gemini`).
* `focus(element)` - устанавливает фокус на указанный элемент.
* `setWindowSize(width, height)` - устанавливает размера окна браузера.
25 changes: 25 additions & 0 deletions lib/browser/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var q = require('q'),
fs = require('q-io/fs'),
inherit = require('inherit'),
promiseUtil = require('../promise-util'),
suiteUtil = require('../suite-util'),
Expand Down Expand Up @@ -232,6 +233,30 @@ module.exports = inherit({
return this;
},

sendFile: function(element, path) {
var _this = this;
if (typeof path !== 'string') {
throw new TypeError('path must be string');
}
if (isInvalidElement(element)) {
throw new TypeError('.sendFile() must receive valid element or CSS selector');
}

this._pushAction(this.sendFile, function sendFile() {
return fs.isFile(path)
.then(function(isFile) {
if (!isFile) {
return q.reject(new StateError(path + ' should be existing file'));
}
return _this._findElement(element);
})
.then(function(element) {
return element.sendKeys(path);
});
});
return this;
},

focus: function(element) {
if (isInvalidElement(element)) {
throw new TypeError('.focus() must receive valid element or CSS selector');
Expand Down

0 comments on commit 31c51b9

Please sign in to comment.