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

Method start

py/selenium/webdriver/remote/server.py:178–217  ·  view source on GitHub ↗

Start the server. Selenium Manager will detect the server location and download it if necessary, unless an existing server path was specified.

(self)

Source from the content-addressed store, hash-verified

176 return SeleniumManager().binary_paths(args)["driver_path"]
177
178 def start(self):
179 """Start the server.
180
181 Selenium Manager will detect the server location and download it if necessary,
182 unless an existing server path was specified.
183 """
184 path = self.download_if_needed(self.version) if self.path is None else self.path
185
186 java_path = self.java_path or shutil.which("java")
187 if java_path is None:
188 raise OSError("Can't find java on system PATH. JRE is required to run the Selenium server")
189
190 command = [
191 java_path,
192 "-jar",
193 path,
194 "standalone",
195 "--port",
196 str(self.port),
197 "--log-level",
198 self.log_level,
199 *self.args,
200 ]
201 if self.host is not None:
202 command.extend(["--host", self.host])
203
204 host = self.host if self.host is not None else "localhost"
205
206 try:
207 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
208 sock.connect((host, self.port))
209 raise ConnectionError(f"Selenium server is already running, or something else is using port {self.port}")
210 except ConnectionRefusedError:
211 print("Starting Selenium server...")
212 self.process = subprocess.Popen(command, env=self.env)
213 print(f"Selenium server running as process: {self.process.pid}")
214 if not self._wait_for_server(timeout=self.startup_timeout):
215 raise TimeoutError(f"Timed out waiting for Selenium server at {self.status_url}") from None
216 print("Selenium server is ready")
217 return self.process
218
219 def stop(self):
220 """Stop the server."""

Callers 1

serverFunction · 0.95

Calls 5

download_if_neededMethod · 0.95
_wait_for_serverMethod · 0.95
TimeoutErrorClass · 0.50
socketMethod · 0.45
connectMethod · 0.45

Tested by 1

serverFunction · 0.76