33K Views

Get started with codeception

In the previous blog by default, we created 3 suites Acceptance, Functional, and Unit.

So before creating suit configuration, we have to generate bootstrap commands. we generate bootstrap commands, because each suite has its own bootstrap file, It’s located in the suite directory and is named _bootstrap.php and It will be executed before each test.

let’s take a look at Codeception architecture. We assume that you already installed Codeception and bootstrapped your first three test suites. As in previous part, Codeception generated three of them: Unit, Functional, and Acceptance. They are well described in previous part and as in your tests folder, you have three config. files and three directories with a name corresponding to their suites like acceptance.suite.yml for Acceptance and for Functional it is functional.suite.yml and for Unit , it is unit.suite.yml.

Writing a Sample Scenario for sign in support UVdesk panel and then after sign in testing on Mailbox Panel.
By default we write our test in narrative scenarios and to make PHP file a valid scenario, its name should have a Cest suffix.

Lets say we created tests/acceptance/SigninCest.php.

We can do that by running the command:

php codecept.phar run acceptance SigninCest.php --steps.

A Scenario always starts with class initialization. After that, writing a scenario with typing $I->

$I = new FunctionalTester($scenario);
$I->wantTo('perform actions and see result');

We have to define a class inside of which we are writing our scenarios, class name should be same as file name like if we are testing on the sign in support UVdesk section and our file name is SigninCest.php then our class is the Sign in likewise,

class SigninCest
{
public function SigninTest(AcceptanceTester $I)

As we know that all actions are performed by tester object ie. SigninTest inside a class which is Signin are defined in modules.

php vendor/bin/codecept g:Cest Acceptance SigninCest.php --config src/AppBundle

Above command create new Cest file with name SigninCest inside acceptance directory.

The generated file will look like this:

<?php
class BasicCest
{
public function _before(\AcceptanceTester $I)
{
}

public function _after(\AcceptanceTester $I)
{
}

// tests
public function tryToTest(\AcceptanceTester $I)
{
}

In a _before and _after method, you can use common setups and teardowns for the tests in the class. This actually makes Cest tests more flexible than Cepts, which rely only on similar methods in Helper classes.

We assume that we have a login page, where we get authenticated by providing username and password. Then after login, we sent a user page where we have mailbox panel and we click on the mailbox and then we add new mailbox with mailbox name and mailbox email id and then a new mailbox added in our UVdesk mailbox panel.

Let’s look at how this scenario is written in Codeception:

$I->wantTo('login by magento2 sso');
$I->amOnUrl('https://support.uvdesk.com/en/customer/login');
$I->click('.uv-element-block.uv-no-margin-bottom div:nth-child(1) a');
$I->wait(2);
$I->fillfield('_username','your email');
$I->fillfield('_password','your password');
$I->click('.uv-btn');
$I->wait(10);
$I->click('#manage .uv-brick:first-child .uv-brick-section a:first-child');
$I->wait('10');
$I->click('.uv-app-list-action-rt .uv-btn-action.add-mailbox');
$I->wait('10');
$I->fillfield('#uv-add-mailbox-form input[name="name"]','your mailbox name');
$I->fillfield('#uv-add-mailbox-form input[name="email"]','your mailbox email id');
$I->click('#uv-add-mailbox-form .uv-btn.save-mailbox');
$I->wait(15);
$I->click('#mailbox-added .uv-pop-up-box.uv-pop-up-slim .uv-pop-up-close');

This scenario can probably be read by non-technical people. If you just remove all special chars like braces, arrows and $, this test transforms into plain English text:

I am user.
I want to login to Support uvdesk website.
I amOn page '/login'
I see('SIGN IN').
I click('SIGN IN').
I see('I am UVdesk Support Agent').
I click('I am UVdesk Support Agent').
I fillfield 'useremail','abc@example.com'.
I fillfield 'password','abc'.
I click('SIGNIN')
I see (Mailbox')
I click('Mailbox')
I see ('NEW MAILBOX')
I click('NEW MAILBOX')
I add MailboxName('abc mailbox')
I add MailboxAdress('abc@example.com')
I see('PROCEED')
I click('PROCEED').

Before we execute this test, we should make sure that the website is running on a local web server. Let’s open the tests/acceptance.suite.yml file and replace the URL with the URL of your web application like we are performing a test on http://support.uvdesk.com

actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: 'http://support.uvdesk.com'
- \Helper\Acceptance
Category(s) Codeception
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php