|
| 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 | + |
| 21 | +require_relative '../spec_helper' |
| 22 | + |
| 23 | +module Selenium |
| 24 | + module WebDriver |
| 25 | + class BiDi |
| 26 | + describe Network, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'}, |
| 27 | + only: {browser: %i[chrome edge firefox]} do |
| 28 | + it 'adds an intercept' do |
| 29 | + reset_driver!(web_socket_url: true) do |driver| |
| 30 | + network = described_class.new(driver.bidi) |
| 31 | + intercept = network.add_intercept(phases: [described_class::PHASES[:before_request]]) |
| 32 | + expect(intercept).not_to be_nil |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + it 'removes an intercept' do |
| 37 | + reset_driver!(web_socket_url: true) do |driver| |
| 38 | + network = described_class.new(driver.bidi) |
| 39 | + intercept = network.add_intercept(phases: [described_class::PHASES[:before_request]]) |
| 40 | + expect(network.remove_intercept(intercept['intercept'])).to be_empty |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + it 'continues with auth' do |
| 45 | + username = SpecSupport::RackServer::TestApp::BASIC_AUTH_CREDENTIALS.first |
| 46 | + password = SpecSupport::RackServer::TestApp::BASIC_AUTH_CREDENTIALS.last |
| 47 | + reset_driver!(web_socket_url: true) do |driver| |
| 48 | + network = described_class.new(driver.bidi) |
| 49 | + network.add_intercept(phases: [described_class::PHASES[:auth_required]]) |
| 50 | + network.on(:auth_required) do |event| |
| 51 | + request_id = event['requestId'] |
| 52 | + network.continue_with_auth(request_id, username, password) |
| 53 | + end |
| 54 | + |
| 55 | + driver.navigate.to url_for('basicAuth') |
| 56 | + expect(driver.find_element(tag_name: 'h1').text).to eq('authorized') |
| 57 | + end |
| 58 | + end |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | +end |
0 commit comments