WPWebDriver
This module extends the WebDriver module adding WordPress-specific configuration parameters and methods.
The module simulates a user interaction with the site with Javascript support; if you don't need to test your project with Javascript support use the WPBrowser module.
This module requires the
codeception/module-webdriver
Composer package to work when wp-browser is used with Codeception 4.0.To install the package run:
composer require --dev codeception/module-webdriver:^1.0
Due to the combination of possible browsers, capabilities and configurations, it's not possible to provide an exhaustive coverage of all the possible configuration parameteters here.
url
required - Start URL of your WordPress project, e.g.http://wp.test
.adminUsername
required - This is the login name, not the "nice" name, of the administrator user of the WordPress test site. This will be used to fill the username field in WordPress login page.adminPassword
required - This is the the password of the administrator use of the WordPress test site. This will be used to fill the password in WordPress login page.adminPath
required - The path, relative to the WordPress test site home URL, to the administration area, usually/wp-admin
.browser
- The browser to use for the tests, e.g.chrome
orfirefox
.capabilities
- Depending on the browser set inbrowser
this is a list of browser-specific capabilities.
modules:
enabled:
- WPWebDriver
config:
WPWebDriver:
url: 'http://wp.test'
adminUsername: 'admin'
adminPassword: 'password'
adminPath: '/wp-admin'
browser: chrome
host: localhost
port: 4444
window_size: false #disabled for Chrome driver
capabilities:
chromeOptions:
args: ["--headless", "--disable-gpu", "--proxy-server='direct://'", "--proxy-bypass-list=*"]
In the plugin administration screen activates one or more plugins clicking the "Activate" link. The method will not handle authentication and navigation to the plugins administration page.
// Activate a plugin.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->activatePlugin('hello-dolly');
// Activate a list of plugins.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->activatePlugin(['hello-dolly','another-plugin']);
Parameters
string/\Codeception\Module\array
$pluginSlug - The plugin slug, like "hello-dolly" or a list of plugin slugs.
Go to the admin page to edit the post with the specified ID. The method will not handle authentication the admin area.
$I->loginAsAdmin();
$postId = $I->havePostInDatabase();
$I->amEditingPostWithId($postId);
$I->fillField('post_title', 'Post title');
Parameters
int
$id - The post ID.
Go to the
admin-ajax.php
page to start a synchronous, and blocking, GET
AJAX request. The method will not handle authentication, nonces or authorization.$I->amOnAdminAjaxPage(['action' => 'my-action', 'data' => ['id' => 23], 'nonce' => $nonce]);
Parameters
string/\Codeception\Module\array
$queryVars - A string or array of query variables to append to the AJAX path.
Go to a page in the admininstration area of the site. This method will not handle authentication to the administration area.
$I->loginAs('user', 'password');
// Go to the plugins management screen.
$I->amOnAdminPage('/plugins.php');
Parameters
string
$page - The path, relative to the admin area URL, to the page.
Go to the cron page to start a synchronous, and blocking,
GET
request to the cron script.// Triggers the cron job with an optional query argument.
$I->amOnCronPage('/?some-query-var=some-value');
Parameters
string/\Codeception\Module\array
$queryVars - A string or array of query variables to append to the AJAX path.
Go the "Pages" administration screen. The method will not handle authentication.
$I->loginAsAdmin();
$I->amOnPagesPage();
$I->see('Add New');
Go to the plugins administration screen. The method will not handle authentication.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->activatePlugin('hello-dolly');
In the plugin administration screen deactivate a plugin clicking the "Deactivate" link. The method will not handle authentication and navigation to the plugins administration page.
// Deactivate one plugin.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->deactivatePlugin('hello-dolly');
// Deactivate a list of plugins.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->deactivatePlugin(['hello-dolly', 'my-plugin']);
Parameters
string/\Codeception\Module\array
$pluginSlug - The plugin slug, like "hello-dolly", or a list of plugin slugs.
Assert a plugin is not installed in the plugins administration screen. The method will not handle authentication and navigation to the plugin administration screen.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->dontSeePluginInstalled('my-plugin');
Parameters
string
$pluginSlug - The plugin slug, like "hello-dolly".
Returns all the cookies whose name matches a regex pattern.
$I->loginAs('customer','password');
$I->amOnPage('/shop');
$cartCookies = $I->grabCookiesWithPattern("#^shop_cart\\.*#");
Parameters
string
$cookiePattern - The regular expression pattern to use for the matching.
Grabs the current page full URL including the query vars.
$today = date('Y-m-d');
$I->amOnPage('/concerts?date=' . $today);
$I->assertRegExp('#\\/concerts$#', $I->grabFullUrl());
Returns WordPress default test cookie object if present.
// Grab the default WordPress test cookie.
$wpTestCookie = $I->grabWordPressTestCookie();
// Grab a customized version of the test cookie.
$myTestCookie = $I->grabWordPressTestCookie('my_test_cookie');
Parameters
string
$name - Optional, overrides the default cookie name.
Navigate to the default WordPress logout page and click the logout link.
// Log out using the `wp-login.php` form and return to the current page.
$I->logOut(true);
// Log out using the `wp-login.php` form and remain there.
$I->logOut(false);
// Log out using the `wp-login.php` form and move to another page.
$I->logOut('/some-other-page');
Parameters
bool/bool/string
$redirectTo - Whether to redirect to another (optionally specified) page after the logout.
Login as the specified user. The method will not follow redirection, after the login, to any page. Depending on the driven browser the login might be "too fast" and the server might have not replied with valid cookies yet; in that case the method will re-attempt the login to obtain the cookies.
$I->loginAs('user', 'password');
$I->amOnAdminPage('/');
$I->see('Dashboard');
Parameters
string
$username - The user login name.string
$password - The user password in plain text.int
$timeout - The max time, in seconds, to try to login.int
$maxAttempts - The max number of attempts to try to login.
Login as the administrator user using the credentials specified in the module configuration. The method will not follow redirection, after the login, to any page.
$I->loginAsAdmin();
$I->amOnAdminPage('/');
$I->see('Dashboard');
Parameters
int
$timeout - The max time, in seconds, to try to login.int
$maxAttempts - The max number of attempts to try to login.
In an administration screen look for an error admin notice. The check is class-based to decouple from internationalization. The method will not handle authentication and navigation the administration area.
.notice.notice-error
ones.$I->loginAsAdmin()
$I->amOnAdminPage('/');
$I->seeErrorMessage('.my-plugin');
Parameters
string/string/\Codeception\Module\array
$classes - A list of classes the notice should have other than the
In an administration screen look for an admin notice. The check is class-based to decouple from internationalization. The method will not handle authentication and navigation the administration area.
$I->loginAsAdmin()
$I->amOnAdminPage('/');
$I->seeMessage('.missing-api-token.my-plugin');
Parameters
string/\Codeception\Module\array/string
$classes - A list of classes the message should have in addition to the.notice
one.
Assert a plugin is activated in the plugin administration screen. The method will not handle authentication and navigation to the plugin administration screen.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->seePluginActivated('my-plugin');
Parameters
string
$pluginSlug - The plugin slug, like "hello-dolly".
Assert a plugin is not activated in the plugins administration screen. The method will not handle authentication and navigation to the plugin administration screen.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->seePluginDeactivated('my-plugin');
Parameters
string
$pluginSlug - The plugin slug, like "hello-dolly".
Assert a plugin is installed, no matter its activation status, in the plugin adminstration screen. The method will not handle authentication and navigation to the plugin administration screen.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->seePluginInstalled('my-plugin');
Parameters
string
$pluginSlug - The plugin slug, like "hello-dolly".
Checks that the current page is one generated by the
wp_die
function. The method will try to identify the page based on the default WordPress die page HTML attributes.$I->loginAs('user', 'password');
$I->amOnAdminPage('/forbidden');
$I->seeWpDiePage();
Waits for any jQuery triggered AJAX request to be resolved.
$I->amOnPage('/triggering-ajax-requests');
$I->waitForJqueryAjax();
$I->see('From AJAX');
Parameters
int
$time - The max time to wait for AJAX requests to complete.
This class extends \Codeception\Module\WebDriver
This class implements \Codeception\Lib\Interfaces\RequiresPackage, \Codeception\Lib\Interfaces\ConflictsWithModule, \Codeception\Lib\Interfaces\ElementLocator, \Codeception\Lib\Interfaces\PageSourceSaver, \Codeception\Lib\Interfaces\ScreenshotSaver, \Codeception\Lib\Interfaces\SessionSnapshot, \Codeception\Lib\Interfaces\MultiSession, \Codeception\Lib\Interfaces\Remote, \Codeception\Lib\Interfaces\Web
Last modified 2yr ago