1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overwatch\TestBundle\Tests\E2E; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriverBy; |
6
|
|
|
use Facebook\WebDriver\WebDriverKeys; |
7
|
|
|
use Facebook\WebDriver\WebDriverSelect; |
8
|
|
|
use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures; |
9
|
|
|
use Overwatch\UserBundle\Tests\Base\WebDriverTestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* AddEditTestTest |
13
|
|
|
* Tests the add/edit group view |
14
|
|
|
*/ |
15
|
|
|
class AddEditTestTest extends WebDriverTestCase |
16
|
|
|
{ |
17
|
|
|
public function setUp() |
18
|
|
|
{ |
19
|
|
|
parent::setUp(); |
20
|
|
|
|
21
|
|
|
$this->logInAsUser('user-1'); |
22
|
|
|
$this->waitForLoadingAnimation(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testEditTest() |
26
|
|
|
{ |
27
|
|
|
$this->webDriver->findElement( |
28
|
|
|
//View first test |
29
|
|
|
WebDriverBy::cssSelector('ul.groups > li:nth-child(1) li:nth-child(1) a:nth-child(3)') |
30
|
|
|
)->click(); |
31
|
|
|
$this->waitForLoadingAnimation(); |
32
|
|
|
|
33
|
|
|
$this->webDriver->findElement( |
34
|
|
|
//Edit test |
35
|
|
|
WebDriverBy::cssSelector('ul.results li:last-child a') |
36
|
|
|
)->click(); |
37
|
|
|
$this->waitForLoadingAnimation(); |
38
|
|
|
|
39
|
|
|
$this->checkTestField('name'); |
40
|
|
|
$this->checkTestField('actual'); |
41
|
|
|
$this->checkTestField('expectation'); |
42
|
|
|
$this->checkTestField('expected'); |
43
|
|
|
|
44
|
|
|
$this->getTestField('name')->clear(); |
45
|
|
|
$this->getTestField('name')->sendKeys('UnUnTestium'); |
46
|
|
|
$this->webDriver->findElement( |
47
|
|
|
WebDriverBy::cssSelector("button[data-ng-click='save()']") |
48
|
|
|
)->click(); |
49
|
|
|
$this->waitForLoadingAnimation(); |
50
|
|
|
$this->assertEquals('UnUnTestium', $this->getHeaderText()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testAddTest() |
54
|
|
|
{ |
55
|
|
|
$this->webDriver->findElement( |
56
|
|
|
//Add test button |
57
|
|
|
WebDriverBy::cssSelector('ul.tests li:last-child a:nth-child(2)') |
58
|
|
|
)->click(); |
59
|
|
|
|
60
|
|
|
$this->getTestField('name')->sendKeys('Github Status Resolves'); |
61
|
|
|
$this->getTestField('actual')->sendKeys('status.github.com'); |
62
|
|
|
(new WebDriverSelect($this->getTestField('expectation')))->selectByValue('string:toResolveTo'); |
63
|
|
|
$this->getTestField('expected')->sendKeys('octostatus-production.github.com'); |
64
|
|
|
$this->getTestField('expected')->sendKeys(WebDriverKeys::ENTER); |
65
|
|
|
|
66
|
|
|
$this->waitForLoadingAnimation(); |
67
|
|
|
$this->assertCount(3, $this->getTestsForFirstGroup()); |
68
|
|
|
$this->assertContains('Github Status Resolves', $this->getTestsForFirstGroup()[2]->getText()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function checkTestField($field, $value = null) |
72
|
|
|
{ |
73
|
|
|
$field = strtolower($field); |
74
|
|
|
|
75
|
|
|
if ($value === null) { |
76
|
|
|
$value = TestFixtures::$tests['test-1']->{'get' . ucfirst($field)}(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($field === 'expectation') { |
80
|
|
|
$select = new WebDriverSelect( |
81
|
|
|
$this->getTestField('expectation') |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->assertEquals($value, $select->getFirstSelectedOption()->getText()); |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->assertEquals($value, $this->getTestField($field)->getAttribute('value')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
private function getTestField($field) |
92
|
|
|
{ |
93
|
|
|
return $this->webDriver->findElement( |
94
|
|
|
WebDriverBy::cssSelector("*[data-ng-model='test.$field']") |
|
|
|
|
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function getTestsForFirstGroup() |
99
|
|
|
{ |
100
|
|
|
$groups = $this->webDriver->findElements( |
101
|
|
|
WebDriverBy::cssSelector('.groups > li.ng-scope') |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
if (count($groups) < 1) { |
105
|
|
|
return []; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $groups[0]->findElements( |
109
|
|
|
WebDriverBy::cssSelector('.tests li.ng-scope') |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.