远程文件上传量角器测试 [英] Remote File Upload Protractor test

查看:319
本文介绍了远程文件上传量角器测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在量角器测试其运行测试一个基于JS框架和硒试验堆。我现在面临一个问题,我就来测试文件上传

I am writing tests in protractor which a JS based framework and selenium test stack for running tests. I am facing an issue where I have to test file upload.

我有问题就是我想上传文件是在测试包,而硒节点是一个单独的服务器,因此不会得到该文件。
  我试着用文件描述符虽然文件名被设置的内容不会上载到。

Problem I am having is File I am trying to upload is in the test package whereas selenium node is a separate server so it will not get the file. I tried using file descriptor although the file name is set contents don’t get uploaded.

下面是code段,我有。

Below is the code snippet that I have.

  var remote = require('selenium-webdriver/remote');
   browser.setFileDetector(new remote.FileDetector());
   var absolutePath = path.resolve(__dirname, "../specs/data/baseProducts.csv");
   $('input[type="file"]').sendKeys(absolutePath);

你有相同的投入?
  或者你知道是谁使用硒书面文件上传测试中JS的人?
  您的帮助将非常AP preciated

Do you have any inputs for the same? Or do you know anyone who has written file upload tests in JS using selenium? Your help will be much appreciated

推荐答案

首先,对文件上传到远程硒服务器的工作,你需要最新的量角器 (目前,3.0.0)(这将有最新的硒的webdriver 包的NodeJS作为依赖)。

First of all, for the file upload to work with remote selenium servers, you need the latest protractor (currently, 3.0.0) (which would have the latest selenium-webdriver nodejs package as a dependency).

然后,这两条线都能够通过网络发送文件到硒节点关键:

Then, these two lines are crucial to be able to send files over the wire to the selenium node:

var remote = require('selenium-webdriver/remote');
browser.setFileDetector(new remote.FileDetector());

而且,现在你应该可以,如果你是在本地运行测试来上传文件。

And, now you should be able to upload files as if you are running tests locally.

完整的工作测试的(上BrowserStack测试,对我的作品完美):

Complete working test (tested on BrowserStack, works for me perfectly):

var path = require('path'),
    remote = require('selenium-webdriver/remote');

describe("File upload test", function () {
    beforeEach(function () {
        browser.setFileDetector(new remote.FileDetector());
        browser.get("https://angular-file-upload.appspot.com/");
    });

    it("should upload an image", function () {
        var input = element(by.model("picFile")),
            uploadedThumbnail = $("img[ngf-src=picFile]");

        // no image displayed
        expect(uploadedThumbnail.isDisplayed()).toBe(true);

        // assuming you have "test.jpg" right near the spec itself
        input.sendKeys(path.resolve(__dirname, "test.jpg"));

        // there is a little uploaded image displayed
        expect(uploadedThumbnail.isDisplayed()).toBe(true);
    });
});

另请参阅相关的问题:

Also see relevant issues:

  • setFileDectector unable to set remote file detector
  • Protractor file uploads - Support remote uploads with webdriver setFileDetector & LocalFileDetector

这篇关于远程文件上传量角器测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