|
| 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 Browser, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'}, |
| 26 | + only: {browser: %i[chrome edge firefox]} do |
| 27 | + it 'creates an user context' do |
| 28 | + reset_driver!(web_socket_url: true) do |driver| |
| 29 | + browser = described_class.new(driver.bidi) |
| 30 | + user_context = browser.create_user_context |
| 31 | + expect(user_context).not_to be_nil |
| 32 | + expect(user_context['userContext']).to be_a String |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + it 'gets user contexts' do |
| 37 | + reset_driver!(web_socket_url: true) do |driver| |
| 38 | + browser = described_class.new(driver.bidi) |
| 39 | + created_context_id = browser.create_user_context['userContext'] |
| 40 | + all_context_ids = browser.user_contexts['userContexts'].map { |c| c['userContext'] } |
| 41 | + |
| 42 | + expect(all_context_ids).to include(created_context_id) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + it 'removes an user context' do |
| 47 | + reset_driver!(web_socket_url: true) do |driver| |
| 48 | + browser = described_class.new(driver.bidi) |
| 49 | + context_id_to_remove = browser.create_user_context['userContext'] |
| 50 | + browser.remove_user_context(context_id_to_remove) |
| 51 | + all_ids_after_removal = browser.user_contexts['userContexts'].map { |c| c['userContext'] } |
| 52 | + |
| 53 | + expect(all_ids_after_removal).not_to include(context_id_to_remove) |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + it 'throws an error when removing the default user context' do |
| 58 | + reset_driver!(web_socket_url: true) do |driver| |
| 59 | + browser = described_class.new(driver.bidi) |
| 60 | + expect { |
| 61 | + browser.remove_user_context('default') |
| 62 | + }.to raise_error(Error::WebDriverError, /user context cannot be removed/) |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + it 'throws an error when removing a non-existent user context' do |
| 67 | + reset_driver!(web_socket_url: true) do |driver| |
| 68 | + browser = described_class.new(driver.bidi) |
| 69 | + expect { |
| 70 | + browser.remove_user_context('fake_context') |
| 71 | + }.to raise_error(Error::WebDriverError) |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | +end |
0 commit comments