Path: blob/trunk/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require_relative '../spec_helper'2021module Selenium22module WebDriver23module Remote24describe Driver, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {driver: :remote}] do25let(:tempfile) { create_tempfile }2627it 'exposes session_id' do28expect(driver.session_id).to be_a(String)29end3031it 'exposes remote status' do32expect(driver.status).to be_a(Hash)33end3435it 'uses a default file detector',36flaky: {browser: :safari, ci: :github, reason: 'unreliable with downloads'} do37driver.navigate.to url_for('upload.html')3839driver.find_element(id: 'upload').send_keys(tempfile.path)40driver.find_element(id: 'go').submit41wait.until { driver.find_element(id: 'upload_label').displayed? }4243driver.switch_to.frame('upload_target')44wait.until { driver.find_element(xpath: '//body') }4546body = driver.find_element(xpath: '//body')47expect(body.text.scan('This is a dummy test file').count).to eq(1)48end4950it 'lists downloads', exclude: {browser: :safari, reason: 'grid hangs'} do51reset_driver!(enable_downloads: true) do |driver|52browser_downloads(driver)5354file_names = %w[file_1.txt file_2.jpg]5556expect(driver.downloadable_files).to match_array(file_names)57end58end5960it 'downloads a file', exclude: {browser: :safari, reason: 'grid hangs'} do61target_directory = File.join(Dir.tmpdir.to_s, SecureRandom.uuid)62at_exit { FileUtils.rm_f(target_directory) }6364reset_driver!(enable_downloads: true) do |driver|65browser_downloads(driver)6667file_name = 'file_1.txt'68driver.download_file(file_name, target_directory)6970file_content = File.read("#{target_directory}/#{file_name}").strip71expect(file_content).to eq('Hello, World!')72end73end7475it 'deletes downloadable files', exclude: {browser: :safari, reason: 'grid hangs'} do76reset_driver!(enable_downloads: true) do |driver|77browser_downloads(driver)7879driver.delete_downloadable_files8081expect(driver.downloadable_files).to be_empty82end83end8485it 'errors when not set', {except: {browser: :firefox, reason: 'grid always sets true and firefox returns it'},86exclude: {browser: :safari, reason: 'grid hangs'}} do87reset_driver!(enable_downloads: false) do |driver|88expect {89driver.downloadable_files90}.to raise_exception(Error::WebDriverError,91'You must enable downloads in order to work with downloadable files.')92end93end9495private9697def browser_downloads(driver)98driver.navigate.to url_for('downloads/download.html')99driver.find_element(id: 'file-1').click100driver.find_element(id: 'file-2').click101102wait.until { driver.downloadable_files.include? 'file_2.jpg' }103end104end105end # Remote106end # WebDriver107end # Selenium108109110