|
| 1 | +<?php |
| 2 | +// Copyright 2004-present Facebook. All Rights Reserved. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +namespace Facebook\WebDriver; |
| 17 | + |
| 18 | +use Facebook\WebDriver\Remote\WebDriverBrowserType; |
| 19 | + |
| 20 | +/** |
| 21 | + * @coversDefaultClass Facebook\WebDriver\Interactions\WebDriverActions |
| 22 | + */ |
| 23 | +class WebDriverActionsTest extends WebDriverTestCase |
| 24 | +{ |
| 25 | + protected function setUp() |
| 26 | + { |
| 27 | + parent::setUp(); |
| 28 | + |
| 29 | + $this->driver->get($this->getTestPageUrl('events.html')); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @covers ::__construct |
| 34 | + * @covers ::click |
| 35 | + * @covers ::perform |
| 36 | + */ |
| 37 | + public function testShouldClickOnElement() |
| 38 | + { |
| 39 | + if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::HTMLUNIT) { |
| 40 | + $this->markTestSkipped('Not supported by HtmlUnit browser'); |
| 41 | + } |
| 42 | + |
| 43 | + $element = $this->driver->findElement(WebDriverBy::id('item-1')); |
| 44 | + |
| 45 | + $this->driver->action() |
| 46 | + ->click($element) |
| 47 | + ->perform(); |
| 48 | + |
| 49 | + $this->assertSame( |
| 50 | + ['mouseover item-1', 'mousedown item-1', 'mouseup item-1', 'click item-1'], |
| 51 | + $this->retrieveLoggedEvents() |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @covers ::__construct |
| 57 | + * @covers ::clickAndHold |
| 58 | + * @covers ::release |
| 59 | + * @covers ::perform |
| 60 | + */ |
| 61 | + public function testShouldClickAndHoldOnElementAndRelease() |
| 62 | + { |
| 63 | + if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::HTMLUNIT) { |
| 64 | + $this->markTestSkipped('Not supported by HtmlUnit browser'); |
| 65 | + } |
| 66 | + |
| 67 | + $element = $this->driver->findElement(WebDriverBy::id('item-1')); |
| 68 | + |
| 69 | + $this->driver->action() |
| 70 | + ->clickAndHold($element) |
| 71 | + ->release() |
| 72 | + ->perform(); |
| 73 | + |
| 74 | + $this->assertSame( |
| 75 | + ['mouseover item-1', 'mousedown item-1', 'mouseup item-1', 'click item-1'], |
| 76 | + $this->retrieveLoggedEvents() |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @covers ::__construct |
| 82 | + * @covers ::contextClick |
| 83 | + * @covers ::perform |
| 84 | + */ |
| 85 | + public function testShouldContextClickOnElement() |
| 86 | + { |
| 87 | + if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::HTMLUNIT) { |
| 88 | + $this->markTestSkipped('Not supported by HtmlUnit browser'); |
| 89 | + } |
| 90 | + |
| 91 | + if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::MICROSOFT_EDGE) { |
| 92 | + $this->markTestSkipped('Getting stuck in EdgeDriver'); |
| 93 | + } |
| 94 | + |
| 95 | + $element = $this->driver->findElement(WebDriverBy::id('item-2')); |
| 96 | + |
| 97 | + $this->driver->action() |
| 98 | + ->contextClick($element) |
| 99 | + ->perform(); |
| 100 | + |
| 101 | + $loggedEvents = $this->retrieveLoggedEvents(); |
| 102 | + |
| 103 | + $this->assertContains('mousedown item-2', $loggedEvents); |
| 104 | + $this->assertContains('mouseup item-2', $loggedEvents); |
| 105 | + $this->assertContains('contextmenu item-2', $loggedEvents); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * @covers ::__construct |
| 110 | + * @covers ::doubleClick |
| 111 | + * @covers ::perform |
| 112 | + */ |
| 113 | + public function testShouldDoubleClickOnElement() |
| 114 | + { |
| 115 | + if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::HTMLUNIT) { |
| 116 | + $this->markTestSkipped('Not supported by HtmlUnit browser'); |
| 117 | + } |
| 118 | + |
| 119 | + $element = $this->driver->findElement(WebDriverBy::id('item-3')); |
| 120 | + |
| 121 | + $this->driver->action() |
| 122 | + ->doubleClick($element) |
| 123 | + ->perform(); |
| 124 | + |
| 125 | + $this->assertSame( |
| 126 | + ['mouseover item-3', 'mousedown item-3', 'mouseup item-3', 'click item-3', 'dblclick item-3'], |
| 127 | + $this->retrieveLoggedEvents() |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * @return array |
| 133 | + */ |
| 134 | + private function retrieveLoggedEvents() |
| 135 | + { |
| 136 | + $logElement = $this->driver->findElement(WebDriverBy::id('log')); |
| 137 | + |
| 138 | + return explode("\n", $logElement->getText()); |
| 139 | + } |
| 140 | +} |
0 commit comments