Skip to content

Commit 1b0fac8

Browse files
committed
Move module unit tests to unit suite
1 parent 94f431a commit 1b0fac8

File tree

2 files changed

+92
-78
lines changed

2 files changed

+92
-78
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
use Codeception\Stub;
4+
use Codeception\Stub\Expected;
5+
use Codeception\Test\Metadata;
6+
use Codeception\Util\Maybe;
7+
use Facebook\WebDriver\WebDriverBy;
8+
use PHPUnit\Framework\Assert;
9+
10+
class WebDriverTest extends \Codeception\Test\Unit
11+
{
12+
public const MODULE_CLASS = 'Codeception\Module\WebDriver';
13+
public const WEBDRIVER_CLASS = 'Facebook\WebDriver\Remote\RemoteWebDriver';
14+
15+
public function testCreateTestScreenshotOnFail()
16+
{
17+
$test = Stub::make(
18+
\Codeception\Test\TestCaseWrapper::class,
19+
[
20+
'getSignature' => 'testLogin',
21+
'getMetadata' => new Metadata(),
22+
]
23+
);
24+
$fakeWd = Stub::make(self::WEBDRIVER_CLASS, [
25+
'takeScreenshot' => Expected::once(function ($filename) use ($test) {
26+
Assert::assertSame(
27+
codecept_log_dir(get_class($test) . '.testLogin.fail.png'),
28+
$filename
29+
);
30+
}),
31+
'getPageSource' => Expected::once(function () {
32+
}),
33+
'manage' => Stub::make('\Facebook\WebDriver\WebDriverOptions', [
34+
'getAvailableLogTypes' => Expected::atLeastOnce(fn() => []),
35+
]),
36+
]);
37+
$module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
38+
$module->_failed($test, new \PHPUnit\Framework\AssertionFailedError());
39+
}
40+
41+
42+
43+
public function testCreateCestScreenshotOnFail()
44+
{
45+
$fakeWd = Stub::make(self::WEBDRIVER_CLASS, [
46+
'takeScreenshot' => Expected::once(function ($filename) {
47+
Assert::assertSame(codecept_log_dir('stdClass.login.fail.png'), $filename);
48+
}),
49+
'getPageSource' => Expected::once(function () {
50+
}),
51+
'manage' => Stub::make('\Facebook\WebDriver\WebDriverOptions', [
52+
'getAvailableLogTypes' => Expected::atLeastOnce(fn() => []),
53+
]),
54+
]);
55+
$module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
56+
$cest = new \Codeception\Test\Cest(
57+
new class {
58+
public function login()
59+
{
60+
}
61+
},
62+
'login',
63+
'someCest.php',
64+
);
65+
$module->_failed($cest, new \PHPUnit\Framework\AssertionFailedError());
66+
}
67+
68+
public function testWebDriverWaits()
69+
{
70+
$fakeWd = Stub::make(self::WEBDRIVER_CLASS, ['wait' => Expected::exactly(16, fn() => new Maybe())]);
71+
$module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
72+
$module->waitForElement(WebDriverBy::partialLinkText('yeah'));
73+
$module->waitForElement(['id' => 'user']);
74+
$module->waitForElement(['css' => '.user']);
75+
$module->waitForElement('//xpath');
76+
77+
$module->waitForElementVisible(WebDriverBy::partialLinkText('yeah'));
78+
$module->waitForElementVisible(['id' => 'user']);
79+
$module->waitForElementVisible(['css' => '.user']);
80+
$module->waitForElementVisible('//xpath');
81+
82+
$module->waitForElementNotVisible(WebDriverBy::partialLinkText('yeah'));
83+
$module->waitForElementNotVisible(['id' => 'user']);
84+
$module->waitForElementNotVisible(['css' => '.user']);
85+
$module->waitForElementNotVisible('//xpath');
86+
87+
$module->waitForElementClickable(WebDriverBy::partialLinkText('yeah'));
88+
$module->waitForElementClickable(['id' => 'user']);
89+
$module->waitForElementClickable(['css' => '.user']);
90+
$module->waitForElementClickable('//xpath');
91+
}
92+
}

