2 namespace Zumba\GastonJS\Tests;
4 use Zumba\GastonJS\Exception\BrowserError;
5 use Zumba\GastonJS\Exception\InvalidSelector;
6 use Zumba\GastonJS\Exception\ObsoleteNode;
9 * Class BrowserPageFindTest
10 * @package Zumba\GastonJS\Tests
12 class BrowserPageFindTest extends BrowserCommandsTestCase {
14 public function testFindElementNoPage() {
15 $notFound = $this->browser->find("xpath", '//*[@id="form_1014473"]');
16 $this->assertEquals(0, $notFound["page_id"]);
19 public function testFindInvalidSelector() {
21 $invalidSelection = '//*INVALID_SELECTOR[@id="form_1014473"]';
23 $this->browser->find($selector, $invalidSelection);
24 } catch (InvalidSelector $e) {
25 $this->assertEquals($selector, $e->getMethod());
26 $this->assertEquals($invalidSelection, $e->getSelector());
30 public function testFindElementPage() {
31 $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
32 $element = $this->browser->find("xpath", '//*[@id="form_1014473"]');
33 $this->assertEquals(1, $element["page_id"]);
34 $this->assertEquals(0, $element["ids"][0]);
35 $cssElement = $this->browser->find("css", "#form_1014473 > div");
36 $this->assertEquals(1, $cssElement["page_id"]);
37 $this->assertEquals(1, $cssElement["ids"][0]);
40 public function testFindWithinElementNoPage() {
42 $this->browser->findWithin(1, 0, "xpath", '//*[@id="li_1"]');
43 } catch (\Exception $e) {
44 $this->assertInstanceOf("Zumba\\GastonJS\\Exception\\ObsoleteNode", $e);
48 public function testFindWithinElementPage() {
49 $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
50 $this->browser->find("css", "#form_1014473");
51 $withinElement = $this->browser->findWithin(1, 0, "css", "div");
52 $this->assertCount(4, $withinElement);
55 public function testGetParents() {
56 $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
57 $this->browser->find("xpath", '//*[@id="form_1014473"]');
58 $this->assertArraySubset(array(1, 2, 3), $this->browser->getParents(1, 0));
61 public function testTagName() {
62 $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
63 $this->browser->find("xpath", '//*[@id="form_1014473"]');
64 $this->assertEquals("form", $this->browser->tagName(1, 0));
67 public function testEquals() {
68 $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
70 $this->browser->equals(1, 0, 1);
71 } catch (ObsoleteNode $e) {
73 //TODO: equals method seems to be broken or i do not know how to use it
76 public function testIsVisible() {
77 $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
78 $this->browser->find("xpath", '//*[@id="break"]');
79 $this->assertTrue($this->browser->isVisible(1, 0));
80 $this->browser->find("xpath", '/html/body/p[1]');
81 $this->assertFalse($this->browser->isVisible(1, 1));
84 public function testIsDisabled() {
85 $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
86 $this->browser->find("xpath", '//*[@id="disabled_check"]');
87 $this->browser->find("xpath", '//*[@id="enabled_check"]');
88 $this->assertTrue($this->browser->isDisabled(1, 0));
89 $this->assertFalse($this->browser->isDisabled(1, 1));