Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/features_spec.rb
4041 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 File.expand_path('../spec_helper', __dir__)2021module Selenium22module WebDriver23module Remote24describe Features do25let(:http) { WebDriver::Remote::Http::Default.new }26let(:bridge) { Bridge.new(http_client: http, url: 'http://localhost') }2728before do29allow(http).to receive(:request)30.with(any_args)31.and_return('status' => 200, 'value' => {'sessionId' => 'foo', 'capabilities' => {}})3233bridge.create_session({})34bridge.extend(Features)35bridge.add_commands(Features::REMOTE_COMMANDS)36end3738describe '#fire_session_event' do39it 'fires event with payload' do40allow(http).to receive(:request)41.with(:post, URI('http://localhost/session/foo/se/event'), any_args)42.and_return('value' => {'success' => true, 'eventType' => 'test:failed'})4344result = bridge.fire_session_event('test:failed', {testName: 'LoginTest', error: 'Element not found'})4546expect(http).to have_received(:request)47.with(:post, URI('http://localhost/session/foo/se/event'), any_args)48expect(result['success']).to be true49expect(result['eventType']).to eq 'test:failed'50end5152it 'fires event without payload' do53allow(http).to receive(:request)54.with(:post, URI('http://localhost/session/foo/se/event'), any_args)55.and_return('value' => {'success' => true, 'eventType' => 'log:collect'})5657result = bridge.fire_session_event('log:collect')5859expect(http).to have_received(:request)60.with(:post, URI('http://localhost/session/foo/se/event'), any_args)61expect(result['success']).to be true62expect(result['eventType']).to eq 'log:collect'63end64end6566describe 'REMOTE_COMMANDS' do67it 'includes fire_session_event command' do68expect(Features::REMOTE_COMMANDS).to include(:fire_session_event)69expect(Features::REMOTE_COMMANDS[:fire_session_event]).to eq [:post, 'session/:session_id/se/event']70end71end72end73end74end75end7677