-
Notifications
You must be signed in to change notification settings - Fork 844
Expand file tree
/
Copy pathWebDriverAlertTest.php
More file actions
86 lines (64 loc) · 2.75 KB
/
Copy pathWebDriverAlertTest.php
File metadata and controls
86 lines (64 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php declare(strict_types=1);
namespace Facebook\WebDriver;
use Facebook\WebDriver\Exception\NoAlertOpenException;
use Facebook\WebDriver\Exception\NoSuchAlertException;
/**
* @covers \Facebook\WebDriver\Remote\RemoteTargetLocator
* @covers \Facebook\WebDriver\WebDriverAlert
*/
class WebDriverAlertTest extends WebDriverTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->driver->get($this->getTestPageUrl(TestPage::ALERT));
}
public function testShouldAcceptAlert(): void
{
// Open alert (it is delayed for 1 second, to make sure following wait for alertIsPresent works properly)
$this->driver->findElement(WebDriverBy::id('open-alert-delayed'))->click();
// Wait until present
$this->driver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
$this->assertSame('This is alert', $this->driver->switchTo()->alert()->getText());
$this->driver->switchTo()->alert()->accept();
if (self::isW3cProtocolBuild()) {
$this->expectException(NoSuchAlertException::class);
} else {
$this->expectException(NoAlertOpenException::class);
}
$this->driver->switchTo()->alert()->accept();
}
public function testShouldAcceptAndDismissConfirmation(): void
{
// Open confirmation
$this->driver->findElement(WebDriverBy::id('open-confirm'))->click();
// Wait until present
$this->driver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
$this->assertSame('Do you confirm?', $this->driver->switchTo()->alert()->getText());
// Test accepting
$this->driver->switchTo()->alert()->accept();
$this->assertSame('accepted', $this->getResultText());
// Open confirmation
$this->driver->findElement(WebDriverBy::id('open-confirm'))->click();
// Test dismissal
$this->driver->switchTo()->alert()->dismiss();
$this->assertSame('dismissed', $this->getResultText());
}
public function testShouldSubmitPromptText(): void
{
// Open confirmation
$this->driver->findElement(WebDriverBy::id('open-prompt'))->click();
// Wait until present
$this->driver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
$this->assertSame('Enter prompt value', $this->driver->switchTo()->alert()->getText());
$this->driver->switchTo()->alert()->sendKeys('Text entered to prompt');
$this->driver->switchTo()->alert()->accept();
$this->assertSame('Text entered to prompt', $this->getResultText());
}
private function getResultText(): string
{
return $this->driver
->findElement(WebDriverBy::id('result'))
->getText();
}
}