Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/webdriver/bidi/browser_spec.rb
4236 views
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
after { |example| reset_driver!(example: example) }
28
29
let(:bidi) { driver.bidi }
30
31
it 'creates an user context' do
32
browser = described_class.new(bidi)
33
user_context = browser.create_user_context
34
expect(user_context).not_to be_nil
35
expect(user_context['userContext']).to be_a String
36
end
37
38
it 'gets user contexts' do
39
browser = described_class.new(bidi)
40
created_context_id = browser.create_user_context['userContext']
41
all_context_ids = browser.user_contexts['userContexts'].map { |c| c['userContext'] }
42
43
expect(all_context_ids).to include(created_context_id)
44
end
45
46
it 'removes an user context' do
47
browser = described_class.new(bidi)
48
context_id_to_remove = browser.create_user_context['userContext']
49
browser.remove_user_context(context_id_to_remove)
50
all_ids_after_removal = browser.user_contexts['userContexts'].map { |c| c['userContext'] }
51
52
expect(all_ids_after_removal).not_to include(context_id_to_remove)
53
end
54
55
it 'throws an error when removing the default user context' do
56
browser = described_class.new(bidi)
57
expect {
58
browser.remove_user_context('default')
59
}.to raise_error(Error::WebDriverError, /user context cannot be removed/)
60
end
61
62
it 'throws an error when removing a non-existent user context' do
63
browser = described_class.new(bidi)
64
expect {
65
browser.remove_user_context('fake_context')
66
}.to raise_error(Error::WebDriverError)
67
end
68
69
it 'get windows' do
70
browser = described_class.new(bidi)
71
windows = browser.windows
72
active_window = windows.first
73
74
expect(active_window).to be_a(Selenium::WebDriver::BiDi::Browser::Window)
75
end
76
end
77
end
78
end
79
end
80
81