Skip to content

Commit f297164

Browse files
authored
Support for Codeception 5 (#92)
1 parent 57e2d83 commit f297164

File tree

5 files changed

+70
-65
lines changed

5 files changed

+70
-65
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
"name": "Zaahid Bateson"
1717
}
1818
],
19-
"minimum-stability": "RC",
19+
"minimum-stability": "dev",
2020

2121
"require": {
22-
"php": "^7.4 | ^8.0",
22+
"php": "^8.0",
2323
"ext-json": "*",
2424
"ext-mbstring": "*",
25-
"codeception/codeception": "^4.0",
25+
"codeception/codeception": "dev-5.0-interfaces as 5.0.x-dev",
26+
"codeception/stub": "^4.0",
2627
"php-webdriver/webdriver": "^1.8.0"
2728
},
2829
"suggest": {

readme.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
A WebDriver module for Codeception.
44

5-
[![Chrome Tests](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome.yml/badge.svg)](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome.yml)
6-
[![Chrome Headless Tests](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome-headless.yml/badge.svg)](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome-headless.yml)
7-
[![Firefox Tests](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-firefox.yml/badge.svg)](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-firefox.yml)
5+
[![Chrome](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome.yml/badge.svg)](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome.yml)
6+
[![Chrome Headless](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome-headless.yml/badge.svg)](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-chrome-headless.yml)
7+
[![Firefox](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-firefox.yml/badge.svg)](https://github.com/Codeception/module-webdriver/actions/workflows/webdriver-firefox.yml)
8+
9+
## Requirements
10+
11+
* `PHP 8.0` or higher.
812

913
## Installation
1014

src/Codeception/Module/WebDriver.php

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use Facebook\WebDriver\Remote\RemoteWebElement;
4646
use Facebook\WebDriver\Remote\UselessFileDetector;
4747
use Facebook\WebDriver\Remote\WebDriverCapabilityType;
48+
use Facebook\WebDriver\WebDriver as WebDriverInterface;
4849
use Facebook\WebDriver\WebDriverBy;
4950
use Facebook\WebDriver\WebDriverDimension;
5051
use Facebook\WebDriver\WebDriverElement;
@@ -387,12 +388,9 @@ class WebDriver extends CodeceptionModule implements
387388
/**
388389
* @var string[]
389390
*/
390-
protected $requiredFields = ['browser', 'url'];
391+
protected array $requiredFields = ['browser', 'url'];
391392

392-
/**
393-
* @var array
394-
*/
395-
protected $config = [
393+
protected array $config = [
396394
'protocol' => 'http',
397395
'host' => '127.0.0.1',
398396
'port' => '4444',
@@ -756,7 +754,7 @@ protected function stopAllSessions(): void
756754
$this->baseElement = null;
757755
}
758756

759-
public function amOnSubdomain($subdomain)
757+
public function amOnSubdomain(string $subdomain): void
760758
{
761759
$url = $this->config['url'];
762760
$url = preg_replace('#(https?://)(.*\.)(.*\.)#', "$1$3", $url); // removing current subdomain
@@ -864,7 +862,7 @@ public function _findElements($locator): array
864862
/**
865863
* Saves HTML source of a page to a file
866864
*/
867-
public function _savePageSource($filename)
865+
public function _savePageSource(string $filename): void
868866
{
869867
if ($this->webDriver === null) {
870868
$this->debug('WebDriver::_savePageSource method has been called when webDriver is not set');
@@ -936,7 +934,7 @@ public function makeElementScreenshot($selector, string $name = null): void
936934
$this->debugSection('Screenshot Saved', "file://{$screenName}");
937935
}
938936

939-
public function makeHtmlSnapshot($name = null)
937+
public function makeHtmlSnapshot(string $name = null): void
940938
{
941939
if (empty($name)) {
942940
$name = uniqid(date("Y-m-d_H-i-s_"));
@@ -1035,7 +1033,7 @@ public function resetCookie($cookie, array $params = []): void
10351033
$this->debugCookies();
10361034
}
10371035

1038-
public function grabCookie($cookie, array $params = [])
1036+
public function grabCookie($cookie, array $params = []): mixed
10391037
{
10401038
$params['name'] = $cookie;
10411039
$cookies = $this->filterCookies($this->webDriver->manage()->getCookies(), $params);
@@ -1157,7 +1155,7 @@ public function dontSeeInPageSource(string $text): void
11571155
);
11581156
}
11591157

1160-
public function click($link, $context = null)
1158+
public function click($link, $context = null): void
11611159
{
11621160
$page = $this->webDriver;
11631161
if ($context) {
@@ -1308,7 +1306,7 @@ protected function findField($selector): WebDriverElement
13081306
return reset($arr);
13091307
}
13101308

1311-
public function seeLink($text, $url = null)
1309+
public function seeLink(string $text, string $url = null): void
13121310
{
13131311
$this->enableImplicitWait();
13141312
$nodes = $this->getBaseElement()->findElements(WebDriverBy::partialLinkText($text));
@@ -1326,7 +1324,7 @@ public function seeLink($text, $url = null)
13261324
$this->assertNotEmpty($nodes, "No links containing text '{$text}' and URL '{$url}' were found in page {$currentUri}");
13271325
}
13281326

1329-
public function dontSeeLink($text, $url = null)
1327+
public function dontSeeLink(string $text, string $url = ''): void
13301328
{
13311329
$nodes = $this->getBaseElement()->findElements(WebDriverBy::partialLinkText($text));
13321330
$currentUri = $this->_getCurrentUri();
@@ -1352,37 +1350,37 @@ function (WebDriverElement $e) use ($expectedUrl, $absoluteCurrentUrl): bool {
13521350
);
13531351
}
13541352

1355-
public function seeInCurrentUrl($uri)
1353+
public function seeInCurrentUrl(string $uri): void
13561354
{
13571355
$this->assertStringContainsString($uri, $this->_getCurrentUri());
13581356
}
13591357

1360-
public function seeCurrentUrlEquals($uri)
1358+
public function seeCurrentUrlEquals(string $uri): void
13611359
{
13621360
$this->assertEquals($uri, $this->_getCurrentUri());
13631361
}
13641362

1365-
public function seeCurrentUrlMatches($uri)
1363+
public function seeCurrentUrlMatches(string $uri): void
13661364
{
13671365
$this->assertRegExp($uri, $this->_getCurrentUri());
13681366
}
13691367

1370-
public function dontSeeInCurrentUrl($uri)
1368+
public function dontSeeInCurrentUrl(string $uri): void
13711369
{
13721370
$this->assertStringNotContainsString($uri, $this->_getCurrentUri());
13731371
}
13741372

1375-
public function dontSeeCurrentUrlEquals($uri)
1373+
public function dontSeeCurrentUrlEquals(string $uri): void
13761374
{
13771375
$this->assertNotEquals($uri, $this->_getCurrentUri());
13781376
}
13791377

1380-
public function dontSeeCurrentUrlMatches($uri)
1378+
public function dontSeeCurrentUrlMatches(string $uri): void
13811379
{
13821380
$this->assertNotRegExp($uri, $this->_getCurrentUri());
13831381
}
13841382

1385-
public function grabFromCurrentUrl($uri = null)
1383+
public function grabFromCurrentUrl($uri = null): mixed
13861384
{
13871385
if (!$uri) {
13881386
return $this->_getCurrentUri();
@@ -1401,34 +1399,34 @@ public function grabFromCurrentUrl($uri = null)
14011399
return $matches[1];
14021400
}
14031401

1404-
public function seeCheckboxIsChecked($checkbox)
1402+
public function seeCheckboxIsChecked($checkbox): void
14051403
{
14061404
$this->assertTrue($this->findField($checkbox)->isSelected());
14071405
}
14081406

1409-
public function dontSeeCheckboxIsChecked($checkbox)
1407+
public function dontSeeCheckboxIsChecked(string $checkbox): void
14101408
{
14111409
$this->assertFalse($this->findField($checkbox)->isSelected());
14121410
}
14131411

1414-
public function seeInField($field, $value)
1412+
public function seeInField($field, $value): void
14151413
{
14161414
$els = $this->findFields($field);
14171415
$this->assert($this->proceedSeeInField($els, $value));
14181416
}
14191417

1420-
public function dontSeeInField($field, $value)
1418+
public function dontSeeInField($field, $value): void
14211419
{
14221420
$els = $this->findFields($field);
14231421
$this->assertNot($this->proceedSeeInField($els, $value));
14241422
}
14251423

1426-
public function seeInFormFields($formSelector, array $params)
1424+
public function seeInFormFields($formSelector, array $params): void
14271425
{
14281426
$this->proceedSeeInFormFields($formSelector, $params, false);
14291427
}
14301428

1431-
public function dontSeeInFormFields($formSelector, array $params)
1429+
public function dontSeeInFormFields($formSelector, array $params): void
14321430
{
14331431
$this->proceedSeeInFormFields($formSelector, $params, true);
14341432
}
@@ -1644,7 +1642,7 @@ public function selectOption($select, $option): void
16441642
*
16451643
* @api
16461644
*/
1647-
public function _initializeSession()
1645+
public function _initializeSession(): void
16481646
{
16491647
try {
16501648
$this->sessions[] = $this->webDriver;
@@ -1674,7 +1672,7 @@ public function _initializeSession()
16741672
* @param RemoteWebDriver $session
16751673
* @api
16761674
*/
1677-
public function _loadSession($session)
1675+
public function _loadSession($session): void
16781676
{
16791677
$this->webDriver = $session;
16801678
$this->setBaseElement();
@@ -1685,7 +1683,7 @@ public function _loadSession($session)
16851683
*
16861684
* @api
16871685
*/
1688-
public function _backupSession(): ?RemoteWebDriver
1686+
public function _backupSession(): WebDriverInterface
16891687
{
16901688
return $this->webDriver;
16911689
}
@@ -1705,7 +1703,7 @@ public function _backupSession(): ?RemoteWebDriver
17051703
* @api
17061704
* @param RemoteWebDriver|null $webDriver a specific webdriver session instance
17071705
*/
1708-
public function _closeSession($webDriver = null)
1706+
public function _closeSession($webDriver = null): void
17091707
{
17101708
if (!$webDriver && $this->webDriver) {
17111709
$webDriver = $this->webDriver;
@@ -1923,7 +1921,7 @@ public function type(string $text, int $delay = 0): void
19231921
sleep($delay);
19241922
}
19251923

1926-
public function attachFile($field, $filename)
1924+
public function attachFile($field, string $filename): void
19271925
{
19281926
$el = $this->findField($field);
19291927
// in order to be compatible on different OS
@@ -1964,7 +1962,7 @@ protected function getVisibleText(): ?string
19641962
return '';
19651963
}
19661964

1967-
public function grabTextFrom($cssOrXPathOrRegex)
1965+
public function grabTextFrom($cssOrXPathOrRegex): mixed
19681966
{
19691967
$els = $this->match($this->getBaseElement(), $cssOrXPathOrRegex, false);
19701968
if ($els !== []) {
@@ -2026,7 +2024,7 @@ protected function filterByAttributes($els, array $attributes)
20262024
return $els;
20272025
}
20282026

2029-
public function seeElement($selector, $attributes = [])
2027+
public function seeElement($selector, array $attributes = []): void
20302028
{
20312029
$this->enableImplicitWait();
20322030
$els = $this->matchVisible($selector);
@@ -2035,7 +2033,7 @@ public function seeElement($selector, $attributes = [])
20352033
$this->assertNotEmpty($els);
20362034
}
20372035

2038-
public function dontSeeElement($selector, $attributes = [])
2036+
public function dontSeeElement($selector, array $attributes = []): void
20392037
{
20402038
$els = $this->matchVisible($selector);
20412039
$els = $this->filterByAttributes($els, $attributes);
@@ -2074,7 +2072,7 @@ public function dontSeeElementInDOM($selector, array $attributes = []): void
20742072
$this->assertEmpty($els);
20752073
}
20762074

2077-
public function seeNumberOfElements($selector, $expected)
2075+
public function seeNumberOfElements($selector, $expected): void
20782076
{
20792077
$counted = count($this->matchVisible($selector));
20802078
if (is_array($expected)) {

tests/web.suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class_name: WebGuy
1+
actor: WebGuy
22
modules:
33
enabled: [WebDriver, WebHelper]
44
config:

0 commit comments

Comments
 (0)