@@ -33,6 +33,37 @@ trait WebTestAssertionsTrait
33
33
}
34
34
use PantherTestCaseTrait;
35
35
36
+ /** @TODO replace this after patching Symfony to allow xpath selectors */
37
+ public static function assertSelectorExists (string $ selector , string $ message = '' ): void
38
+ {
39
+ $ element = self ::findElement ($ selector );
40
+ self ::assertNotNull ($ element , $ message );
41
+ }
42
+
43
+ /** @TODO replace this after patching Symfony to allow xpath selectors */
44
+ public static function assertSelectorNotExists (string $ selector , string $ message = '' ): void
45
+ {
46
+ /** @var PantherClient $client */
47
+ $ client = self ::getClient ();
48
+ $ by = $ client ::createWebDriverByFromLocator ($ selector );
49
+ $ elements = $ client ->findElements ($ by );
50
+ self ::assertEmpty ($ elements , $ message );
51
+ }
52
+
53
+ /** @TODO replace this after patching Symfony to allow xpath selectors */
54
+ public static function assertSelectorTextContains (string $ selector , string $ text , string $ message = '' ): void
55
+ {
56
+ $ element = self ::findElement ($ selector );
57
+ self ::assertStringContainsString ($ text , $ element ->getText (), $ message );
58
+ }
59
+
60
+ /** @TODO replace this after patching Symfony to allow xpath selectors */
61
+ public static function assertSelectorTextNotContains (string $ selector , string $ text , string $ message = '' ): void
62
+ {
63
+ $ element = self ::findElement ($ selector );
64
+ self ::assertStringNotContainsString ($ text , $ element ->getText (), $ message );
65
+ }
66
+
36
67
public static function assertPageTitleSame (string $ expectedTitle , string $ message = '' ): void
37
68
{
38
69
$ client = self ::getClient ();
@@ -63,30 +94,129 @@ public static function assertPageTitleContains(string $expectedTitle, string $me
63
94
self ::baseAssertPageTitleContains ($ expectedTitle , $ message );
64
95
}
65
96
97
+ public static function assertSelectorWillExist (string $ locator ): void
98
+ {
99
+ /** @var PantherClient $client */
100
+ $ client = self ::getClient ();
101
+ $ client ->waitFor ($ locator );
102
+ self ::assertSelectorExists ($ locator );
103
+ }
104
+
105
+ public static function assertSelectorWillNotExist (string $ locator ): void
106
+ {
107
+ /** @var PantherClient $client */
108
+ $ client = self ::getClient ();
109
+ $ client ->waitForStaleness ($ locator );
110
+ self ::assertSelectorNotExists ($ locator );
111
+ }
112
+
66
113
public static function assertSelectorIsVisible (string $ locator ): void
67
114
{
68
115
$ element = self ::findElement ($ locator );
69
116
self ::assertTrue ($ element ->isDisplayed (), 'Failed asserting that element is visible. ' );
70
117
}
71
118
119
+ public static function assertSelectorWillBeVisible (string $ locator ): void
120
+ {
121
+ /** @var PantherClient $client */
122
+ $ client = self ::getClient ();
123
+ $ client ->waitForVisibility ($ locator );
124
+ self ::assertSelectorIsVisible ($ locator );
125
+ }
126
+
72
127
public static function assertSelectorIsNotVisible (string $ locator ): void
73
128
{
74
129
$ element = self ::findElement ($ locator );
75
130
self ::assertFalse ($ element ->isDisplayed (), 'Failed asserting that element is not visible. ' );
76
131
}
77
132
133
+ public static function assertSelectorWillNotBeVisible (string $ locator ): void
134
+ {
135
+ /** @var PantherClient $client */
136
+ $ client = self ::getClient ();
137
+ $ client ->waitForInvisibility ($ locator );
138
+ self ::assertSelectorIsNotVisible ($ locator );
139
+ }
140
+
141
+ public static function assertSelectorWillContain (string $ locator , string $ text ): void
142
+ {
143
+ /** @var PantherClient $client */
144
+ $ client = self ::getClient ();
145
+ $ client ->waitForElementToContain ($ locator , $ text );
146
+ self ::assertSelectorTextContains ($ locator , $ text );
147
+ }
148
+
149
+ public static function assertSelectorWillNotContain (string $ locator , string $ text ): void
150
+ {
151
+ /** @var PantherClient $client */
152
+ $ client = self ::getClient ();
153
+ $ client ->waitForElementToNotContain ($ locator , $ text );
154
+ self ::assertSelectorTextNotContains ($ locator , $ text );
155
+ }
156
+
78
157
public static function assertSelectorIsEnabled (string $ locator ): void
79
158
{
80
159
$ element = self ::findElement ($ locator );
81
160
self ::assertTrue ($ element ->isEnabled (), 'Failed asserting that element is enabled. ' );
82
161
}
83
162
163
+ public static function assertSelectorWillBeEnabled (string $ locator ): void
164
+ {
165
+ /** @var PantherClient $client */
166
+ $ client = self ::getClient ();
167
+ $ client ->waitForEnabled ($ locator );
168
+ self ::assertSelectorAttributeContains ($ locator , 'disabled ' );
169
+ }
170
+
84
171
public static function assertSelectorIsDisabled (string $ locator ): void
85
172
{
86
173
$ element = self ::findElement ($ locator );
87
174
self ::assertFalse ($ element ->isEnabled (), 'Failed asserting that element is disabled. ' );
88
175
}
89
176
177
+ public static function assertSelectorWillBeDisabled (string $ locator ): void
178
+ {
179
+ /** @var PantherClient $client */
180
+ $ client = self ::getClient ();
181
+ $ client ->waitForDisabled ($ locator );
182
+ self ::assertSelectorAttributeContains ($ locator , 'disabled ' , 'true ' );
183
+ }
184
+
185
+ public static function assertSelectorAttributeContains (string $ locator , string $ attribute , string $ text = null ): void
186
+ {
187
+ $ element = self ::findElement ($ locator );
188
+
189
+ if (null === $ text ) {
190
+ self ::assertNull ($ element ->getAttribute ($ attribute ));
191
+
192
+ return ;
193
+ }
194
+
195
+ self ::assertStringContainsString ($ text , $ element ->getAttribute ($ attribute ));
196
+ }
197
+
198
+ public static function assertSelectorAttributeWillContain (string $ locator , string $ attribute , string $ text ): void
199
+ {
200
+ /** @var PantherClient $client */
201
+ $ client = self ::getClient ();
202
+ $ client ->waitForAttributeToContain ($ locator , $ attribute , $ text );
203
+ self ::assertSelectorAttributeContains ($ locator , $ attribute , $ text );
204
+ }
205
+
206
+ public static function assertSelectorAttributeNotContains (string $ locator , string $ attribute , string $ text ): void
207
+ {
208
+ $ element = self ::findElement ($ locator );
209
+ self ::assertStringNotContainsString ($ text , $ element ->getAttribute ($ attribute ));
210
+ }
211
+
212
+ public static function assertSelectorAttributeWillNotContain (string $ locator , string $ attribute , string $ text ): void
213
+ {
214
+ /** @var PantherClient $client */
215
+ $ client = self ::getClient ();
216
+ $ client ->waitForAttributeToNotContain ($ locator , $ attribute , $ text );
217
+ self ::assertSelectorAttributeNotContains ($ locator , $ attribute , $ text );
218
+ }
219
+
90
220
private static function findElement (string $ locator ): WebDriverElement
91
221
{
92
222
/** @var PantherClient $client */
0 commit comments