Path: blob/trunk/rb/spec/integration/selenium/webdriver/bidi/browser_spec.rb
4236 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 WebDriver23class BiDi24describe Browser, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'},25only: {browser: %i[chrome edge firefox]} do26after { |example| reset_driver!(example: example) }2728let(:bidi) { driver.bidi }2930it 'creates an user context' do31browser = described_class.new(bidi)32user_context = browser.create_user_context33expect(user_context).not_to be_nil34expect(user_context['userContext']).to be_a String35end3637it 'gets user contexts' do38browser = described_class.new(bidi)39created_context_id = browser.create_user_context['userContext']40all_context_ids = browser.user_contexts['userContexts'].map { |c| c['userContext'] }4142expect(all_context_ids).to include(created_context_id)43end4445it 'removes an user context' do46browser = described_class.new(bidi)47context_id_to_remove = browser.create_user_context['userContext']48browser.remove_user_context(context_id_to_remove)49all_ids_after_removal = browser.user_contexts['userContexts'].map { |c| c['userContext'] }5051expect(all_ids_after_removal).not_to include(context_id_to_remove)52end5354it 'throws an error when removing the default user context' do55browser = described_class.new(bidi)56expect {57browser.remove_user_context('default')58}.to raise_error(Error::WebDriverError, /user context cannot be removed/)59end6061it 'throws an error when removing a non-existent user context' do62browser = described_class.new(bidi)63expect {64browser.remove_user_context('fake_context')65}.to raise_error(Error::WebDriverError)66end6768it 'get windows' do69browser = described_class.new(bidi)70windows = browser.windows71active_window = windows.first7273expect(active_window).to be_a(Selenium::WebDriver::BiDi::Browser::Window)74end75end76end77end78end798081