BehatClipboard is an integration layer between contexts in Behat 3.0+ and it provides:, (*2)
Clipboard
,Behat\ClipboardExtension\Context\FeatureContext
context which provides base
step definitions for your contexts,Purpose of this is that, I'm testing REST API. In return I get JSON that want call universal way.
I'm saving last respond to clipboard and freely call this by clipboard(last_response.body.KEY.KEY.KEY)
, (*3)
System generate a container that hold data. We could save there and read inside context.
Clipboard will we shared between all context that implement interface Behat\ClipboardExtension\Context\ClipboardContextAwareInterface
;, (*4)
Extension add event for transform data in scenario with given prefix
and pattern
., (*5)
In default, it will look for example: clipboard(test1)
, where test1
is key from clipboard
and replace in scenario before execute step. The transform not depend on given context., (*6)
Given Clipboard save the value "10" on key "test1" #in next step clipboard.test1 will be transformed to 10, and send to step And Clipboard over key "clipboard(test1)" have "10"
Minimum functionality you need to implement in your context is saving to clipboard. Like in Behat\ClipboardExtension\Context\FeatureContext
:, (*7)
/** * @Then Clipboard save the value :arg1 on key :arg2 * * @param $arg1 * @param $arg2 */ public function clipboardSaveTheValueOnKey($arg1, $arg2) { $this->clipboard->set($arg2, $arg1); }
The easiest way to install is by using Composer:, (*8)
$> curl -sS https://getcomposer.org/installer | php $> php composer.phar require timitao/behatclipboard='1.0.*'
or composer.json, (*9)
"require": { "timitao/behatclipboard": "1.0.*" },
Base context allow: * save value on key to clipboard * check containing KEY by clipboard * copy from KEY1 to KEY2 * save multi values by TableNode * save PyString by key, (*10)
Look at this clipboard.feature, (*11)
We can define default values for clipboard by:, (*12)
extensions: Behat\ClipboardExtension\ClipboardExtension: defaults: key1: value1 key2.key2 : value2
Additionally, it assist dotNotification., (*13)
If you save array on [test=>[test2=>15]]
in scenario, you could call this by
* clipboard(test1)
to get [test2=>15]
* clipboard(test.test2)
to get 15
, (*14)
Actually used configuration:
* prefix
- prefix for recognise data in scenario to replace. Default: clipboard
* pattern
- pattern that will be complete with prefix and looking data to transform from clipboard. Default: /%s\(([a-zA-Z0-9_\.\-]+)\)/
, (*15)
Suggested to use with Behat Assert Context., (*16)
Staring version 1.0.0
, will follow Semantic Versioning v2.0.0., (*17)