Skip to content

Commit 925e653

Browse files
committed
Add DSLs for performing actions on web elements by javascript
1 parent ac49624 commit 925e653

File tree

4 files changed

+842
-550
lines changed

4 files changed

+842
-550
lines changed

docs/04-dsl.mdx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,12 +4238,89 @@ Since [v4.8.0](https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.8.0)
42384238

42394239
#### JS actions
42404240

4241+
<details id="i-execute-js-on-element">
4242+
<summary class="dsl">
4243+
4244+
```gherkin
4245+
I execute <js|javascript> on <element> "<function>"
4246+
```
4247+
4248+
<p>Executes a javascript function on a web element.</p>
4249+
</summary>
4250+
<p>Where</p>
4251+
<ul>
4252+
<li><code>&lt;element&gt;</code> is the name of the element to execute the function on</li>
4253+
<li>
4254+
<code>&lt;function&gt;</code> is the javascript function that will perform the action (can be in <Link to="/docs/doc-strings">DocString</Link> position)
4255+
<ul>
4256+
<li>The function must use <Link to="/docs/js-functions">Arrow syntax</Link> and define a single argument for accepting the web element.</li>
4257+
</ul>
4258+
</li>
4259+
</ul>
4260+
<p>Example</p>
4261+
4262+
```gherkin {3}
4263+
Given the todo link can be located by xpath "//a[contains(text(),'TodoMVC')]"
4264+
When I navigate to "https://todomvc.com/examples/react/dist/"
4265+
And I execute js on the todo link "(elem) => elem.click()"
4266+
```
4267+
4268+
<div class="grid-3">
4269+
<div><Link to="#i-execute-js-on-element">Link</Link></div>
4270+
<div align="center"></div>
4271+
<div align="right">Since <Link to="https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.16.0">v4.16.0</Link></div>
4272+
</div>
4273+
</details>
4274+
4275+
<details id="i-execute-jsref-on-element">
4276+
<summary class="dsl">
4277+
4278+
```gherkin
4279+
I execute <functionRef> on <element>
4280+
```
4281+
4282+
<p>Executes a javascript function on a web element.</p>
4283+
</summary>
4284+
<p>Where</p>
4285+
<ul>
4286+
<li>
4287+
<code>&lt;functionRef&gt;</code> is the name of the binding containing the javascript function to execute
4288+
<ul>
4289+
<li>The referenced function must use <Link to="/docs/js-functions">Arrow syntax</Link> and define a single argument for accepting the web element.</li>
4290+
</ul>
4291+
</li>
4292+
<li><code>&lt;element&gt;</code> is the name of the element to execute the function on</li>
4293+
</ul>
4294+
<p>Example</p>
4295+
4296+
```gherkin {4}
4297+
Given the todo link can be located by xpath "//a[contains(text(),'TodoMVC')]"
4298+
And the click function is defined by js "(elem) => elem.click()"
4299+
When I navigate to "https://todomvc.com/examples/react/dist/"
4300+
And I execute the click function on the todo link
4301+
```
4302+
4303+
<div class="grid-3">
4304+
<div><Link to="#i-execute-jsref-on-element">Link</Link></div>
4305+
<div align="center"></div>
4306+
<div align="right">Since <Link to="https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.16.0">v4.16.0</Link></div>
4307+
</div>
4308+
</details>
4309+
42414310
<details id="element-can-be-actioned-by-javascript">
42424311
<summary class="dsl">
4312+
4313+
:::caution Deprecated since v4.16.0 and will be dropped in next major Gwen 5 release.
42434314

42444315
```gherkin
42454316
<element> can be <actioned> by <javascript|js> "<script>"
42464317
```
4318+
4319+
Instead use one of:
4320+
4321+
- `I execute <js|javascript> on <element> "<function>"`
4322+
- `I execute <functionRef> on <element>`
4323+
:::
42474324
<p>Registers a javascript action on an element. When the action is performed, then the javascript will execute in place of the default behaviour.</p>
42484325
</summary>
42494326
<p>Where</p>

docusaurus.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ module.exports = {
99
url: 'https://gweninterpreter.org',
1010
baseUrl: '/',
1111
onBrokenLinks: 'throw',
12-
onBrokenMarkdownLinks: 'warn',
12+
markdown: {
13+
hooks: {
14+
onBrokenMarkdownLinks: 'warn'
15+
}
16+
},
1317
favicon: 'img/favicon.ico',
1418
organizationName: 'gwen-interpreter', // Usually your GitHub org/user name.
1519
projectName: 'gwen-interpreter.github.io', // Usually your repo name.
@@ -41,7 +45,7 @@ module.exports = {
4145
label: 'FAQ',
4246
},
4347
{
44-
href: '/docs/dsl#data-asserts',
48+
href: '/docs/dsl#js-actions',
4549
position: 'left',
4650
label: "What's New?",
4751
},

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"write-heading-ids": "docusaurus write-heading-ids"
1515
},
1616
"dependencies": {
17-
"@docusaurus/core": "^3.8.1",
18-
"@docusaurus/preset-classic": "^3.8.1",
17+
"@docusaurus/core": "^3.9.2",
18+
"@docusaurus/preset-classic": "^3.9.2",
1919
"@mdx-js/react": "^3.0.1",
2020
"@svgr/webpack": "^8.1.0",
2121
"clsx": "^2.1.0",

0 commit comments

Comments
 (0)