You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It can operate with different entities: the web page can be loaded with Symfony1 module, the database assertion uses Db module, and file state can be checked with Filesystem module.
29
31
30
32
Modules are attached to Guy-classes in suite config.
31
33
For current example in 'tests/functional.suite.yml' we should see.
32
34
33
-
``
35
+
``
36
+
34
37
class_name: TestGuy
35
38
modules:
36
39
enabled: [Symfony1, Db, Filesystem]
37
-
``
40
+
``
41
+
38
42
39
43
The TestGuy class has it's methods defined in modules. Actually, it doesn't contain any of them, but acts as a proxy for them. It knows which module executes this action and passes parameters into it. To make your IDE see all methods of TestGuy listed, you use the 'build' command. It generates definition of TestGuy class by copying signatures from modules.
40
44
@@ -62,7 +66,8 @@ It's good idea to define missing actions or assertion commands in helpers.
62
66
63
67
Let's say we are going to extend TestHelper class. By default it's linked with a TestGuy class and functional test suite.
64
68
65
-
``
69
+
``
70
+
66
71
{% highlight php %}
67
72
<?php
68
73
namespace Codeception\Module;
@@ -75,22 +80,26 @@ class TestHelper extends \Codeception\Module
75
80
}
76
81
?>
77
82
{% endhighlight %}
78
-
``
83
+
``
84
+
79
85
80
86
As for actions everything is quite simple. Every action you define is a public function. Write down any public method, run 'build' command, and you will see this function added into TestGuy class. Still, public methods prefixed by '_' are treated as hidden and won't be added you your Guy class.
81
87
82
88
Assertions are a bit tricky. First of all it's recommended to prefix all your assert actions with 'see', or 'dontSee'. In Codeception philosophy all tests are performed by humans, i.e. guys. The expected result they see (or they don't) is what we use for assertion.
Every 'see' or 'dontSee' function requires at least one assert. Codeception uses PHPUnit assertions.
105
115
106
116
### Assertions
107
117
You can define asserts by using assertXXX functions, from 'PHPUnit/Framework/Assert/Functions.php' file.
108
118
In case your application falls into conflict with one of this functions, you can use PHPUnit static methods from class PHPUnit_Framework_Assert to define asserts.
109
119
110
-
``
120
+
``
121
+
111
122
{% highlight php %}
112
123
<?php
113
124
@@ -119,11 +130,13 @@ function seeClassExist($class)
119
130
}
120
131
?>
121
132
{% endhighlight %}
122
-
``
133
+
``
134
+
123
135
124
136
Each module has special $this->assert and $this->assertNot methods. They take the same arguments and are useful if you need to define both positive and negative assertions in your module. This functions take an array as parameter, where the first value of array is the name of PHPUnit assert function.
Next time you start suite without this values set, an exception will be thrown.
298
326
299
327
For the optional parameters you should have default values set. The $config property is used to define optional parameters as well as their values. In Seleinum module we use default Selenium Server address and port.
300
328
301
-
``
329
+
``
330
+
302
331
{% highlight php %}
303
332
<?php
304
333
class Selenium extends \Codeception\Util\MinkJS
@@ -307,11 +336,13 @@ class Selenium extends \Codeception\Util\MinkJS
Copy file name to clipboardExpand all lines: docs/04-AcceptanceTesting.markdown
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ We call him a WebGuy, as he uses web browser to open your site and test it's beh
13
13
Writing Codeception tests is just the same as describing actions you perform on a site. Only the basic knowlegde of HTML and PHP is required for wrinig such tests.
14
14
15
15
``
16
+
16
17
{% highlight php %}
17
18
<?php
18
19
$I = new WebGuy($scenario);
@@ -24,13 +25,14 @@ $I->click('LOGIN');
24
25
$I->see('Welcome, Davert!');
25
26
?>
26
27
{% endhighlight %}
27
-
``
28
+
{% endhighlight %}
28
29
29
30
With no knowledge in PHP or HTML you can still read this scenario. Or not?
30
31
Well, if you have problems reading this, Codeception can convert this scenario into text written mostly in native English:
31
32
32
33
``
33
34
35
+
34
36
I WANT TO SIGN IN
35
37
I am on page '/login'
36
38
I fill field ['signin[username]', 'davert']
@@ -40,6 +42,7 @@ I see 'Welcome, Davert!'
40
42
41
43
``
42
44
45
+
43
46
This scenario can be performed in either simple PHP browser or within the browser through Selenium (also Sahi or ZombieJS).
0 commit comments