Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
0f2313ab
Commit
0f2313ab
authored
Apr 29, 2021
by
catch
Browse files
Issue
#3211164
by alexpott: Random errors in Javascript Testing
parent
9289782c
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php
View file @
0f2313ab
...
...
@@ -14,6 +14,25 @@
*/
class
WebDriverCurlService
extends
CurlService
{
/**
* The maximum number of times to try in the event of a stale element
* reference error.
*
* @var int
*/
private
static
$maxRetries
=
10
;
/**
* Sets the maximum number of retries.
*
* @param int $max_retries
* The maximum number of times to try in the event of a stale element
* reference error. This number must be greater than 10.
*/
public
static
function
setMaxRetries
(
int
$max_retries
)
{
static
::
$maxRetries
=
max
(
$max_retries
,
static
::
$maxRetries
);
}
/**
* {@inheritdoc}
*/
...
...
@@ -22,7 +41,7 @@ public function execute($requestMethod, $url, $parameters = NULL, $extraOptions
CURLOPT_FAILONERROR
=>
TRUE
,
];
$retries
=
0
;
while
(
$retries
<
10
)
{
while
(
$retries
<
static
::
$maxRetries
)
{
try
{
$customHeaders
=
[
'Content-Type: application/json;charset=UTF-8'
,
...
...
@@ -104,8 +123,9 @@ public function execute($requestMethod, $url, $parameters = NULL, $extraOptions
$result
=
json_decode
(
$rawResult
,
TRUE
);
if
(
isset
(
$result
[
'status'
])
&&
$result
[
'status'
]
===
WebDriverException
::
STALE_ELEMENT_REFERENCE
)
{
usleep
(
100000
);
$retries
++
;
// Wait a bit longer each time a stale reference error has occurred.
usleep
(
100000
*
$retries
);
continue
;
}
return
[
$rawResult
,
$info
];
...
...
core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
View file @
0f2313ab
...
...
@@ -31,6 +31,15 @@ abstract class WebDriverTestBase extends BrowserTestBase {
*/
protected
$minkDefaultDriverClass
=
DrupalSelenium2Driver
::
class
;
/**
* The maximum number of times to try a webdriver request.
*
* @var int
*
* @see \Drupal\FunctionalJavascriptTests\WebDriverCurlService::$maxRetries
*/
protected
const
WEBDRIVER_RETRIES
=
10
;
/**
* {@inheritdoc}
*/
...
...
@@ -39,6 +48,7 @@ protected function initMink() {
throw
new
\
UnexpectedValueException
(
sprintf
(
"%s has to be an instance of %s"
,
$this
->
minkDefaultDriverClass
,
DrupalSelenium2Driver
::
class
));
}
$this
->
minkDefaultDriverArgs
=
[
'chrome'
,
NULL
,
'http://localhost:4444'
];
WebDriverCurlService
::
setMaxRetries
(
max
((
int
)
getenv
(
'WEBDRIVER_RETRIES'
),
static
::
WEBDRIVER_RETRIES
));
try
{
return
parent
::
initMink
();
...
...
catch
@catch
mentioned in commit
2cfb999e
·
Apr 29, 2021
mentioned in commit
2cfb999e
mentioned in commit 2cfb999e15d1a3cf11a017e60b5bbe17c1fbffab
Toggle commit list
catch
@catch
mentioned in commit
e5c0783a
·
Apr 29, 2021
mentioned in commit
e5c0783a
mentioned in commit e5c0783a3819073bd340a448642cbd2e2b184f19
Toggle commit list
catch
@catch
mentioned in commit
3f054652
·
Apr 29, 2021
mentioned in commit
3f054652
mentioned in commit 3f054652bc517c238f77b6614a5617264f88bbf8
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment