最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uploading an image file with Nightwatch.js - Stack Overflow

programmeradmin3浏览0评论

I'm running front-end tests using nightwatch.js using the Chrome Driver. I need to test that image uploading works properly, presumably through the provided file input since there are callbacks that run on a successful post.

I'm aware that this can be done using sendKeys method of the Selenium Web Driver.

How can you accomplish this using javascript and nightwatch.js? Can you access the Selenium webdriver or an interface with it?

I'm running front-end tests using nightwatch.js using the Chrome Driver. I need to test that image uploading works properly, presumably through the provided file input since there are callbacks that run on a successful post.

I'm aware that this can be done using sendKeys method of the Selenium Web Driver.

How can you accomplish this using javascript and nightwatch.js? Can you access the Selenium webdriver or an interface with it?

Share Improve this question asked Jun 26, 2014 at 21:40 JeffpowrsJeffpowrs 4,5404 gold badges31 silver badges49 bronze badges 1
  • i'd be interested to see how a file is chosen, i didn't think such a thing was possible. – dandavis Commented Jun 26, 2014 at 22:26
Add a comment  | 

6 Answers 6

Reset to default 8

Use this for uploading image from local desktop

.setValue('input[type="file"]', require('path').resolve('/home/My-PC/Desktop/img.png')) 

As someone above has mentioned, you can pass the absolute path to your input[type="file"] as if you were typing text into a field.

This uses nightwatch's setValue function. You can retrieve the current directory path using Node's __dirname global var.

For example: .setValue('#upload-input', __dirname + '\\upload.jpg')

Use client.setValue function to set the absolute path of your image. Here is the working example in my project.

client.setValue('#editPictures .modal-body input[type="file"]', '/Users/testing/pictures/CAM00003.jpg');

In my case there is a div with id="Upload Icon" which has input with type="file"

.setValue('//div[@id="Upload Icon"]/input[@type="file"]', require('path').resolve(__dirname + '/categoryIcon.png'))

The above code working fine for me.

This solution worked for me:

.setValue('#file-upload', require('path').resolve('C:/Users/Mihai/Desktop/test.png'))

this worked for me.

.setValue('input[type="file"]', require('path').resolve('/home/My-PC/Desktop/img.png'))

Only thing maybe others running into might the different versions of firefox where it didn't work 2 yrs back for a co-worker.

发布评论

评论列表(0)

  1. 暂无评论