|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Licensed to the Software Freedom Conservancy (SFC) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The SFC licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +require_relative '../spec_helper' |
| 21 | + |
| 22 | +module Selenium |
| 23 | + module WebDriver |
| 24 | + class BiDi |
| 25 | + describe BrowsingContext, exclusive: {browser: %i[chrome firefox]} do |
| 26 | + before do |
| 27 | + quit_driver |
| 28 | + create_driver!(web_socket_url: true) |
| 29 | + end |
| 30 | + |
| 31 | + it 'can create a browsing context for given id' do |
| 32 | + id = driver.window_handle |
| 33 | + browsing_context = BrowsingContext.new(driver: driver, browsing_context_id: id) |
| 34 | + expect(browsing_context.id).to eq(id) |
| 35 | + end |
| 36 | + |
| 37 | + it 'can create a window' do |
| 38 | + browsing_context = BrowsingContext.new(driver: driver, type: :window) |
| 39 | + expect(browsing_context.id).not_to be_nil |
| 40 | + end |
| 41 | + |
| 42 | + it 'can create a window with a reference context' do |
| 43 | + browsing_context = BrowsingContext.new(driver: driver, type: :window, |
| 44 | + reference_context: driver.window_handle) |
| 45 | + expect(browsing_context.id).not_to be_nil |
| 46 | + end |
| 47 | + |
| 48 | + it 'can create a tab' do |
| 49 | + browsing_context = BrowsingContext.new(driver: driver, type: :tab) |
| 50 | + expect(browsing_context.id).not_to be_nil |
| 51 | + end |
| 52 | + |
| 53 | + it 'can create a tab with a reference context' do |
| 54 | + browsing_context = BrowsingContext.new(driver: driver, type: :tab, reference_context: driver.window_handle) |
| 55 | + expect(browsing_context.id).not_to be_nil |
| 56 | + end |
| 57 | + |
| 58 | + it 'can navigate to a url' do |
| 59 | + browsing_context = BrowsingContext.new(driver: driver, type: :tab) |
| 60 | + |
| 61 | + info = browsing_context.navigate url: url_for('/bidi/logEntryAdded.html') |
| 62 | + |
| 63 | + expect(browsing_context.id).not_to be_nil |
| 64 | + expect(info.navigation_id).to be_nil |
| 65 | + expect(info.url).to include('/bidi/logEntryAdded.html') |
| 66 | + end |
| 67 | + |
| 68 | + it 'can navigate to a url with readiness state' do |
| 69 | + browsing_context = BrowsingContext.new(driver: driver, type: :tab) |
| 70 | + |
| 71 | + info = browsing_context.navigate url: url_for('/bidi/logEntryAdded.html'), |
| 72 | + readiness_state: :complete |
| 73 | + |
| 74 | + expect(browsing_context.id).not_to be_nil |
| 75 | + expect(info.navigation_id).to be_nil |
| 76 | + expect(info.url).to include('/bidi/logEntryAdded.html') |
| 77 | + end |
| 78 | + |
| 79 | + it 'can get tree with a child' do |
| 80 | + browsing_context_id = driver.window_handle |
| 81 | + parent_window = BrowsingContext.new(driver: driver, browsing_context_id: browsing_context_id) |
| 82 | + parent_window.navigate(url: url_for('iframes.html'), |
| 83 | + readiness_state: :complete) |
| 84 | + |
| 85 | + context_info = parent_window.get_tree |
| 86 | + expect(context_info.children.size).to eq(1) |
| 87 | + expect(context_info.id).to eq(browsing_context_id) |
| 88 | + expect(context_info.children[0]["url"]).to include('formPage.html') |
| 89 | + end |
| 90 | + |
| 91 | + it 'can get tree with depth' do |
| 92 | + browsing_context_id = driver.window_handle |
| 93 | + parent_window = BrowsingContext.new(driver: driver, browsing_context_id: browsing_context_id) |
| 94 | + parent_window.navigate(url: url_for('iframes.html'), |
| 95 | + readiness_state: :complete) |
| 96 | + |
| 97 | + context_info = parent_window.get_tree(max_depth: 0) |
| 98 | + expect(context_info.children).to be_nil |
| 99 | + expect(context_info.id).to eq(browsing_context_id) |
| 100 | + end |
| 101 | + |
| 102 | + it 'can close a window' do |
| 103 | + window1 = BrowsingContext.new(driver: driver, type: :window) |
| 104 | + window2 = BrowsingContext.new(driver: driver, type: :window) |
| 105 | + |
| 106 | + window2.close |
| 107 | + |
| 108 | + expect { window1.get_tree }.not_to raise_error |
| 109 | + expect { window2.get_tree }.to raise_error(Error::WebDriverError) |
| 110 | + end |
| 111 | + end # BrowsingContext |
| 112 | + end # BiDi |
| 113 | + end # WebDriver |
| 114 | +end # Selenium |
0 commit comments