Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/features_spec.rb
4041 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 File.expand_path('../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
module Remote
25
describe Features do
26
let(:http) { WebDriver::Remote::Http::Default.new }
27
let(:bridge) { Bridge.new(http_client: http, url: 'http://localhost') }
28
29
before do
30
allow(http).to receive(:request)
31
.with(any_args)
32
.and_return('status' => 200, 'value' => {'sessionId' => 'foo', 'capabilities' => {}})
33
34
bridge.create_session({})
35
bridge.extend(Features)
36
bridge.add_commands(Features::REMOTE_COMMANDS)
37
end
38
39
describe '#fire_session_event' do
40
it 'fires event with payload' do
41
allow(http).to receive(:request)
42
.with(:post, URI('http://localhost/session/foo/se/event'), any_args)
43
.and_return('value' => {'success' => true, 'eventType' => 'test:failed'})
44
45
result = bridge.fire_session_event('test:failed', {testName: 'LoginTest', error: 'Element not found'})
46
47
expect(http).to have_received(:request)
48
.with(:post, URI('http://localhost/session/foo/se/event'), any_args)
49
expect(result['success']).to be true
50
expect(result['eventType']).to eq 'test:failed'
51
end
52
53
it 'fires event without payload' do
54
allow(http).to receive(:request)
55
.with(:post, URI('http://localhost/session/foo/se/event'), any_args)
56
.and_return('value' => {'success' => true, 'eventType' => 'log:collect'})
57
58
result = bridge.fire_session_event('log:collect')
59
60
expect(http).to have_received(:request)
61
.with(:post, URI('http://localhost/session/foo/se/event'), any_args)
62
expect(result['success']).to be true
63
expect(result['eventType']).to eq 'log:collect'
64
end
65
end
66
67
describe 'REMOTE_COMMANDS' do
68
it 'includes fire_session_event command' do
69
expect(Features::REMOTE_COMMANDS).to include(:fire_session_event)
70
expect(Features::REMOTE_COMMANDS[:fire_session_event]).to eq [:post, 'session/:session_id/se/event']
71
end
72
end
73
end
74
end
75
end
76
end
77