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

Method start

py/selenium/webdriver/remote/server.py:179–218  ·  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

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

Callers 1

serverFunction · 0.95

Calls 4

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

Tested by 1

serverFunction · 0.76