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

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

问题描述

我正在用量角器编写测试,它是一个基于 JS 的框架和用于运行测试的 selenium 测试堆栈.我遇到了必须测试文件上传的问题.

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.

我遇到的问题是我尝试上传的文件在测试包中,而 selenium 节点是一个单独的服务器,因此它不会获取文件.我尝试使用文件描述符,尽管文件名设置了内容不会上传.

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.

下面是我的代码片段.

  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);

你有什么相同的输入吗?或者你知道有谁使用 selenium 在 JS 中编写了文件上传测试?非常感谢您的帮助

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

推荐答案

首先,对于远程 selenium 服务器的文件上传,你需要最新的量角器(目前,3.0.0)(将最新的 selenium-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).

然后,这两行对于能够通过网络将文件发送到 selenium 节点至关重要:

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);
    });
});

另见相关问题:

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

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