Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions tests/Form/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ public function testBasicForm(): void

$page->pressButton('Save');

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

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

$page->pressButton($submitVia);

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

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

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

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

public function testFormSubmitWithoutButton(): void
Expand All @@ -113,9 +105,7 @@ public function testFormSubmitWithoutButton(): void

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

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

public function testBasicGetForm(): void
Expand Down Expand Up @@ -204,8 +194,8 @@ public function testAdvancedForm(): void

$button->press();

if ($this->safePageWait(5000, 'document.getElementsByTagName("title") === "Advanced form save"')) {
$out = <<<'OUT'
$this->assertStringContainsString(
<<<'OUT'
array(
agreement = `on`,
email = `ever.zet@gmail.com`,
Expand All @@ -218,9 +208,9 @@ public function testAdvancedForm(): void
)
some_file.txt
1 uploaded file
OUT;
$this->assertStringContainsString($out, $page->getContent());
}
OUT,
$page->getContent()
);
}

public function testQuoteInValue(): void
Expand All @@ -245,22 +235,27 @@ public function testQuoteInValue(): void

$button->press();

if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<'OUT'
$this->assertThat(
$page->getContent(),
$this->logicalOr(
$this->stringContains(
<<<'OUT'
first_name = `Foo &quot;item&quot;`,
last_name = `Bar`,
OUT;
OUT
),
$this->stringContains(
// Escaping of double quotes are optional in HTML text nodes. Even though our backend escapes
// the quote in the HTML when returning it, browsers may apply only the minimal escaping in
// the content they expose to Selenium depending of how they build it (they might serialize
// their DOM again rathet than returning the raw HTTP response content).
$minEscapedOut = <<<'OUT'
// their DOM again rather than returning the raw HTTP response content).
<<<'OUT'
first_name = `Foo "item"`,
last_name = `Bar`,
OUT;

$this->assertThat($page->getContent(), $this->logicalOr($this->stringContains($out), $this->stringContains($minEscapedOut)));
}
OUT
)
)
);
}

public function testMultiInput(): void
Expand Down
59 changes: 28 additions & 31 deletions tests/Form/Html5Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function testHtml5FormInputAttribute(): void

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

if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<'OUT'
$this->assertStringContainsString(
<<<'OUT'
first_name = `John`,
last_name = `Doe`,
OUT;
$this->assertStringContainsString($out, $page->getContent());
$this->assertStringNotContainsString('other_field', $page->getContent());
}
OUT,
$page->getContent()
);
$this->assertStringNotContainsString('other_field', $page->getContent());
}

public function testHtml5FormRadioAttribute(): void
Expand Down Expand Up @@ -72,14 +72,14 @@ public function testHtml5FormButtonAttribute(): void

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

if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<'OUT'
$this->assertStringContainsString(
<<<'OUT'
first_name = `John`,
last_name = `Doe`,
submit_button = `test`,
OUT;
$this->assertStringContainsString($out, $page->getContent());
}
OUT,
$page->getContent()
);
}

public function testHtml5FormOutside(): void
Expand All @@ -91,13 +91,13 @@ public function testHtml5FormOutside(): void

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

if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<'OUT'
$this->assertStringContainsString(
<<<'OUT'
other_field = `hello`,
OUT;
$this->assertStringContainsString($out, $page->getContent());
$this->assertStringNotContainsString('first_name', $page->getContent());
}
OUT,
$page->getContent()
);
$this->assertStringNotContainsString('first_name', $page->getContent());
}

public function testHtml5Types(): void
Expand All @@ -115,7 +115,8 @@ public function testHtml5Types(): void

$page->pressButton('Submit');

$out = <<<'OUT'
$this->assertStringContainsString(
<<<'OUT'
color = `#ff00aa`,
date = `1111-11-11`,
email = `mink@example.org`,
Expand All @@ -124,9 +125,9 @@ public function testHtml5Types(): void
submit_button = `Submit`,
time = `14:12`,
url = `https://mink.behat.org/`,
OUT;

$this->assertStringContainsString($out, $page->getContent());
OUT,
$page->getContent()
);
}

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

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

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

if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$this->assertEquals(
$this->pathTo('advanced_form_post.php') . '?first_name=Jimmy&last_name=Jones',
$this->getSession()->getCurrentUrl()
);
}
$this->assertEquals(
$this->pathTo('advanced_form_post.php') . '?first_name=Jimmy&last_name=Jones',
$this->getSession()->getCurrentUrl()
);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Behat\Mink\Tests\Driver;

use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\Mink;
use Behat\Mink\Session;
use Behat\Mink\WebAssert;
Expand Down Expand Up @@ -159,21 +158,21 @@ protected function pathTo($path)
}

/**
* Waits for a condition to be true, considering than it is successful for drivers not supporting wait().
*
* @param int $time
* @param string $condition A JS condition to evaluate
* @param string $condition
*
* @return bool
*
* @see \Behat\Mink\Session::wait()
* @deprecated To be removed since drivers are should wait for page navigation automatically and meanwhile tests
* shouldn't try fixing it.
*/
protected function safePageWait($time, $condition)
{
try {
return $this->getSession()->wait($time, $condition);
} catch (UnsupportedDriverActionException $e) {
return true;
}
@trigger_error(
sprintf('The method %s is deprecated: drivers should wait for page navigation automatically', __METHOD__),
E_USER_DEPRECATED
);

return true;
}
}