attach_file与capybara-webkit无法正常工作 [英] attach_file isn't working the right way with capybara-webkit

查看:224
本文介绍了attach_file与capybara-webkit无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < input type =filename = imagemultiple =accept =image / *> 

当我使用 selenium driver,是:

$ pre $ attach_file('image',File.absolute_path('../ pictures / pic1.JPG' ))
attach_file('image',File.absolute_path('../ pictures / pic2.JPG'))
attach_file('image',File.absolute_path('../ pictures / pic3。 JPG))

当我使用 capybara-webkit :由于输入被隐藏,一些元素重叠,我需要改变一些css属性:

 页面.execute_script($('input [name = image]')。css('opacity','1'))
page.execute_script($('input [name = image]') ('position','fixed'))
page.execute_script($('input [name = image]')。css('top','620px'))

即使测试通过,图片也无法正确上传。如果我使用 page.save_screenshot('after_upload.png')来看看发生了什么事情:



预期的结果当使用 selenium 驱动程序时) - >

解决方案

我刚刚发现一个修复:在每次上传图片后都放上 sleep(3)

I'm trying to attach some files to this input:

<input type="file" name="image" multiple="" accept="image/*">

My code, that is working when I use selenium driver, is:

attach_file('image', File.absolute_path('../pictures/pic1.JPG'))
attach_file('image', File.absolute_path('../pictures/pic2.JPG'))
attach_file('image', File.absolute_path('../pictures/pic3.JPG'))

The problems come when I use capybara-webkit: as the input is hidden and some elements overlaps it, I need to change some css properties:

page.execute_script("$('input[name=image]').css('opacity','1')")
page.execute_script("$('input[name=image]').css('position','fixed')")
page.execute_script("$('input[name=image]').css('top','620px')")

And even if the test passes, the pictures aren't uploading the right way. If I use page.save_screenshot('after_upload.png') to see what's happening:

Expected result (and result when using selenium driver) ->

Actual result when using capybara-webkit ->

解决方案

I just found a "fix": put a sleep(3) after each image upload!

这篇关于attach_file与capybara-webkit无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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