1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Use file_detector for remote tests

This commit is contained in:
Thomas Walpole 2018-06-25 15:28:30 -07:00
parent 1bb31b3ae0
commit 1b547439ca
4 changed files with 42 additions and 23 deletions

View file

@ -7,12 +7,12 @@ services:
image: "selenium/${SELENIUM_IMAGE:-standalone-chrome-debug}"
volumes:
- "/dev/shm:/dev/shm"
- "${PWD}:${PWD}" # For making attach_file specs work
# - "${PWD}:${PWD}" # For making attach_file specs work
selenium_firefox:
network_mode: "host"
image: "selenium/${SELENIUM_IMAGE:-standalone-firefox-debug}"
volumes:
- "/dev/shm:/dev/shm"
- "${PWD}:${PWD}" # For making attach_file specs work
# - "${PWD}:${PWD}" # For making attach_file specs work
environment:
- SE_OPTS=-port 4445

View file

@ -39,6 +39,19 @@ module TestSessions
Chrome = Capybara::Session.new(CHROME_REMOTE_DRIVER, TestApp)
end
TestSessions::Chrome.driver.browser.file_detector = lambda do |args|
# args => ["/path/to/file"]
str = args.first.to_s
str if File.exist?(str)
end
session.driver.browser.file_detector = lambda do |args|
# args => ["/path/to/file"]
str = args.first.to_s
str if File.exist?(str)
end
skipped_tests = %i[response_headers status_code trigger download]
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])

View file

@ -39,6 +39,12 @@ module TestSessions
Firefox = Capybara::Session.new(FIREFOX_REMOTE_DRIVER, TestApp)
end
TestSessions::Firefox.driver.browser.file_detector = lambda do |args|
# args => ["/path/to/file"]
str = args.first.to_s
str if File.exist?(str)
end
skipped_tests = %i[response_headers status_code trigger download]
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])

View file

@ -264,27 +264,27 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
end
end
describe "#attach_file" do
before do
session.visit('/form')
end
after do
session.driver.browser.file_detector = nil if session.driver.browser.respond_to?(:file_detector=)
end
it "uploads the file when file_detector is used", :focus_ do
skip "Only test on remote drivers" unless session.driver.browser.respond_to?(:file_detector=)
session.driver.browser.file_detector = lambda do |args|
# args => ["/path/to/file"]
str = args.first.to_s
str if File.exist?(str)
end
session.attach_file "form_image", with_os_path_separators(__FILE__)
session.click_button('awesome')
expect(extract_results(session)['image']).to eq(File.basename(__FILE__))
end
end
# describe "#attach_file" do
# before do
# session.visit('/form')
# end
#
# after do
# session.driver.browser.file_detector = nil if session.driver.browser.respond_to?(:file_detector=)
# end
#
# it "uploads the file when file_detector is used", :focus_ do
# skip "Only test on remote drivers" unless session.driver.browser.respond_to?(:file_detector=)
# session.driver.browser.file_detector = lambda do |args|
# # args => ["/path/to/file"]
# str = args.first.to_s
# str if File.exist?(str)
# end
# session.attach_file "form_image", with_os_path_separators(__FILE__)
# session.click_button('awesome')
# expect(extract_results(session)['image']).to eq(File.basename(__FILE__))
# end
# end
context "Windows" do
it "can't close the primary window" do