/**
  * Gets the details page.
  *
  * @return Crawler
  * @todo Refactor this as it is not possible to mock currently
  */
 private function getDetails()
 {
     if (is_null($this->details)) {
         $url = $this->crawler->selectLink($this->getTitle())->link()->getUri();
         $scraper = new Scraper();
         $this->details = $scraper->fetch($url);
         $this->length = $scraper->getResponseSize();
     }
     return $this->details;
 }
Exemple #2
0
 public function dontSeeLink($text, $url = null)
 {
     $links = $this->crawler->selectLink($text);
     if ($url) {
         $links = $links->filterXPath(sprintf('.//a[contains(@href, %s)]', Crawler::xpathLiteral($url)));
     }
     $this->assertDomNotContains($links, 'a');
 }
Exemple #3
0
 public function dontSeeLink($text, $url = null)
 {
     $links = $this->crawler->selectLink($this->escape($text));
     if (!$url) {
         \PHPUnit_Framework_Assert::assertEquals(0, $links->count(), "'{$text}' on page");
     }
     $links->filterXPath(sprintf('descendant-or-self::a[contains(@href, "%s")]', Crawler::xpathLiteral(' ' . $this->escape($url) . ' ')));
     \PHPUnit_Framework_Assert::assertEquals(0, $links->count());
 }
 /**
  * Click a link with the given body, name, or ID attribute.
  *
  * @param  string  $name
  * @return $this
  */
 protected function click($name)
 {
     $link = $this->crawler->selectLink($name);
     if (!count($link)) {
         $link = $this->filterByNameOrId($name, 'a');
         if (!count($link)) {
             throw new InvalidArgumentException("Could not find a link with a body, name, or ID attribute of [{$name}].");
         }
     }
     $this->visit($link->link()->getUri());
     return $this;
 }
Exemple #5
0
 /**
  * @When /^I click the ([^"]*) link in the e-?mail$/
  */
 public function iClickTheLink($linkText)
 {
     if (empty($this->email)) {
         throw new \Exception('No email to click through from.');
     }
     $crawler = new Crawler();
     $crawler->addHtmlContent($this->email['htmlContent']['htmlBody']);
     try {
         $href = $crawler->selectLink($linkText)->attr('href');
     } catch (\InvalidArgumentException $e) {
         throw new \Exception("No link with text '{$linkText}' found in email.");
     }
     $this->getSession()->visit($href);
 }
Exemple #6
0
 /**
  *  Does login with ID and password.
  **/
 public function doAlunoLogin()
 {
     // get csrf token
     $this->crawler = $this->client->request('GET', $this->endpoint);
     $token = $this->crawler->filter('input[name="csrfmiddlewaretoken"]');
     $token = $token->attr('value');
     // get form and submit
     $form = $this->crawler->selectButton('Acessar')->form();
     $this->crawler = $this->client->submit($form, ['username' => $this->username, 'password' => $this->password, 'csrfmiddlewaretoken' => $token]);
     // get matricula number
     $meusdados_link = $this->crawler->selectLink('Meus Dados')->link()->getUri();
     $link_parts = explode('/', $meusdados_link);
     $this->matricula = $link_parts[5];
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $html = file_get_contents('http://spb.hh.ru/search/vacancy?text=php&clusters=true&enable_snippets=true');
     $crawler = new Crawler($html, 'http://spb.hh.ru/search/vacancy?text=php&clusters=true&enable_snippets=true');
     $output->writeln($formatter->formatBlock('Vacancies', 'question', true));
     $crawler->filterXPath(CssSelector::toXPath('body a.search-result-item__name'))->each(function (Crawler $node) use($output) {
         $output->writeln(sprintf('<comment>%s</comment>', $node->text()));
     });
     $data = $crawler->filter('body a.search-result-item__name')->extract(['_text', 'class']);
     print_r($data[0]);
     $output->writeln($formatter->formatBlock('Link test', 'question', true));
     $link = $crawler->selectLink('PHP developer')->link();
     $output->writeln($link->getUri());
     $crawler = new Crawler(file_get_contents('http://spb.hh.ru/login'), 'http://spb.hh.ru/login');
     $output->writeln($formatter->formatBlock('Form test', 'question', true));
     $form = $crawler->selectButton('Войти')->form(['username' => 'name', 'password' => 'pass']);
     $output->writeln($form->getUri());
     $form['remember']->tick();
     $output->writeln(print_r($form->getPhpValues()));
 }
