MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Selenium

Class Selenium

rb/spec/unit/selenium/server_spec.rb:23–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21require 'selenium/server'
22
23module Selenium
24 describe Server do
25 let(:mock_process) { instance_double(WebDriver::ChildProcess).as_null_object }
26 let(:port) { 4321 }
27 let(:jar) { 'selenium_server_deploy.jar' }
28
29 before { allow(File).to receive(:exist?).with(jar).and_return(true) }
30
31 it 'raises an error if the jar file does not exist' do
32 expect {
33 described_class.new('doesnt-exist.jar')
34 }.to raise_error(Errno::ENOENT)
35 end
36
37 describe '#start' do
38 let(:status_url) { "http://127.0.0.1:#{port}/status" }
39
40 before do
41 allow(WebDriver::ChildProcess).to receive(:build).and_return(mock_process)
42 allow(WebDriver::SocketPoller).to receive(:new)
43 .and_return(instance_double(WebDriver::SocketPoller, connected?: true))
44 stub_request(:get, status_url).to_return(body: {value: {ready: true}}.to_json)
45 end
46
47 it 'uses the given jar file and port' do
48 described_class.new(jar, port: port).start
49
50 expect(WebDriver::ChildProcess).to have_received(:build)
51 .with('java', '-jar', jar, 'standalone', '--port', port.to_s)
52 end
53
54 it 'waits for the server process by default' do
55 described_class.new(jar, port: port).start
56
57 expect(mock_process).to have_received(:wait)
58 end
59
60 it 'does not wait for the server process when running in the background' do
61 described_class.new(jar, port: port, background: true).start
62
63 expect(mock_process).not_to have_received(:wait)
64 end
65
66 it 'adds additional args' do
67 server = described_class.new(jar, port: port)
68 server << %w[foo bar]
69 server.start
70
71 expect(WebDriver::ChildProcess).to have_received(:build)
72 .with('java', '-jar', jar, 'standalone', '--port', port.to_s, 'foo', 'bar')
73 end
74
75 it 'adds additional JAVA options args' do
76 server = described_class.new(jar, port: port)
77 server << %w[foo bar]
78 server << '-Dwebdriver.chrome.driver=/bin/chromedriver'
79 server.start
80

Callers

nothing calls this directly

Calls 15

beFunction · 0.85
to_sMethod · 0.80
downloadMethod · 0.80
latestMethod · 0.80
toMethod · 0.65
withMethod · 0.65
startMethod · 0.65
runMethod · 0.65
readMethod · 0.65
getMethod · 0.65
logMethod · 0.65
newMethod · 0.45

Tested by

no test coverage detected