【发布时间】:2019-01-30 00:33:04
【问题描述】:
使用 selenium webdriver 3.12 并在 saucelabs(硒网格)上运行文件上传测试作为 Win 10 chrome 66。我尝试实现文件检测器并将密钥发送到我的代码中,以便系统可以将文件从我的本地机器并在 saucelabs 中使用,但遇到错误:
Selenium::WebDriver::Error::ExpectedError:
invalid argument: File not found : /Users/john.doe/Work/project/spec/support/apps/files/suggested_content/valid_sc.csv
(Session info: chrome=66.0.3359.117)
(Driver info: chromedriver=2.38.551601 (edb21f07fc70e9027c746edd3201443e011a61ed),platform=Windows NT 10.0.10586 x86_64)
我实现这一点的方式是将文件检测器添加为我的规范帮助程序的一部分,然后在我的规范文件顶部需要规范帮助程序,然后使用 sendkeys 发送文件上传的路径。类似于Saucelabs best practices here
来自我的规范助手内部的一个 sn-p... 我已经实例化了驱动程序并添加了文件检测器的代码(这是从酱汁和 rubydoc 的使用稍微调整的,因为它使用当前会话驱动程序而不是驱动程序) :
Capybara::Selenium::Driver.new(app,
browser: :remote,
url: url,
desired_capabilities: capabilities)
end
Capybara.current_session.driver.browser.file_detector = lambda do |args|
str = args.first.to_s
str if File.exist?(str)
end
以及上传文件的调用方法:
def add_file(file_name = 'valid_sc.csv')
path = './spec/support/apps/files/suggested_content/'
expose_file_upload
page.find('input[id*=content--add-file')
.send_keys(File.expand_path(path + file_name))
end
该文件肯定位于该路径,并且当我在本地运行测试时工作正常。我在这里错过了什么?
【问题讨论】:
标签: ruby selenium rspec capybara selenium-grid