forked from Zverik/Level0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPageTest.php
105 lines (78 loc) · 3.16 KB
/
PageTest.php
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
require 'vendor/autoload.php';
// https://php-webdriver.github.io/php-webdriver/latest/Facebook/WebDriver.html
// https://gist.github.com/aczietlow/7c4834f79a7afd920d8f
use Facebook\WebDriver\Chrome\ChromeDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverKeys;
use Facebook\WebDriver\WebDriverExpectedCondition;
use PHPUnit\Framework\TestCase;
require_once 'WebServerHelper.php';
class WebPageTest extends TestCase
{
protected $webDriver;
// Runs once
public static function setUpBeforeClass(): void
{
WebServerHelper::start();
}
public static function tearDownAfterClass(): void
{
WebServerHelper::stop();
}
// Runs before each test
public function setUp(): void
{
// https://github.com/php-webdriver/php-webdriver/wiki/Chrome#start-chromedriver
// putenv('WEBDRIVER_CHROME_DRIVER=/path/to/chromedriver');
// https://github.com/php-webdriver/php-webdriver/wiki/Chrome#general-usage
$chromeOptions = new ChromeOptions();
// $chromeOptions->setBinary('/home/user/Downloads/my_chrome_binary');
$chromeOptions->addArguments(['--headless']);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions);
$this->webDriver = ChromeDriver::start($capabilities);
}
public function tearDown(): void
{
$this->webDriver->quit();
}
private function elementByCSS($query)
{
return $this->webDriver->findElement(WebDriverBy::cssSelector($query));
}
public function testPage()
{
$this->webDriver->get(WebServerHelper::url());
sleep(2);
// Wait for map (Javacript) to load
$this->webDriver->wait()->until(
WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('.leaflet-map-pane'))
);
$h2 = $this->elementByCSS('h2');
$this->assertEquals($h2->getText(), 'Level0 OpenStreetMap Editor');
$input = $this->elementByCSS('input[name="url"]');
$input->sendKeys(array('w105957600', WebDriverKeys::ENTER));
sleep(2);
$textarea = $this->elementByCSS('textarea');
$this->assertStringContainsString("way 105957600\n", $textarea->getText());
$this->assertStringContainsString(" addr:street = Downing Street\n", $textarea->getText());
// Button "Add to Editor"
$input = $this->elementByCSS('input[name="url"]');
$input->sendKeys('n3815077900');
$this->elementByCSS('input[type="submit"][name="add"]')->click();
sleep(2);
$textarea = $this->elementByCSS('textarea');
$this->assertStringContainsString("way 105957600\n", $textarea->getText());
$this->assertStringContainsString("node 3815077900: ", $textarea->getText());
// Button "Check for conflicts"
$this->elementByCSS('input[name="check"]')->click();
$this->assertStringContainsString('Nothing is modified', $this->webDriver->getPageSource());
// Button "Show osmChange"
$this->elementByCSS('input[name="showosc"]')->click();
$this->assertStringContainsString('this will be uploaded to the server', $this->webDriver->getPageSource());
$this->assertMatchesRegularExpression('/<osmChange [^&]+>\s*<\/osmChange>/', $this->webDriver->getPageSource());
}
}