Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser.php
Show First 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | public function withinBody($callback) | ||||
call_user_func($callback, $this); | call_user_func($callback, $this); | ||||
if (isset($orig_prefix)) { | if (isset($orig_prefix)) { | ||||
$this->resolver->prefix = $orig_prefix; | $this->resolver->prefix = $orig_prefix; | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* Store the console output with the given name. Overwrites Dusk's method. | |||||
* | |||||
* @param string $name | |||||
* @return $this | |||||
*/ | |||||
public function storeConsoleLog($name) | |||||
{ | |||||
if (in_array($this->driver->getCapabilities()->getBrowserName(), static::$supportsRemoteLogs)) { | |||||
$console = $this->driver->manage()->getLog('browser'); | |||||
// Ignore errors/warnings irrelevant for testing | |||||
foreach ($console as $idx => $entry) { | |||||
if ( | |||||
$entry['level'] != 'SEVERE' | |||||
|| strpos($entry['message'], 'Failed to load resource: the server responded with a status of') | |||||
) { | |||||
$console[$idx] = null; | |||||
} | |||||
} | |||||
$console = array_values(array_filter($console)); | |||||
if (!empty($console)) { | |||||
$file = sprintf('%s/%s.log', rtrim(static::$storeConsoleLogAt, '/'), $name); | |||||
$content = json_encode($console, JSON_PRETTY_PRINT); | |||||
file_put_contents($file, $content); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |