|
| 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 | +/** |
| 19 | + * @coversDefaultClass Facebook\WebDriver\WebDriverNavigation |
| 20 | + */ |
| 21 | +class WebDriverNavigationTest extends WebDriverTestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @covers ::to |
| 25 | + * @covers ::__construct |
| 26 | + */ |
| 27 | + public function testShouldNavigateToUrl() |
| 28 | + { |
| 29 | + $this->driver->navigate()->to($this->getTestPageUrl('index.html')); |
| 30 | + |
| 31 | + $this->assertStringEndsWith('/index.html', $this->driver->getCurrentURL()); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @covers ::back |
| 36 | + * @covers ::forward |
| 37 | + */ |
| 38 | + public function testShouldNavigateBackAndForward() |
| 39 | + { |
| 40 | + $this->driver->get($this->getTestPageUrl('index.html')); |
| 41 | + $linkElement = $this->driver->findElement(WebDriverBy::id('a-form')); |
| 42 | + |
| 43 | + $linkElement->click(); |
| 44 | + |
| 45 | + $this->driver->wait()->until( |
| 46 | + WebDriverExpectedCondition::urlContains('form.html') |
| 47 | + ); |
| 48 | + |
| 49 | + $this->driver->navigate()->back(); |
| 50 | + |
| 51 | + $this->driver->wait()->until( |
| 52 | + WebDriverExpectedCondition::urlContains('index.html') |
| 53 | + ); |
| 54 | + |
| 55 | + $this->driver->navigate()->forward(); |
| 56 | + |
| 57 | + $this->driver->wait()->until( |
| 58 | + WebDriverExpectedCondition::urlContains('form.html') |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @covers ::refresh |
| 64 | + */ |
| 65 | + public function testShouldRefreshPage() |
| 66 | + { |
| 67 | + $this->driver->get($this->getTestPageUrl('index.html')); |
| 68 | + |
| 69 | + // Change input element content, to make sure it was refreshed (=> cleared to original value) |
| 70 | + $inputElement = $this->driver->findElement(WebDriverBy::name('test_name')); |
| 71 | + $inputElementOriginalValue = $inputElement->getAttribute('value'); |
| 72 | + $inputElement->clear()->sendKeys('New value'); |
| 73 | + $this->assertSame('New value', $inputElement->getAttribute('value')); |
| 74 | + |
| 75 | + $this->driver->navigate()->refresh(); |
| 76 | + |
| 77 | + $this->driver->wait()->until( |
| 78 | + WebDriverExpectedCondition::stalenessOf($inputElement) |
| 79 | + ); |
| 80 | + |
| 81 | + $inputElementAfterRefresh = $this->driver->findElement(WebDriverBy::name('test_name')); |
| 82 | + |
| 83 | + $this->assertSame($inputElementOriginalValue, $inputElementAfterRefresh->getAttribute('value')); |
| 84 | + } |
| 85 | +} |
0 commit comments