public function testHumanReadableString() { $this->assertEquals("'string selector'", Locator::humanReadableString("string selector")); $this->assertEquals("css '.something'", Locator::humanReadableString(['css' => '.something'])); $this->assertEquals("css selector '.something'", Locator::humanReadableString(WebDriverBy::cssSelector('.something'))); try { Locator::humanReadableString(null); $this->fail("Expected exception when calling humanReadableString() with invalid selector"); } catch (\InvalidArgumentException $e) { } }
protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null) { $selectorString = Locator::humanReadableString($selector); if (!$this->string) { throw new \PHPUnit_Framework_ExpectationFailedException("Element {$selectorString} was found", $comparisonFailure); } $output = "There was {$selectorString} element"; $output .= $this->uriMessage("on page"); $output .= str_replace($this->string, "<bold>{$this->string}</bold>", $this->nodesList($nodes, $this->string)); $output .= "\ncontaining '{$this->string}'"; throw new \PHPUnit_Framework_ExpectationFailedException($output, $comparisonFailure); }
public function testGetArguments() { $by = WebDriverBy::cssSelector('.something'); $step = $this->getStep([null, [$by]]); $this->assertEquals('"' . Locator::humanReadableString($by) . '"', $step->getArguments(true)); $step = $this->getStep([null, [['just', 'array']]]); $this->assertEquals('"just","array"', $step->getArguments(true)); $step = $this->getStep([null, [function () { }]]); $this->assertEquals('"lambda function"', $step->getArguments(true)); $step = $this->getStep([null, [[$this, 'testGetArguments']]]); $this->assertEquals('"callable function"', $step->getArguments(true)); }
public function testGetArguments() { $by = WebDriverBy::cssSelector('.something'); $step = $this->getStep([null, [$by]]); $this->assertEquals('"' . Locator::humanReadableString($by) . '"', $step->getArgumentsAsString()); $step = $this->getStep([null, [['just', 'array']]]); $this->assertEquals('["just","array"]', $step->getArgumentsAsString()); $step = $this->getStep([null, [function () { }]]); $this->assertEquals('"Closure"', $step->getArgumentsAsString()); $step = $this->getStep([null, [[$this, 'testGetArguments']]]); $this->assertEquals('["StepTest","testGetArguments"]', $step->getArgumentsAsString()); $step = $this->getStep([null, [['PDO', 'getAvailableDrivers']]]); $this->assertEquals('["PDO","getAvailableDrivers"]', $step->getArgumentsAsString()); }
protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null) { if (!count($nodes)) { throw new ElementNotFound($selector, 'Element located either by name, CSS or XPath'); } $output = "Failed asserting that any element by " . Locator::humanReadableString($selector); $output .= $this->uriMessage('on page'); if (count($nodes) < 5) { $output .= "\nElements: "; $output .= $this->nodesList($nodes); } else { $message = new Message("[total %s elements]"); $output .= $message->with(count($nodes))->style('debug'); } $output .= "\ncontains text '" . $this->string . "'"; throw new \PHPUnit_Framework_ExpectationFailedException($output, $comparisonFailure); }
protected function parseArgumentAsString($argument) { if (is_object($argument)) { if (method_exists($argument, '__toString')) { return (string) $argument; } if (get_class($argument) == 'Facebook\\WebDriver\\WebDriverBy') { return Locator::humanReadableString($argument); } return $this->getClassName($argument); } if (is_array($argument)) { foreach ($argument as $key => $value) { if (is_object($value)) { $argument[$key] = $this->getClassName($value); } } return $argument; } if (is_resource($argument)) { return (string) $argument; } return $argument; }
public function testGetArguments() { $by = WebDriverBy::cssSelector('.something'); $step = $this->getMockBuilder('\\Codeception\\Step')->setConstructorArgs([null, [$by]])->setMethods(null)->getMock(); $this->assertEquals('"' . Locator::humanReadableString($by) . '"', $step->getArguments(true)); }
protected function parseArgumentAsString($argument) { if (is_object($argument)) { if (method_exists($argument, '__toString')) { return (string) $argument; } if (get_class($argument) == 'Facebook\\WebDriver\\WebDriverBy') { return Locator::humanReadableString($argument); } } if ($argument instanceof \Closure) { return 'lambda function'; } if (is_callable($argument)) { return 'callable function'; } if (!is_object($argument)) { return $argument; } return isset($argument->__mocked) ? $this->formatClassName($argument->__mocked) : $this->formatClassName(get_class($argument)); }
protected function stringifyArgument($argument) { if (is_string($argument)) { return '"' . strtr($argument, ["\n" => '\\n', "\r" => '\\r', "\t" => ' ']) . '"'; } elseif (is_resource($argument)) { $argument = (string) $argument; } elseif (is_array($argument)) { foreach ($argument as $key => $value) { if (is_object($value)) { $argument[$key] = $this->getClassName($value); } } } elseif (is_object($argument)) { if (method_exists($argument, '__toString')) { $argument = (string) $argument; } elseif (get_class($argument) == 'Facebook\\WebDriver\\WebDriverBy') { $argument = Locator::humanReadableString($argument); } else { $argument = $this->getClassName($argument); } } return json_encode($argument, JSON_UNESCAPED_UNICODE); }
public function __construct($selector, $message = null) { $selector = Locator::humanReadableString($selector); parent::__construct($message . " element with {$selector} was not found."); }