Path: blob/trunk/rb/spec/integration/selenium/webdriver/bidi/browser_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 WebDriver23class BiDi24describe Browser, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'},25only: {browser: %i[chrome edge firefox]} do26it 'creates an user context' do27reset_driver!(web_socket_url: true) do |driver|28browser = described_class.new(driver.bidi)29user_context = browser.create_user_context30expect(user_context).not_to be_nil31expect(user_context['userContext']).to be_a String32end33end3435it 'gets user contexts' do36reset_driver!(web_socket_url: true) do |driver|37browser = described_class.new(driver.bidi)38created_context_id = browser.create_user_context['userContext']39all_context_ids = browser.user_contexts['userContexts'].map { |c| c['userContext'] }4041expect(all_context_ids).to include(created_context_id)42end43end4445it 'removes an user context' do46reset_driver!(web_socket_url: true) do |driver|47browser = described_class.new(driver.bidi)48context_id_to_remove = browser.create_user_context['userContext']49browser.remove_user_context(context_id_to_remove)50all_ids_after_removal = browser.user_contexts['userContexts'].map { |c| c['userContext'] }5152expect(all_ids_after_removal).not_to include(context_id_to_remove)53end54end5556it 'throws an error when removing the default user context' do57reset_driver!(web_socket_url: true) do |driver|58browser = described_class.new(driver.bidi)59expect {60browser.remove_user_context('default')61}.to raise_error(Error::WebDriverError, /user context cannot be removed/)62end63end6465it 'throws an error when removing a non-existent user context' do66reset_driver!(web_socket_url: true) do |driver|67browser = described_class.new(driver.bidi)68expect {69browser.remove_user_context('fake_context')70}.to raise_error(Error::WebDriverError)71end72end73end74end75end76end777879