Exemple #8
0
    public function testSelectLinkAndLinkFiltered()
    {
        $html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<body>
    <div id="action">
        <a href="/index.php?r=site/login">Login</a>
    </div>
    <form id="login-form" action="/index.php?r=site/login" method="post">
        <button type="submit">Submit</button>
    </form>
</body>
</html>
HTML;
        $crawler = new Crawler($html);
        $filtered = $crawler->filterXPath("descendant-or-self::*[@id = 'login-form']");
        $this->assertCount(0, $filtered->selectLink('Login'));
        $this->assertCount(1, $filtered->selectButton('Submit'));
        $filtered = $crawler->filterXPath("descendant-or-self::*[@id = 'action']");
        $this->assertCount(1, $filtered->selectLink('Login'));
        $this->assertCount(0, $filtered->selectButton('Submit'));
        $this->assertCount(1, $crawler->selectLink('Login')->selectLink('Login'));
        $this->assertCount(1, $crawler->selectButton('Submit')->selectButton('Submit'));
    }
 public function test_getLink()
 {
     $link = $this->decorator->getLink();
     $crawler = new Crawler($link);
     $this->assertEquals($this->decorator->getUrl(), $crawler->selectLink("Term 1")->attr('href'));
 }
Exemple #10
0
 /**
  * @param SymfonyCrawler $crawler
  * @return \Symfony\Component\DomCrawler\Link|null
  */
 protected function getNextLink(SymfonyCrawler $crawler)
 {
     $linkNode = $crawler->selectLink('След');
     return count($linkNode) ? $linkNode->link() : null;
 }
 function test_Link()
 {
     $link = $this->decorator->link;
     $crawler = new Crawler($link);
     $this->assertEquals($this->decorator->url, $crawler->selectLink('Post title 1')->attr('href'));
 }
Exemple #12
0
 /**
  * @param Crawler $crawler
  * @return boolean|Crawler
  * TODO: Поиск записей по всем доступным страницам.
  */
 protected function pagination(Crawler $crawler)
 {
     $nextPageCrawler = $crawler->selectLink('След.');
     if ($nextPageCrawler && $nextPageCrawler->getNode(0) && false === mb_stripos($nextPageCrawler->getNode(0)->getAttribute('class'), 'ui-disabled', null, 'UTF-8')) {
         return self::$client->click($nextPageCrawler->link());
     }
     return false;
 }
 /**
  * Assumes an email has been identified by a previous step,
  * e.g. through 'Given there should be an email to "*****@*****.**"'.
  * 
  * @When /^I click on the "([^"]*)" link in the email"$/
  */
 public function iGoToInTheEmail($linkSelector)
 {
     if (!$this->lastMatchedEmail) {
         throw new \LogicException('No matched email found from previous step');
     }
     $match = $this->lastMatchedEmail;
     $crawler = new Crawler($match->Content);
     $linkEl = $crawler->selectLink($linkSelector);
     assertNotNull($linkEl);
     $link = $linkEl->attr('href');
     assertNotNull($link);
     return new Step\When(sprintf('I go to "%s"', $link));
 }
Exemple #14
0
 /**
  * Clicks a link
  *
  * @param Crawler $crawler
  * @param string $where Translation key of the link text
  *
  * @return Crawler
  */
 public static function clickLink(Crawler $crawler, $where)
 {
     $link = $crawler->selectLink(self::$translator->trans($where));
     return self::$client->click($link->link());
 }