Skip to content

Commit ced2509

Browse files
committed
Deprecate safePageWait
1 parent 9996798 commit ced2509

File tree

3 files changed

+56
-74
lines changed

3 files changed

+56
-74
lines changed

tests/Form/GeneralTest.php

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ public function testBasicForm(): void
4848

4949
$page->pressButton('Save');
5050

51-
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
52-
$this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText());
53-
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
54-
$this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText());
55-
}
51+
$this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText());
52+
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
53+
$this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText());
5654
}
5755

5856
/**
@@ -70,11 +68,7 @@ public function testFormSubmitWays(string $submitVia): void
7068

7169
$page->pressButton($submitVia);
7270

73-
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
74-
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
75-
} else {
76-
$this->fail('Form was never submitted');
77-
}
71+
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
7872
}
7973

8074
/**
@@ -98,9 +92,7 @@ public function testFormSubmit(): void
9892

9993
$webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();
10094

101-
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
102-
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
103-
}
95+
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
10496
}
10597

10698
public function testFormSubmitWithoutButton(): void
@@ -113,9 +105,7 @@ public function testFormSubmitWithoutButton(): void
113105

114106
$webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();
115107

116-
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
117-
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
118-
}
108+
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
119109
}
120110

121111
public function testBasicGetForm(): void
@@ -204,8 +194,8 @@ public function testAdvancedForm(): void
204194

205195
$button->press();
206196

207-
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") === "Advanced form save"')) {
208-
$out = <<<'OUT'
197+
$this->assertStringContainsString(
198+
<<<'OUT'
209199
array(
210200
agreement = `on`,
211201
email = `ever.zet@gmail.com`,
@@ -218,9 +208,9 @@ public function testAdvancedForm(): void
218208
)
219209
some_file.txt
220210
1 uploaded file
221-
OUT;
222-
$this->assertStringContainsString($out, $page->getContent());
223-
}
211+
OUT,
212+
$page->getContent()
213+
);
224214
}
225215

226216
public function testQuoteInValue(): void
@@ -245,22 +235,27 @@ public function testQuoteInValue(): void
245235

246236
$button->press();
247237

248-
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
249-
$out = <<<'OUT'
238+
$this->assertThat(
239+
$page->getContent(),
240+
$this->logicalOr(
241+
$this->stringContains(
242+
<<<'OUT'
250243
first_name = `Foo &quot;item&quot;`,
251244
last_name = `Bar`,
252-
OUT;
245+
OUT
246+
),
247+
$this->stringContains(
253248
// Escaping of double quotes are optional in HTML text nodes. Even though our backend escapes
254249
// the quote in the HTML when returning it, browsers may apply only the minimal escaping in
255250
// the content they expose to Selenium depending of how they build it (they might serialize
256-
// their DOM again rathet than returning the raw HTTP response content).
257-
$minEscapedOut = <<<'OUT'
251+
// their DOM again rather than returning the raw HTTP response content).
252+
<<<'OUT'
258253
first_name = `Foo "item"`,
259254
last_name = `Bar`,
260-
OUT;
261-
262-
$this->assertThat($page->getContent(), $this->logicalOr($this->stringContains($out), $this->stringContains($minEscapedOut)));
263-
}
255+
OUT
256+
)
257+
)
258+
);
264259
}
265260

266261
public function testMultiInput(): void

tests/Form/Html5Test.php

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public function testHtml5FormInputAttribute(): void
2424

2525
$page->pressButton('Submit in form');
2626

27-
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
28-
$out = <<<'OUT'
27+
$this->assertStringContainsString(
28+
<<<'OUT'
2929
first_name = `John`,
3030
last_name = `Doe`,
31-
OUT;
32-
$this->assertStringContainsString($out, $page->getContent());
33-
$this->assertStringNotContainsString('other_field', $page->getContent());
34-
}
31+
OUT,
32+
$page->getContent()
33+
);
34+
$this->assertStringNotContainsString('other_field', $page->getContent());
3535
}
3636

3737
public function testHtml5FormRadioAttribute(): void
@@ -72,14 +72,14 @@ public function testHtml5FormButtonAttribute(): void
7272

7373
$page->pressButton('Submit outside form');
7474

75-
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
76-
$out = <<<'OUT'
75+
$this->assertStringContainsString(
76+
<<<'OUT'
7777
first_name = `John`,
7878
last_name = `Doe`,
7979
submit_button = `test`,
80-
OUT;
81-
$this->assertStringContainsString($out, $page->getContent());
82-
}
80+
OUT,
81+
$page->getContent()
82+
);
8383
}
8484

8585
public function testHtml5FormOutside(): void
@@ -91,13 +91,13 @@ public function testHtml5FormOutside(): void
9191

9292
$page->pressButton('Submit separate form');
9393

94-
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
95-
$out = <<<'OUT'
94+
$this->assertStringContainsString(
95+
<<<'OUT'
9696
other_field = `hello`,
97-
OUT;
98-
$this->assertStringContainsString($out, $page->getContent());
99-
$this->assertStringNotContainsString('first_name', $page->getContent());
100-
}
97+
OUT,
98+
$page->getContent()
99+
);
100+
$this->assertStringNotContainsString('first_name', $page->getContent());
101101
}
102102

103103
public function testHtml5Types(): void
@@ -115,7 +115,8 @@ public function testHtml5Types(): void
115115

116116
$page->pressButton('Submit');
117117

118-
$out = <<<'OUT'
118+
$this->assertStringContainsString(
119+
<<<'OUT'
119120
color = `#ff00aa`,
120121
date = `1111-11-11`,
121122
email = `mink@example.org`,
@@ -124,9 +125,9 @@ public function testHtml5Types(): void
124125
submit_button = `Submit`,
125126
time = `14:12`,
126127
url = `https://mink.behat.org/`,
127-
OUT;
128-
129-
$this->assertStringContainsString($out, $page->getContent());
128+
OUT,
129+
$page->getContent()
130+
);
130131
}
131132

132133
public function testHtml5FormAction(): void
@@ -137,10 +138,8 @@ public function testHtml5FormAction(): void
137138
$page->fillField('first_name', 'Jimmy');
138139
$page->pressButton('Submit to basic form');
139140

140-
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
141-
$this->assertStringContainsString('<title>Basic Form Saving</title>', $page->getContent());
142-
$this->assertStringContainsString('Firstname: Jimmy', $page->getContent());
143-
}
141+
$this->assertStringContainsString('<title>Basic Form Saving</title>', $page->getContent());
142+
$this->assertStringContainsString('Firstname: Jimmy', $page->getContent());
144143
}
145144

146145
public function testHtml5FormMethod(): void
@@ -152,12 +151,10 @@ public function testHtml5FormMethod(): void
152151
$page->fillField('last_name', 'Jones');
153152
$page->pressButton('Submit as GET');
154153

155-
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
156-
$this->assertEquals(
157-
$this->pathTo('advanced_form_post.php') . '?first_name=Jimmy&last_name=Jones',
158-
$this->getSession()->getCurrentUrl()
159-
);
160-
}
154+
$this->assertEquals(
155+
$this->pathTo('advanced_form_post.php') . '?first_name=Jimmy&last_name=Jones',
156+
$this->getSession()->getCurrentUrl()
157+
);
161158
}
162159

163160
/**

tests/TestCase.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,11 @@ protected function pathTo($path)
159159
}
160160

161161
/**
162-
* Waits for a condition to be true, considering than it is successful for drivers not supporting wait().
163-
*
164-
* @param int $time
165-
* @param string $condition A JS condition to evaluate
166-
*
167-
* @return bool
168-
*
169-
* @see \Behat\Mink\Session::wait()
162+
* @deprecated To be removed since drivers are should wait for page navigation automatically and meanwhile tests
163+
* shouldn't try fixing it.
170164
*/
171165
protected function safePageWait($time, $condition)
172166
{
173-
try {
174-
return $this->getSession()->wait($time, $condition);
175-
} catch (UnsupportedDriverActionException $e) {
176-
return true;
177-
}
167+
return true;
178168
}
179169
}

0 commit comments

Comments
 (0)