|
1 | | -"use strict"; |
| 1 | +import { When, Then } from '@cucumber/cucumber'; |
| 2 | +import assert from 'assert'; |
2 | 3 |
|
3 | | -var assert = require("cucumber-assert"); |
4 | | -module.exports = function() { |
5 | | - this.When(/^I click on first item$/, function(next) { |
6 | | - this.driver.get("https://lambdatest.github.io/sample-todo-app/"); |
7 | | - this.driver |
8 | | - .findElement({ name: "li1" }) |
9 | | - .click() |
10 | | - .then(next); |
11 | | - }); |
| 4 | +When('I click on first item', async function () { |
| 5 | + await this.driver.get('https://lambdatest.github.io/sample-todo-app/'); |
| 6 | + const firstItem = await this.driver.findElement({ name: 'li1' }); |
| 7 | + await firstItem.click(); |
| 8 | +}); |
12 | 9 |
|
13 | | - this.When(/^I click on second item$/, function(next) { |
14 | | - this.driver |
15 | | - .findElement({ name: "li2" }) |
16 | | - .click() |
17 | | - .then(next); |
18 | | - }); |
| 10 | +When('I click on second item', async function () { |
| 11 | + const secondItem = await this.driver.findElement({ name: 'li2' }); |
| 12 | + await secondItem.click(); |
| 13 | +}); |
19 | 14 |
|
20 | | - this.When(/^I add new item "([^"]*)"$/, function(newItemName, next) { |
21 | | - var self = this; |
22 | | - this.driver |
23 | | - .findElement({ id: "sampletodotext" }) |
24 | | - .sendKeys(newItemName + "\n") |
25 | | - this.driver |
26 | | - .findElement({ id: "addbutton" }) |
27 | | - .click() |
28 | | - .then(next); |
29 | | - }); |
| 15 | +When('I add new item {string}', async function (newItemName) { |
| 16 | + const inputBox = await this.driver.findElement({ id: 'sampletodotext' }); |
| 17 | + await inputBox.sendKeys(`${newItemName}\n`); |
| 18 | + const addButton = await this.driver.findElement({ id: 'addbutton' }); |
| 19 | + await addButton.click(); |
| 20 | +}); |
30 | 21 |
|
31 | | - this.Then(/^I should see new item in list "([^"]*)"$/, function(item, next) { |
32 | | - var self = this; |
33 | | - this.driver |
34 | | - .findElement({ xpath: "//html/body/div/div/div/ul/li[6]/span" }) |
35 | | - .getText() |
36 | | - .then(function(text) { |
37 | | - console.log(text); |
38 | | - assert.equal(text, item, next, "Expected title to be " + item); |
39 | | - }); |
| 22 | +Then('I should see new item in list {string}', async function (item) { |
| 23 | + const newItem = await this.driver.findElement({ |
| 24 | + xpath: '//html/body/div/div/div/ul/li[last()]/span', |
40 | 25 | }); |
41 | | -}; |
| 26 | + const text = (await newItem.getText()).trim(); |
| 27 | + console.log('New item text:', text); |
| 28 | + assert.strictEqual( |
| 29 | + text, |
| 30 | + item.trim(), |
| 31 | + `Expected title to be "${item}", but got "${text}"` |
| 32 | + ); |
| 33 | +}); |
0 commit comments