MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / waitForServer

Function waitForServer

javascript/selenium-webdriver/http/util.js:56–99  ·  view source on GitHub ↗

* Waits for a WebDriver server to be healthy and accepting requests. * @param {string} url Base URL of the server to query. * @param {number} timeout How long to wait for the server. * @param {Promise=} opt_cancelToken A promise used as a cancellation signal: * if resolved before the server

(url, timeout, opt_cancelToken)

Source from the content-addressed store, hash-verified

54 * if the wait is cancelled.
55 */
56function waitForServer(url, timeout, opt_cancelToken) {
57 return new Promise((onResolve, onReject) => {
58 let start = Date.now()
59
60 let done = false
61 let resolve = (status) => {
62 done = true
63 onResolve(status)
64 }
65 let reject = (err) => {
66 done = true
67 onReject(err)
68 }
69
70 if (opt_cancelToken) {
71 opt_cancelToken.then((_) => reject(new CancellationError()))
72 }
73
74 checkServerStatus()
75
76 function checkServerStatus() {
77 return getStatus(url).then((status) => resolve(status), onError)
78 }
79
80 function onError(e) {
81 // Some servers don't support the status command. If they are able to
82 // response with an error, then can consider the server ready.
83 if (e instanceof error.UnsupportedOperationError) {
84 resolve({})
85 return
86 }
87
88 if (Date.now() - start > timeout) {
89 reject(Error('Timed out waiting for the WebDriver server at ' + url))
90 } else {
91 setTimeout(function () {
92 if (!done) {
93 checkServerStatus()
94 }
95 }, 50)
96 }
97 }
98 })
99}
100
101/**
102 * Polls a URL with GET requests until it returns a 2xx response or the

Callers

nothing calls this directly

Calls 3

checkServerStatusFunction · 0.85
nowMethod · 0.80
rejectFunction · 0.70

Tested by

no test coverage detected