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

Class Selenium

rb/spec/unit/selenium/server_spec.rb:23–232  ·  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(:mock_poller) { instance_double(WebDriver::SocketPoller, connected?: true, closed?: true) }
27 let(:repo) { 'https://api.github.com/repos/seleniumhq/selenium/releases' }
28 let(:port) { WebDriver::PortProber.above(4444) }
29 let(:example_json) do
30 [{url: "#{repo}/41272273",
31 assets: {
32 name: 'selenium-server-3.141.59.jar',
33 browser_download_url: "#{repo}/selenium-3.141.59/selenium-server-standalone-3.141.59.jar"
34 }},
35 {url: "#{repo}/51272273",
36 assets: {
37 name: 'selenium-server-10.0.1.jar',
38 browser_download_url: "#{repo}/selenium-10.0.1/selenium-server-10.0.1.jar"
39 }}].to_json
40 end
41
42 it 'raises an error if the jar file does not exist' do
43 expect {
44 described_class.new('doesnt-exist.jar')
45 }.to raise_error(Errno::ENOENT)
46 end
47
48 it 'uses the given jar file and port' do
49 allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
50 allow(WebDriver::ChildProcess).to receive(:build)
51 .with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
52 .and_return(mock_process)
53
54 server = described_class.new('selenium_server_deploy.jar', port: 1234, background: true)
55 allow(server).to receive_messages(socket: mock_poller, status_ok?: true)
56
57 server.start
58 expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
59 expect(WebDriver::ChildProcess).to have_received(:build)
60 .with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
61 end
62
63 it 'waits for the server process by default' do
64 allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
65 allow(WebDriver::ChildProcess).to receive(:build)
66 .with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
67 .and_return(mock_process)
68
69 server = described_class.new('selenium_server_deploy.jar', port: port)
70 allow(server).to receive_messages(socket: mock_poller, status_ok?: true)
71 allow(mock_process).to receive(:wait)
72
73 server.start
74
75 expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
76 expect(WebDriver::ChildProcess).to have_received(:build)
77 .with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
78 expect(mock_process).to have_received(:wait)
79 end
80

Callers

nothing calls this directly

Calls 15

beFunction · 0.85
to_sMethod · 0.80
downloadMethod · 0.80
net_http_startMethod · 0.80
latestMethod · 0.80
toMethod · 0.65
withMethod · 0.65
startMethod · 0.65
getMethod · 0.65
logMethod · 0.65
aboveMethod · 0.45
to_jsonMethod · 0.45

Tested by

no test coverage detected