Skip to content

Commit

Permalink
Jliao/qe 13732/click table column given text (#374)
Browse files Browse the repository at this point in the history
Add a step and tests to allow users to click a specific column that
relates to a row that contains specific text.
  • Loading branch information
ddl-joy-liao authored Oct 17, 2023
1 parent e36ad16 commit 63c4b4d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project closely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.168.0
- Add - step and test for clicking a table column within a table row that has specified text

## 0.167.0
- Fix - fuzzy JS code injection in web page redirection

Expand Down
14 changes: 14 additions & 0 deletions features/browser/tables.feature
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,17 @@ Feature: Tables
Then I should see the text "Africa clicked"
When I wait to click the cell corresponding to the "4th" row and "1st" column in the "6th" table
Then I should see the text "Tokyo clicked"

Scenario: User can click a column within a row that contains specific text within the table
Given I open a browser at the url "http://{HOST_ADDRESS}:{PORT}/tables.html"
And I should see a table that matches the following:
| City | Country | Continent |
| Paris | France | Europe |
| Cairo | Egypt | Africa |
| Tokyo | Japan | Asia |
When I wait to click the "2nd" column within a row that contains the text "Paris" in the "6th" table
Then I should see the text "France clicked"
When I wait to click the "1st" column within a row that contains the text "Africa" in the "6th" table
Then I should see the text "Cairo clicked"
When I wait to click the "3rd" column within a row that contains the text "Japan" in the "6th" table
Then I should see the text "Asia clicked"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cucu"
version = "0.167.0"
version = "0.168.0"
license = "MIT"
description = "Easy BDD web testing"
authors = ["Domino Data Lab <[email protected]>"]
Expand Down
36 changes: 35 additions & 1 deletion src/cucu/steps/table_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

from selenium.webdriver.common.by import By

from cucu import config, format_gherkin_table, fuzzy, helpers, retry, step
from cucu import (
config,
format_gherkin_table,
fuzzy,
helpers,
logger,
retry,
step,
)
from cucu.browser.frames import run_in_all_frames


Expand Down Expand Up @@ -342,3 +350,29 @@ def wait_click_table_cell(ctx, row, column, table):
Add 1 to the row number if the table has a header row.
"""
retry(click_table_cell)(ctx, row, column, table)


@step(
'I wait to click the "{column:nth}" column within a row that contains the text "{match_text}" in the "{table:nth}" table'
)
def wait_click_table_cell_matching_text(ctx, column, match_text, table):
def click_table_cell_matching_text(ctx, column, match_text, table):
table_element = find_table_element(ctx, table)

try:
row = table_element.find_elements(
By.XPATH, f'//td[.="{match_text}"]/parent::tr'
)
if len(row) > 1:
logger.warn(
f'Found {len(row)} rows with matching text "{match_text}", using the first row.'
)
cell = row[0].find_elements(By.CSS_SELECTOR, "td")[column]
except IndexError:
raise RuntimeError(
f"Cannot find table:{table+1},column:{column+1},text:{match_text}. Please check your table data."
)

ctx.browser.click(cell)

retry(click_table_cell_matching_text)(ctx, column, match_text, table)

0 comments on commit 63c4b4d

Please sign in to comment.