javascriptのレイヤー上に入力[type = "file]要素を表示する(Quality Productの回答を参照)ことができないと仮定すると、robotjsを使用してファイルブラウザからファイルをアップロードすることは可能です。
あなたはあなたの特定の状況に合わせて周りのコードスニペット以下に変更する必要がありますが、これは私がrobotjsは(ページオブジェクトのデザインパターンを利用して)仕事を得ることができた方法です
ページオブジェクト
var robot = require("robotjs");
var path = require("path");
var MediaPO = function() {
...
...
...
this.clickBrowseFileLink = function() {
return browseFileLink.click(); //returns a promise
};
this.uploadFile = function(filename) {
robot.moveMouse(648, 264) //May need to change based on desktop size
var uploadPath = path.resolve(__dirname,'../PATH/TO/UPLOAD/', filename); //change to your upload file's path
robot.setKeyboardDelay(1000);
console.log(uploadPath); //for debugging
robot.typeString(uploadPath);
robot.keyTap("enter");
browser.sleep(3000);
};
...
...
...
スペック
//Note: all code but uploadFile should be replaced with the code from your project
// this is just an example
it("should upload .png files successfully", function() {
...
...
...
//your page object function for opening the file explorer
//must return a promise otherwise the string will be typed too early
mediaPO.clickBrowseFileLink().then(function() {
mediaPO.uploadFile("teddy.png");
mediaPO.clickUploadNowButton(); //replace with your method of confirming upload.
expect(mediaPO.pngFileExists()).toBeTruthy();
});
};
理想的にはそこにその走行試験は、あなたがマウスときにそれを移動するためならば中にへのディレクトリパスを投稿しrobotjsデスクトップ役に立たないレンダリングするので完全にファイルブラウザを避けることができ、入力フィールドになりますパスをタイプする必要があります。あなたのテキストエディタ)。私はこれを動作させることができましたが、後で家に帰るとコードサンプルを投稿することができます。 – sonhu