tests/web/WebDriverTest.php

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Codeception\Module\WebDriver;
88
use Codeception\Stub;
99
use Codeception\Stub\Expected;
10-
use Codeception\Test\Metadata;
11-
use Codeception\Util\Maybe;
1210
use data;
1311
use Facebook\WebDriver\Cookie;
1412
use Facebook\WebDriver\Remote\DesiredCapabilities;
@@ -569,82 +567,6 @@ public function testCreateCeptScreenshotFail()
569567
$module->_failed($cept, new \PHPUnit\Framework\AssertionFailedError());
570568
}
571569

572-
public function testCreateCestScreenshotOnFail()
573-
{
574-
$fakeWd = Stub::make(self::WEBDRIVER_CLASS, [
575-
'takeScreenshot' => Expected::once(function ($filename) {
576-
Assert::assertSame(codecept_log_dir('stdClass.login.fail.png'), $filename);
577-
}),
578-
'getPageSource' => Expected::once(function () {
579-
}),
580-
'manage' => Stub::make('\Facebook\WebDriver\WebDriverOptions', [
581-
'getAvailableLogTypes' => Expected::atLeastOnce(fn() => []),
582-
]),
583-
]);
584-
$module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
585-
$cest = new \Codeception\Test\Cest(
586-
new class {
587-
public function login()
588-
{
589-
}
590-
},
591-
'login',
592-
'someCest.php',
593-
);
594-
$module->_failed($cest, new \PHPUnit\Framework\AssertionFailedError());
595-
}
596-
597-
public function testCreateTestScreenshotOnFail()
598-
{
599-
$test = Stub::make(
600-
\Codeception\Test\TestCaseWrapper::class,
601-
[
602-
'getSignature' => 'testLogin',
603-
'getMetadata' => new Metadata(),
604-
]
605-
);
606-
$fakeWd = Stub::make(self::WEBDRIVER_CLASS, [
607-
'takeScreenshot' => Expected::once(function ($filename) use ($test) {
608-
Assert::assertSame(
609-
codecept_log_dir(get_class($test) . '.testLogin.fail.png'),
610-
$filename
611-
);
612-
}),
613-
'getPageSource' => Expected::once(function () {
614-
}),
615-
'manage' => Stub::make('\Facebook\WebDriver\WebDriverOptions', [
616-
'getAvailableLogTypes' => Expected::atLeastOnce(fn() => []),
617-
]),
618-
]);
619-
$module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
620-
$module->_failed($test, new \PHPUnit\Framework\AssertionFailedError());
621-
}
622-
623-
public function testWebDriverWaits()
624-
{
625-
$fakeWd = Stub::make(self::WEBDRIVER_CLASS, ['wait' => Expected::exactly(16, fn() => new Maybe())]);
626-
$module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
627-
$module->waitForElement(WebDriverBy::partialLinkText('yeah'));
628-
$module->waitForElement(['id' => 'user']);
629-
$module->waitForElement(['css' => '.user']);
630-
$module->waitForElement('//xpath');
631-
632-
$module->waitForElementVisible(WebDriverBy::partialLinkText('yeah'));
633-
$module->waitForElementVisible(['id' => 'user']);
634-
$module->waitForElementVisible(['css' => '.user']);
635-
$module->waitForElementVisible('//xpath');
636-
637-
$module->waitForElementNotVisible(WebDriverBy::partialLinkText('yeah'));
638-
$module->waitForElementNotVisible(['id' => 'user']);
639-
$module->waitForElementNotVisible(['css' => '.user']);
640-
$module->waitForElementNotVisible('//xpath');
641-
642-
$module->waitForElementClickable(WebDriverBy::partialLinkText('yeah'));
643-
$module->waitForElementClickable(['id' => 'user']);
644-
$module->waitForElementClickable(['css' => '.user']);
645-
$module->waitForElementClickable('//xpath');
646-
}
647-
648570
public function testWaitForElement()
649571
{
650572
$this->module->amOnPage('/form/timeout');

0 commit comments

Comments
 (0)