|
| 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 | + 2.times { browser.create_user_context } |
| 40 | + expect(browser.get_user_contexts['userContexts'].count).to eq 3 |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + it 'removes an user context' do |
| 45 | + reset_driver!(web_socket_url: true) do |driver| |
| 46 | + browser = described_class.new(driver.bidi) |
| 47 | + user_context = browser.create_user_context |
| 48 | + expect(browser.get_user_contexts['userContexts'].count).to eq 2 |
| 49 | + browser.remove_user_context(user_context['userContext']) |
| 50 | + expect(browser.get_user_contexts['userContexts'].count).to eq 1 |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + it 'throws an error when removing the default user context' do |
| 55 | + reset_driver!(web_socket_url: true) do |driver| |
| 56 | + browser = described_class.new(driver.bidi) |
| 57 | + expect { |
| 58 | + browser.remove_user_context('default') |
| 59 | + }.to raise_error(Error::WebDriverError, /user context cannot be removed/) |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + it 'throws an error when removing a non-existent user context' do |
| 64 | + reset_driver!(web_socket_url: true) do |driver| |
| 65 | + browser = described_class.new(driver.bidi) |
| 66 | + expect { |
| 67 | + browser.remove_user_context('fake_context') |
| 68 | + }.to raise_error(Error::WebDriverError, /Failed to find context with id/) |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | +end |
0 commit comments