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}" image: "selenium/${SELENIUM_IMAGE:-standalone-chrome-debug}"
volumes: volumes:
- "/dev/shm:/dev/shm" - "/dev/shm:/dev/shm"
- "${PWD}:${PWD}" # For making attach_file specs work # - "${PWD}:${PWD}" # For making attach_file specs work
selenium_firefox: selenium_firefox:
network_mode: "host" network_mode: "host"
image: "selenium/${SELENIUM_IMAGE:-standalone-firefox-debug}" image: "selenium/${SELENIUM_IMAGE:-standalone-firefox-debug}"
volumes: volumes:
- "/dev/shm:/dev/shm" - "/dev/shm:/dev/shm"
- "${PWD}:${PWD}" # For making attach_file specs work # - "${PWD}:${PWD}" # For making attach_file specs work
environment: environment:
- SE_OPTS=-port 4445 - SE_OPTS=-port 4445

View File

@ -39,6 +39,19 @@ module TestSessions
Chrome = Capybara::Session.new(CHROME_REMOTE_DRIVER, TestApp) Chrome = Capybara::Session.new(CHROME_REMOTE_DRIVER, TestApp)
end 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] skipped_tests = %i[response_headers status_code trigger download]
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome # 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']) 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) Firefox = Capybara::Session.new(FIREFOX_REMOTE_DRIVER, TestApp)
end 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] skipped_tests = %i[response_headers status_code trigger download]
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome # 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']) 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
end end
describe "#attach_file" do # describe "#attach_file" do
before do # before do
session.visit('/form') # session.visit('/form')
end # end
#
after do # after do
session.driver.browser.file_detector = nil if session.driver.browser.respond_to?(:file_detector=) # session.driver.browser.file_detector = nil if session.driver.browser.respond_to?(:file_detector=)
end # end
#
it "uploads the file when file_detector is used", :focus_ do # 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=) # skip "Only test on remote drivers" unless session.driver.browser.respond_to?(:file_detector=)
session.driver.browser.file_detector = lambda do |args| # session.driver.browser.file_detector = lambda do |args|
# args => ["/path/to/file"] # # args => ["/path/to/file"]
str = args.first.to_s # str = args.first.to_s
str if File.exist?(str) # str if File.exist?(str)
end # end
session.attach_file "form_image", with_os_path_separators(__FILE__) # session.attach_file "form_image", with_os_path_separators(__FILE__)
session.click_button('awesome') # session.click_button('awesome')
expect(extract_results(session)['image']).to eq(File.basename(__FILE__)) # expect(extract_results(session)['image']).to eq(File.basename(__FILE__))
end # end
end # end
context "Windows" do context "Windows" do
it "can't close the primary window" do it "can't close the primary window" do