Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Zumba\Mink\Driver;
|
Chris@0
|
4
|
Chris@0
|
5 use Behat\Mink\Exception\DriverException;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Class PageContentTrait
|
Chris@0
|
9 * @package Zumba\Mink\Driver
|
Chris@0
|
10 */
|
Chris@0
|
11 trait PageContentTrait {
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * @return string
|
Chris@0
|
15 */
|
Chris@0
|
16 public function getContent() {
|
Chris@0
|
17 return $this->browser->getBody();
|
Chris@0
|
18 }
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@0
|
21 * Given xpath, will try to get ALL the text, visible and not visible from such xpath
|
Chris@0
|
22 * @param string $xpath
|
Chris@0
|
23 * @return string
|
Chris@0
|
24 * @throws DriverException
|
Chris@0
|
25 */
|
Chris@0
|
26 public function getText($xpath) {
|
Chris@0
|
27 $elements = $this->findElement($xpath, 1);
|
Chris@0
|
28 //allText works only with ONE element so it will be the first one and also returns new lines that we will remove
|
Chris@0
|
29 $text = $this->browser->allText($elements["page_id"], $elements["ids"][0]);
|
Chris@0
|
30 $text = trim(str_replace(array("\r", "\r\n", "\n"), ' ', $text));
|
Chris@0
|
31 $text = preg_replace('/ {2,}/', ' ', $text);
|
Chris@0
|
32 return $text;
|
Chris@0
|
33 }
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * Returns the inner html of a given xpath
|
Chris@0
|
37 * @param string $xpath
|
Chris@0
|
38 * @return string
|
Chris@0
|
39 * @throws DriverException
|
Chris@0
|
40 */
|
Chris@0
|
41 public function getHtml($xpath) {
|
Chris@0
|
42 $elements = $this->findElement($xpath, 1);
|
Chris@0
|
43 //allText works only with ONE element so it will be the first one
|
Chris@0
|
44 return $this->browser->allHtml($elements["page_id"], $elements["ids"][0], "inner");
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 /**
|
Chris@0
|
48 * Gets the outer html of a given xpath
|
Chris@0
|
49 * @param string $xpath
|
Chris@0
|
50 * @return string
|
Chris@0
|
51 * @throws DriverException
|
Chris@0
|
52 */
|
Chris@0
|
53 public function getOuterHtml($xpath) {
|
Chris@0
|
54 $elements = $this->findElement($xpath, 1);
|
Chris@0
|
55 //allText works only with ONE element so it will be the first one
|
Chris@0
|
56 return $this->browser->allHtml($elements["page_id"], $elements["ids"][0], "outer");
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 /**
|
Chris@0
|
60 * Returns the binary representation of the current page we are in
|
Chris@0
|
61 * @throws DriverException
|
Chris@0
|
62 * @return string
|
Chris@0
|
63 */
|
Chris@0
|
64 public function getScreenshot() {
|
Chris@0
|
65 $options = array("full" => true, "selector" => null);
|
Chris@0
|
66 $b64ScreenShot = $this->browser->renderBase64("JPEG", $options);
|
Chris@0
|
67 if (($binaryScreenShot = base64_decode($b64ScreenShot, true)) === false) {
|
Chris@0
|
68 throw new DriverException("There was a problem while doing the screenshot of the current page");
|
Chris@0
|
69 }
|
Chris@0
|
70 return $binaryScreenShot;
|
Chris@0
|
71 }
|
Chris@0
|
72 }
|