Skip to content

Commit 91ebac9

Browse files
committed
Add DSL step to support element function bindings
1 parent 30d2afb commit 91ebac9

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/04-dsl.mdx

+53
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,59 @@ All Gherkin steps that match the DSL expressions described here are readily exec
497497
</div>
498498
</details>
499499

500+
<details id="name-is-defined-by-js-function-applied-to-element">
501+
<summary class="dsl">
502+
503+
```gherkin
504+
<name> is defined by <javascriptRef> applied to <element>
505+
```
506+
<p>Applies a JavaScript function to an element and binds the result to <code>&lt;name&gt;</code> in the global scope.</p>
507+
</summary>
508+
<p>Where</p>
509+
<ul>
510+
<li><code>&lt;name&gt;</code> is the name to bind the function result to</li>
511+
<li><code>&lt;javascriptRef&gt;</code> is the name of the binding containing the javascript single argument function to apply</li>
512+
<li><code>&lt;element&gt;</code> is the name of the web element to apply the function to</li>
513+
</ul>
514+
<p>
515+
Optionally accepts the <Link href="/docs/eager-or-lazy"><code>@Eager</code>, <code>@Lazy</code></Link> or <code>@Masked</code> annotations.
516+
<ul>
517+
<li><code>@Eager</code> immediately applies the function to the element and binds the result to <code>&lt;name&gt;</code></li>
518+
<li><code>@Lazy</code> applies the function to the element and binds the result to <code>&lt;name&gt;</code> when it is first referenced</li>
519+
<li>In the absence of either of the above annotations, the function is applied to the element every time <code>&lt;name&gt;</code> is referenced</li>
520+
<li><code>@Masked</code> masks the captured value to prevent it from being logged as clear text</li>
521+
</ul>
522+
</p>
523+
<p>Examples</p>
524+
525+
```gherkin {3}
526+
Given getHref is defined by js "(elem) => elem.getAttribute('href')"
527+
And the todo link can be located by xpath "//a[contains(text(),'TodoMVC')]"
528+
And href is defined by getHref applied to the todo link
529+
When I navigate to "https://todomvc.com/examples/react/dist/"
530+
Then href should be "http://todomvc.com"
531+
```
532+
533+
```gherkin {9}
534+
Given getHref is defined by js
535+
"""
536+
(elem) => {
537+
return elem.getAttribute('href')
538+
}
539+
"""
540+
And the todo link can be located by xpath "//a[contains(text(),'TodoMVC')]"
541+
When I navigate to "https://todomvc.com/examples/react/dist/"
542+
And @Eager href is defined by getHref applied to the todo link
543+
Then href should be "http://todomvc.com"
544+
```
545+
546+
<div class="grid-3">
547+
<div><Link to="#name-is-defined-by-js-function-applied-to-element">Link</Link></div>
548+
<div align="center"></div>
549+
<div align="right">Since <Link to="https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.6.0">v4.6.0</Link></div>
550+
</div>
551+
</details>
552+
500553
#### System Processes bindings
501554

502555
<details id="name-is-defined-by-system-process-expression">

0 commit comments

Comments
 (0)