/** * Get full path to results file. * @return string */ public function getFilePath() { if (!$this->fileDir) { $this->fileDir = ConfigProvider::getInstance()->logsDir; } return $this->fileDir . '/' . $this->fileName; }
public function execute($command_name, $params = []) { if (ConfigProvider::getInstance()->debug) { $this->log('Executing command "%s" with params %s', $command_name, json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); } return parent::execute($command_name, $params); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage Custom configuration options can be set only before the Config object was instantiated */ public function testShouldFailIfSettingCustomConfigurationOptionsAfterFirstInstantiation() { ConfigHelper::setEnvironmentVariables($this->environmentVariables); $provider = ConfigProvider::getInstance(); // Create Config instance $provider->getConfig(); // This should fail, as the Config instance was already created $provider->setCustomConfigurationOptions(['CUSTOM_OPTION']); }
/** * Create Legacy instance * @param AbstractTestCaseBase $tc TestCase instance */ public function __construct(AbstractTestCaseBase $tc) { parent::__construct($tc); $logsDir = ConfigProvider::getInstance()->logsDir; if ($logsDir) { // if the directory is not defined, the setFileDir() must be called explicitly later $this->setFileDir($logsDir); } $this->testClassName = get_class($tc); $this->log('New legacy instantiated in class "%s"', $this->testClassName); }
/** * Get path to given fixture, which could be then entered into file input field. * * @param string $fixture Fixture identifier (relative path to fixture from directory with tests) * @return string Path to fixture */ public function getFixturePath($fixture) { $fixturesDir = ConfigProvider::getInstance()->fixturesDir; $directorySeparator = '/'; if (strpos($fixturesDir, '\\') !== false) { // if \ was used in the path, we are most probably on windows $directorySeparator = '\\'; $fixture = str_replace('/', $directorySeparator, $fixture); } $fixturePath = rtrim($fixturesDir, $directorySeparator) . $directorySeparator . $fixture; // if relative path was provided and the file is accessible, resolve into absolute path if (realpath($fixturePath)) { $fixturePath = realpath($fixturePath); } $this->debug('Assembled path to fixture: "%s"', $fixturePath); return $fixturePath; }
/** * Take screenshot and save it. * * @param AbstractTestCase $test */ protected function takeSnapshot(AbstractTestCase $test) { $savePath = ConfigProvider::getInstance()->logsDir . '/'; $testIdentifier = Strings::webalize(get_class($test), null, $lower = false) . '-' . Strings::webalize($test->getName(), null, $lower = false) . '-' . date('Y-m-d-H-i-s'); if (!$test->wd instanceof \RemoteWebDriver) { $test->warn('WebDriver instance not found, cannot take screenshot.'); return; } $test->appendTestLog('Test failed on page "%s", taking page snapshots:', $test->wd->getCurrentURL()); // Save PNG screenshot $screenshotPath = $savePath . $testIdentifier . '.png'; $test->wd->takeScreenshot($screenshotPath); $test->appendTestLog('Screenshot saved to file "%s" ', $this->getSnapshotUrl($screenshotPath)); // Save HTML snapshot of page $htmlPath = $savePath . $testIdentifier . '.html'; file_put_contents($htmlPath, $test->wd->getPageSource()); $test->appendTestLog('HTML snapshot saved to file "%s" ', $this->getSnapshotUrl($htmlPath)); }
/** * Subroutine to encapsulate creation of real WebDriver. Handles some exceptions that may occur etc. * The WebDriver instance is stored to $test->wd when created. * * @param AbstractTestCase $test * @param $remoteServerUrl * @param \DesiredCapabilities $capabilities * @param $connectTimeoutMs * @param $requestTimeoutMs */ protected function createWebDriver(AbstractTestCase $test, $remoteServerUrl, \DesiredCapabilities $capabilities, $connectTimeoutMs, $requestTimeoutMs) { $browserName = ConfigProvider::getInstance()->browserName; for ($startAttempts = 0; $startAttempts < 4; $startAttempts++) { try { $test->wd = RemoteWebDriver::create($remoteServerUrl, $capabilities, $connectTimeoutMs, $requestTimeoutMs); return; } catch (\UnknownServerException $e) { if ($browserName == 'firefox' && strpos($e->getMessage(), 'Unable to bind to locking port') !== false) { // As a consequence of Selenium issue #5172 (cannot change locking port), Firefox may on CI server // collide with other FF instance. As a workaround, we try to start it again after a short delay. $test->warn('Firefox locking port is occupied; beginning attempt #%d to start it ("%s")', $startAttempts + 2, $e->getMessage()); sleep(1); continue; } elseif (strpos($e->getMessage(), 'Error forwarding the new session') !== false) { $test->warn("Cannot execute test on the node. Maybe you started just the hub and not the node?"); } throw $e; } } $test->warn('All %d attempts to instantiate Firefox WebDriver failed', $startAttempts + 1); throw $e; }
public function debug($format, $args = null) { if (ConfigProvider::getInstance()->debug) { echo $this->formatOutput(func_get_args(), 'DEBUG'); } }