Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
support content-type meta tag with SeleniumDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed May 25, 2012
1 parent e41e70a commit 2e5672a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Behat/Mink/Driver/Goutte/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function createResponse(GuzzleResponse $response)
$contentType = $response->getContentType();

if (!$contentType || false === strpos($contentType, 'charset=')) {
if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/', $body, $matches)) {
if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset='.$matches[1];
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/Behat/Mink/Driver/SeleniumDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Behat\Mink\Exception\DriverException,
Behat\Mink\Exception\UnsupportedDriverActionException;

use Symfony\Component\DomCrawler\Crawler;

use Selenium\Client as SeleniumClient,
Selenium\Locator as SeleniumLocator,
Selenium\Exception as SeleniumException;
Expand Down Expand Up @@ -627,7 +629,18 @@ public function dragTo($sourceXpath, $destinationXpath)
*/
private function getCrawler()
{
return new \Symfony\Component\DomCrawler\Crawler('<html>'.$this->browser->getHtmlSource().'</html>');
$content = '<html>'.$this->browser->getHtmlSource().'</html>';

$contentType = null;
// get content-type from meta tag
if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $content, $matches)) {
$contentType = 'text/html;charset='.$matches[1];
}

$crawler = new Crawler();
$crawler->addContent($content, $contentType);

return $crawler;
}

/**
Expand Down

0 comments on commit 2e5672a

Please sign in to comment.