Skip to content

Commit 39df04e

Browse files
Update GettingStarted.md
1 parent 1e209b8 commit 39df04e

File tree

1 file changed

+38
-81
lines changed

1 file changed

+38
-81
lines changed

docs/GettingStarted.md

Lines changed: 38 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ Codeception follows simple naming rules to make it easy to remember (as well as
3838
```php
3939
$method = $I->grabAttributeFrom('#login-form', 'method');
4040
$I->assertSame('post', $method);
41-
```
42-
41+
```
4342

4443
## Actors
4544

@@ -60,7 +59,6 @@ modules:
6059
url: 'http://localhost/myapp/'
6160
```
6261
63-
6462
In this configuration file you can enable/disable and reconfigure modules for your needs.
6563
When you change the configuration, the actor classes are rebuilt automatically. If the actor classes are not created or updated as you expect,
6664
try to generate them manually with the `build` command:
@@ -69,7 +67,6 @@ try to generate them manually with the `build` command:
6967
php vendor/bin/codecept build
7068
```
7169

72-
7370
## Writing a Sample Test
7471

7572
Codeception has its own testing format called "Cest" (a combination of "Codecept" and "Test").
@@ -79,7 +76,6 @@ To start writing a test we need to create a new Cest file. We can do that by run
7976
php vendor/bin/codecept generate:cest Acceptance Signin
8077
```
8178

82-
8379
This will generate the `SigninCest.php` file inside the `tests/Acceptance` directory. Let's open it:
8480

8581
```php
@@ -110,7 +106,7 @@ namespace Tests\Acceptance;
110106
111107
use Tests\Support\AcceptanceTester;
112108
113-
class SigninCest
109+
final class SigninCest
114110
{
115111
public function signInSuccessfully(AcceptanceTester $I): void
116112
{
@@ -134,18 +130,16 @@ I click 'Login'
134130
I see 'Hello, davert'
135131
```
136132

137-
138133
Codeception generates this text representation from PHP code by executing:
139134

140135
```bash
141-
php vendor/bin/codecept generate:scenarios
136+
php vendor/bin/codecept generate:scenarios Acceptance
142137
```
143138

144-
145-
These generated scenarios will be stored in your `_data` directory in text files.
139+
These generated scenarios will be stored in your `tests/Support/Data/scenarios/Functional` directory in `*.txt` files.
146140

147141
Before we execute this test, we should make sure that the website is running on a local web server.
148-
Let's open the `tests/acceptance.suite.yml` file and replace the URL with the URL of your web application:
142+
Let's open the `tests/Acceptance.suite.yml` file and fill in the URL of your web application:
149143

150144
```yaml
151145
actor: AcceptanceTester
@@ -155,7 +149,6 @@ modules:
155149
url: 'http://myappurl.local'
156150
```
157151

158-
159152
After configuring the URL we can run this test with the `run` command:
160153

161154
```bash
@@ -167,102 +160,73 @@ This is the output we should see:
167160

168161
```bash
169162
Acceptance Tests (1) -------------------------------
170-
✔ SigninCest: sign in successfully
163+
✔ SigninCest: sign in successfully (0.00s)
171164
----------------------------------------------------
172165
173-
Time: 1 second, Memory: 21.00Mb
166+
Time: 00:00.019, Memory: 12.00 MB
174167
175-
OK (1 test, 1 assertions)
168+
OK (1 test, 1 assertion)
176169
```
177170

178-
179171
Let's get some detailed output:
180172

181173
```
182-
php vendor/bin/codecept run acceptance --steps
174+
php vendor/bin/codecept run Acceptance --steps
183175
```
184176

185-
186177
We should see a step-by-step report on the performed actions:
187178

188179
```bash
189180
Acceptance Tests (1) -------------------------------
190181
SigninCest: Login to website
191182
Signature: SigninCest.php:signInSuccessfully
192-
Test: tests/acceptance/SigninCest.php:signInSuccessfully
183+
Test: tests/Acceptance/SigninCest.php:signInSuccessfully
193184
Scenario --
194185
I am on page "/login"
195186
I fill field "Username" "davert"
196187
I fill field "Password" "qwerty"
197188
I click "Login"
198189
I see "Hello, davert"
199-
OK
190+
PASSED
200191
----------------------------------------------------
201192
202-
Time: 0 seconds, Memory: 21.00Mb
193+
Time: 00:00.019, Memory: 12.00 MB
203194
204-
OK (1 test, 1 assertions)
195+
OK (1 test, 1 assertion)
205196
```
206197

198+
This simple test can be extended to a complete scenario of site usage, therefore, by emulating the user's actions, you can test any of your websites.
207199

208-
This simple test can be extended to a complete scenario of site usage, therefore,
209-
by emulating the user's actions, you can test any of your websites.
210-
211-
To run more tests create a public method for each of them. Include `AcceptanceTester` object as `$I` as a method parameter and use the same `$I->` API you've seen before.
212-
If your tests share common setup actions put them into `_before` method.
213-
214-
For instance, to test CRUD we want 4 methods to be implemented and all next tests should start at `/task` page:
200+
To run more tests, create a public method for each of them. If your tests share common setup actions, put them into the `_before()` method:
215201

216202
```php
217203
<?php
204+
namespace Tests\Acceptance;
218205
219-
namespace Tests\Functional;
220-
221-
use \Tests\Support\FunctionalTester;
206+
use Tests\Support\AcceptanceTester;
222207
223-
class TaskCrudCest
208+
final class TaskCrudCest
224209
{
225-
function _before(AcceptanceTester $I)
210+
public function _before(AcceptanceTester $I): void
226211
{
227212
// will be executed at the beginning of each test
228213
$I->amOnPage('/task');
229214
}
230-
231-
function createTask(AcceptanceTester $I)
232-
{
233-
// todo: write test
234-
}
235-
236-
function viewTask(AcceptanceTester $I)
237-
{
238-
// todo: write test
239-
}
240-
241-
function updateTask(AcceptanceTester $I)
242-
{
243-
// todo: write test
244-
}
245-
246-
function deleteTask(AcceptanceTester $I)
247-
{
248-
// todo: write test
249-
}
250215
}
251216
```
252217

218+
Learn more about the [Cest format](https://codeception.com/docs/AdvancedUsage#Cest-Classes) in the Advanced Testing chapter.
253219

254-
Learn more about the [Cest format](https://codeception.com/docs/07-AdvancedUsage#Cest-Classes) in the Advanced Testing section.
255-
256-
## BDD
220+
## Behavior Driven Development (BDD)
257221

258-
Codeception allows execution of user stories in Gherkin format in a similar manner as is done in Cucumber or Behat.
259-
Please refer to [the BDD chapter](https://codeception.com/docs/07-BDD) to learn more.
222+
Codeception allows execution of user stories in Gherkin format in a similar manner as it is done in Cucumber or Behat.
223+
Please refer to [the BDD chapter](https://codeception.com/docs/BDD) to learn more.
260224

261225
## Configuration
262226

263-
Codeception has a global configuration in `codeception.yml` and a config for each suite. We also support `.dist` configuration files.
227+
Codeception has a global configuration file `codeception.yml` and a config for each suite. We also support `.dist` configuration files.
264228
If you have several developers in a project, put shared settings into `codeception.dist.yml` and personal settings into `codeception.yml`.
265-
The same goes for suite configs. For example, the `unit.suite.yml` will be merged with `unit.suite.dist.yml`.
229+
The same goes for suite configs. For example, the `Unit.suite.yml` will be merged with `Unit.suite.dist.yml`.
266230

267231
## Running Tests
268232

@@ -272,51 +236,44 @@ Tests can be started with the `run` command:
272236
php vendor/bin/codecept run
273237
```
274238

275-
276239
With the first argument you can run all tests from one suite:
277240

278241
```bash
279-
php vendor/bin/codecept run acceptance
242+
php vendor/bin/codecept run Acceptance
280243
```
281244

282-
283245
To limit tests run to a single class, add a second argument. Provide a local path to the test class, from the suite directory:
284246

285247
```bash
286-
php vendor/bin/codecept run acceptance SigninCest.php
248+
php vendor/bin/codecept run Acceptance SigninCest.php
287249
```
288250

289-
290-
Alternatively you can provide the full path to test file:
251+
Alternatively you can provide the full path to the test file:
291252

292253
```bash
293-
php vendor/bin/codecept run tests/acceptance/SigninCest.php
254+
php vendor/bin/codecept run tests/Acceptance/SigninCest.php
294255
```
295256

296-
297-
You can further filter which tests are run by appending a method name to the class, separated by a colon (for Cest or Test formats):
257+
You can further filter which tests to run by appending a method name to the class, separated by a colon:
298258

299259
```bash
300-
php vendor/bin/codecept run tests/acceptance/SigninCest.php:^anonymousLogin$
260+
php vendor/bin/codecept run tests/Acceptance/SigninCest.php:^anonymousLogin$
301261
```
302262

303-
304-
You can provide a directory path as well. This will execute all acceptance tests from the `backend` dir:
263+
You can provide a directory path as well. This will execute all Acceptance tests from the `backend` dir:
305264

306265
```bash
307-
php vendor/bin/codecept run tests/acceptance/backend
266+
php vendor/bin/codecept run tests/Acceptance/backend
308267
```
309268

310-
311269
Using regular expressions, you can even run many different test methods from the same directory or class.
312-
For example, this will execute all acceptance tests from the `backend` dir beginning with the word "login":
270+
For example, this will execute all Acceptance tests from the `backend` dir beginning with the word "login":
313271

314272
```bash
315-
php vendor/bin/codecept run tests/acceptance/backend:^login
273+
php vendor/bin/codecept run tests/Acceptance/backend:^login
316274
```
317275

318-
319-
To execute a group of tests that are not stored in the same directory, you can organize them in [groups](https://codeception.com/docs/07-AdvancedUsage#Groups).
276+
To execute a group of tests that are not stored in the same directory, you can organize them in [groups](https://codeception.com/docs/AdvancedUsage#Groups).
320277

321278
### Reports
322279

@@ -327,7 +284,7 @@ php vendor/bin/codecept run --steps --xml --html
327284
```
328285

329286

330-
This command will run all tests for all suites, displaying the steps, and building HTML and XML reports. Reports will be stored in the `tests/_output/` directory.
287+
This command will run all tests for all suites, displaying the steps, and building HTML and XML reports. The reports will be stored in the `tests/_output/` directory.
331288

332289
Learn more about [available reports](/docs/Reporting).
333290

@@ -354,7 +311,7 @@ There are plenty of useful Codeception commands:
354311

355312
## Conclusion
356313

357-
We have taken a look into the Codeception structure. Most of the things you need were already generated by the `bootstrap` command.
314+
We have taken a look into Codeception's structure. Most of the things you need were already generated by the `bootstrap` command.
358315
After you have reviewed the basic concepts and configurations, you can start writing your first scenario.
359316

360317
<div class="alert alert-warning"><a href="https://github.com/Codeception/codeception.github.com/edit/master/docs/GettingStarted.md"><strong>Improve</strong> this guide</a></div>

0 commit comments

Comments
 (0)