Path: blob/trunk/rb/spec/integration/selenium/webdriver/bidi/browsing_context_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 BrowsingContext, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'},25only: {browser: %i[chrome edge firefox]} do26after { |example| reset_driver!(example: example) }2728let(:bridge) { driver.instance_variable_get(:@bridge) }2930describe '#create' do31it 'without arguments' do32id = described_class.new(bridge).create3334expect(driver.window_handles).to include(id)35end3637it 'accepts a tab type' do38id = described_class.new(bridge).create(type: :tab)3940expect(driver.window_handles).to include(id)41end4243it 'accepts a window type' do44id = described_class.new(bridge).create(type: :window)4546expect(driver.window_handles).to include(id)47end4849it 'errors on unknown type', except: {browser: :firefox, reason: "Doesn't return the expected error"} do50msg = /invalid argument: Invalid enum value. Expected 'tab' | 'window', received 'unknown'/51expect {52described_class.new(bridge).create(type: :unknown)53}.to raise_error(Error::WebDriverError, msg)54end5556it 'accepts a reference context' do57id = driver.window_handle58result = described_class.new(bridge).create(context_id: id)5960expect(driver.window_handles).to include(id, result)61end62end6364it 'closes a window' do65browsing_context = described_class.new(bridge)66window1 = browsing_context.create67window2 = browsing_context.create6869browsing_context.close(context_id: window2)7071handles = driver.window_handles72expect(handles).to include(window1)73expect(handles).not_to include(window2)74end7576it 'sets the viewport', except: {rbe: true, reason: 'unknown, returns value of 1 instead of 2.0'} do77browsing_context = described_class.new(bridge)78browsing_context.set_viewport(width: 800, height: 600, device_pixel_ratio: 2.0)79expect(driver.execute_script('return [window.innerWidth, window.innerHeight]')).to eq([800, 600])80expect(driver.execute_script('return window.devicePixelRatio')).to eq(2.0)81end8283it 'accepts users prompts without text',84except: {browser: %i[edge chrome],85reason: 'https://github.com/GoogleChromeLabs/chromium-bidi/issues/3281'} do86browsing_context = described_class.new(bridge)8788driver.navigate.to url_for('alerts.html')89driver.find_element(id: 'alert').click90wait_for_alert91window = driver.window_handles.first92browsing_context.handle_user_prompt(window, accept: true)93wait_for_no_alert9495expect(driver.title).to eq('Testing Alerts')96end9798it 'accepts users prompts with text',99except: {browser: %i[edge chrome],100reason: 'https://github.com/GoogleChromeLabs/chromium-bidi/issues/3281'} do101browsing_context = described_class.new(bridge)102driver.navigate.to url_for('alerts.html')103driver.find_element(id: 'prompt').click104wait_for_alert105window = driver.window_handles.first106browsing_context.handle_user_prompt(window, accept: true, text: 'Hello, world!')107wait_for_no_alert108109expect(driver.title).to eq('Testing Alerts')110end111112it 'rejects users prompts', except: {browser: %i[edge chrome],113reason: 'https://github.com/GoogleChromeLabs/chromium-bidi/issues/3281'} do114browsing_context = described_class.new(bridge)115driver.navigate.to url_for('alerts.html')116driver.find_element(id: 'alert').click117wait_for_alert118window = driver.window_handles.first119120browsing_context.handle_user_prompt(window, accept: false)121wait_for_no_alert122123expect(driver.title).to eq('Testing Alerts')124end125126it 'activates a browser context' do127browsing_context = described_class.new(bridge)128browsing_context.create129130expect(driver.execute_script('return document.hasFocus();')).to be_falsey131browsing_context.activate132expect(driver.execute_script('return document.hasFocus();')).to be_truthy133end134end135end # BiDi136end # WebDriver137end # Selenium138139140