forked from SeleniumHQ/seleniumhq.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowsing_context_spec.rb
More file actions
109 lines (85 loc) · 4.29 KB
/
browsing_context_spec.rb
File metadata and controls
109 lines (85 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# frozen_string_literal: true
require 'selenium-webdriver'
RSpec.describe 'Browsing Context' do
let(:driver) do
options = Selenium::WebDriver::Options.firefox
options.add_option(:web_socket_url, true)
Selenium::WebDriver.for :firefox, options: options
end
after do
driver.quit
end
it 'test create a browsing context for given id' do
id = driver.window_handle
browsing_context = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, browsing_context_id: id)
expect(browsing_context.id).to eq(id)
end
it 'test create a window' do
browsing_context = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :window)
expect(browsing_context.id).not_to be_nil
end
it 'test create a window with a reference context' do
browsing_context = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :window,
reference_context: driver.window_handle)
expect(browsing_context.id).not_to be_nil
end
it 'test create a tab' do
browsing_context = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :tab)
expect(browsing_context.id).not_to be_nil
end
it 'test create a tab with a reference context' do
browsing_context = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :tab,
reference_context: driver.window_handle)
expect(browsing_context.id).not_to be_nil
end
it 'test navigate to a url' do
browsing_context = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :tab)
info = browsing_context.navigate url: 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html'
expect(browsing_context.id).not_to be_nil
expect(info.navigation_id).to be_nil
expect(info.url).to include('/bidi/logEntryAdded.html')
end
it 'test navigate to a url with readiness state' do
browsing_context = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :tab)
info = browsing_context.navigate url: 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html',
readiness_state: :complete
expect(browsing_context.id).not_to be_nil
expect(info.navigation_id).to be_nil
expect(info.url).to include('/bidi/logEntryAdded.html')
end
it 'test get tree with a child' do
browsing_context_id = driver.window_handle
parent_window = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver,
browsing_context_id: browsing_context_id)
parent_window.navigate(url: 'https://www.selenium.dev/selenium/web/iframes.html',
readiness_state: :complete)
context_info = parent_window.get_tree
expect(context_info.children.size).to eq(1)
expect(context_info.id).to eq(browsing_context_id)
expect(context_info.children[0]['url']).to include('formPage.html')
end
it 'test get tree with depth' do
browsing_context_id = driver.window_handle
parent_window = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver,
browsing_context_id: browsing_context_id)
parent_window.navigate(url: 'https://www.selenium.dev/selenium/web/iframes.html',
readiness_state: :complete)
context_info = parent_window.get_tree(max_depth: 0)
expect(context_info.children).to be_nil
expect(context_info.id).to eq(browsing_context_id)
end
it 'test close a window' do
window1 = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :window)
window2 = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :window)
window2.close
expect { window1.get_tree }.not_to raise_error
expect { window2.get_tree }.to raise_error(Selenium::WebDriver::Error::WebDriverError)
end
it 'test close a tab' do
tab1 = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :tab)
tab2 = Selenium::WebDriver::BiDi::BrowsingContext.new(driver: driver, type: :tab)
tab2.close
expect { tab1.get_tree }.not_to raise_error
expect { tab2.get_tree }.to raise_error(Selenium::WebDriver::Error::WebDriverError)
end
end