Codeception is a Behavioral Driven Development test framework for PHP. With Codeception, and BDD in general for that matter, your tests define how your application should behave in different scenarios.
Get set up
- Install Composer
First, make sure you have PHP Dependency Manager Composer installed. You can do this by following the instructions on their download page.
- Installing Codeception
Once you have Composer, you can then follow the instructions in step 1 of Codeception’s Quickstart guide, choosing whether to install for reference or global use.
Once that has been taken care of, clone this repository and use these files as a skeleton for your tests with CrossBrowserTesting using Codeception.
- Set up Acceptance Test
In order to run tests through our service, you will need to make changes to the file located at tests/acceptance.suite.yml
In this file you will need to first specify within the WebDriver the
url
you are testing. Then within the host field, you will need to provide your email that is associated with your CrossBrowserTesting account where[email protected]
is. After the colon you will need to replaceyourauthkey
with the authkey associated with your account.There is also the option to change your
capabilities
to rename/re-version your test, extend themax_duration
, or change your target browser(s).acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://crossbrowsertesting.github.io/'
host: 'YOUR_USERNAME:[email protected]'
port: 80
browser: chrome
capabilities:
name: 'Codeception Example'
build: '1.0'
browserName: 'Chrome'# request the latest version of chrome
platform: 'Windows 10'# To specify version, add version: 'desired version'
record_video: 'true'
record_network: 'false'A CBTCest.php file created in the tests/acceptance folder will run a simple acceptance test using our services.
CBTCest.php
//Insert opening php tag
class CBTCest
{
public function tryToTest(AcceptanceTester $I) {
$I->wantTo('ensure my todo-app works');
$I->amOnPage('/todo-app.html');
$I->see('Todo App');
$I->checkOption('/html/body/div/div/div/ul/li[4]/input');
$I->checkOption('/html/body/div/div/div/ul/li[5]/input');
$I->fillField('//*[@id="todotext"]','run your first selenium test');
$I->click('//*[@id="addbutton"]');
$I->click('/html/body/div/div/div/a');
}
}To find the os_api_name and browser_api_name that corresponds to your targeted platform, you can go to CrossBrowserTesting's Selenium Page, open the wizard, and watch the capabilities in the sample script change as you select different browsers, or you can parse the os/browser you want out of the JSON response from https://crossbrowsertesting.com/api/v3/selenium/browsers.
If you run into any trouble, visit our Codeception GitHub, or if you have any questions, contact Support.
See Also
Test Frameworks and Tools
About Selenium Testing
Selenium and PHP
Behat