Skip to content

Commit

Permalink
QE-11488 update filenames and paths (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddl-kavya authored Mar 7, 2024
1 parent 3c1d903 commit 45f9fff
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 21 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.191.0
- Change - shorten fienames and paths, remove quotes, '{,},#' from file names.

## 0.190.0
- Add - screenshot highlight on find functions
- Change - highlight to be separate overlay element
Expand Down
2 changes: 1 addition & 1 deletion features/browser/images.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Feature: Images
When I click the button "I should see the button "button with child""
Then I should not see the image with the alt text "After I open a browser at the url "http://{HOST_ADDRESS}:{PORT}/buttons.html""
And I should not see the image with the alt text "After I open a browser at the url "http://{HOST_ADDRESS}:{PORT}/buttons.html""
And I should see the image with the alt text "After I should see the button "button with child""
And I should see the image with the alt text "After I should see the button button with child"
8 changes: 4 additions & 4 deletions features/cli/report_basics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Feature: Report basics

* # Can see image for step with secret in name
When I click the button "I should see the text "\{MY_SECRET\}""
Then I should see the image with the alt text "After I should see the text "\{MY_SECRET\}""
Then I should see the image with the alt text "After I should see the text MY_SECRET"

* # Cannot see secrets in the exception message
When I click the button "Then I click the button "\{MY_SECRET\}""
Expand All @@ -70,13 +70,13 @@ Feature: Report basics
And I should not see the image with the alt text "After I open a browser at the url \"http://{HOST_ADDRESS}:{PORT}/checkboxes.html\""
And I should not see the image with the alt text "After I should see the checkbox \"checkbox with inner label\""
Then I click the button "Then I should see the checkbox \"checkbox with inner label\""
And I should see the image with the alt text "After I should see the checkbox \"checkbox with inner label\""
And I should see the image with the alt text "After I should see the checkbox checkbox with inner label"
And I should not see the image with the alt text "After I start a webserver at directory \"data/www\" and save the port to the variable \"PORT\""
And I should not see the image with the alt text "After I open a browser at the url \"http://{HOST_ADDRESS}:{PORT}/checkboxes.html""
When I save the current url to the variable "CURRENT_URL"
And I click the link "Index"
Then I navigate to the url "{CURRENT_URL}"
And I wait to see the image with the alt text "After I should see the checkbox \"checkbox with inner label\""
And I wait to see the image with the alt text "After I should see the checkbox checkbox with inner label"
And I should not see the image with the alt text "After I start a webserver at directory \"data/www\" and save the port to the variable \"PORT\""
And I should not see the image with the alt text "After I open a browser at the url \"http://{HOST_ADDRESS}:{PORT}/checkboxes.html\""

Expand Down Expand Up @@ -322,4 +322,4 @@ Feature: Report basics
| .* | Just a scenario that opens a web page | 3 | failed | .* |
When I click the button "Just a scenario that opens a web page"
And I wait to click the button "show images"
And I should see the image with the alt text "After I should see the text \"inexistent\""
And I should see the image with the alt text "After I should see the text inexistent"
4 changes: 2 additions & 2 deletions features/cli/secrets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Feature: Secrets
Then I pass the secret "\{MY_SECRET\}" to a substep
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/substeps_without_variable_passthru --secrets MY_SECRET --results={CUCU_RESULTS_DIR}/substeps_without_variable_passthru_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see a file at "{CUCU_RESULTS_DIR}/substeps_without_variable_passthru_results/Feature that spills the beans/This scenario prints some secrets to the logs/0003 - I echo "************"/0000 - After I echo "************".png"
Then I should see a file at "{CUCU_RESULTS_DIR}/substeps_without_variable_passthru_results/Feature that spills the beans/This scenario prints some secrets to the logs/0003 - I echo ************/0000 - After I echo ************.png"

Scenario: User gets expected behavior when using variable_passthru=True
Given I create a file at "{CUCU_RESULTS_DIR}/substeps_with_variable_passthru/environment.py" with the following:
Expand Down Expand Up @@ -178,4 +178,4 @@ Feature: Secrets
Then I pass the secret "\{MY_SECRET\}" to a substep
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/substeps_with_variable_passthru --secrets MY_SECRET --results={CUCU_RESULTS_DIR}/substeps_with_variable_passthru_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see a file at "{CUCU_RESULTS_DIR}/substeps_with_variable_passthru_results/Feature that spills the beans/This scenario prints some secrets to the logs/0003 - I echo "\{MY_SECRET\}"/0000 - After I echo "\{MY_SECRET\}".png"
Then I should see a file at "{CUCU_RESULTS_DIR}/substeps_with_variable_passthru_results/Feature that spills the beans/This scenario prints some secrets to the logs/0003 - I echo MY_SECRET/0000 - After I echo MY_SECRET.png"
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.190.0"
version = "0.191.0"
license = "MIT"
description = "Easy BDD web testing"
authors = ["Domino Data Lab <[email protected]>"]
Expand Down
10 changes: 7 additions & 3 deletions src/cucu/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cucu import config, init_scenario_hook_variables, logger
from cucu.config import CONFIG
from cucu.page_checks import init_page_checks
from cucu.utils import take_screenshot
from cucu.utils import ellipsize_filename, take_screenshot

CONFIG.define(
"FEATURE_RESULTS_DIR",
Expand Down Expand Up @@ -57,7 +57,9 @@ def after_all(ctx):
def before_feature(ctx, feature):
if config.CONFIG["CUCU_RESULTS_DIR"] is not None:
results_dir = config.CONFIG["CUCU_RESULTS_DIR"]
ctx.feature_dir = os.path.join(results_dir, feature.name)
ctx.feature_dir = os.path.join(
results_dir, ellipsize_filename(feature.name)
)
CONFIG["FEATURE_RESULTS_DIR"] = ctx.feature_dir


Expand Down Expand Up @@ -86,7 +88,9 @@ def before_scenario(ctx, scenario):
ctx.step_timers = {}

if config.CONFIG["CUCU_RESULTS_DIR"] is not None:
ctx.scenario_dir = os.path.join(ctx.feature_dir, scenario.name)
ctx.scenario_dir = os.path.join(
ctx.feature_dir, ellipsize_filename(scenario.name)
)
CONFIG["SCENARIO_RESULTS_DIR"] = ctx.scenario_dir
os.makedirs(ctx.scenario_dir, exist_ok=True)

Expand Down
14 changes: 10 additions & 4 deletions src/cucu/reporter/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from cucu import format_gherkin_table, logger
from cucu.ansi_parser import parse_log_to_html
from cucu.config import CONFIG
from cucu.utils import get_step_image_dir
from cucu.utils import ellipsize_filename, get_step_image_dir


def escape(data):
Expand Down Expand Up @@ -123,8 +123,12 @@ def generate(results, basepath, only_failures=False):

if feature["status"] not in ["skipped", "untested"]:
# copy each feature directories contents over to the report directory
src_feature_filepath = os.path.join(results, feature["name"])
dst_feature_filepath = os.path.join(basepath, feature["name"])
src_feature_filepath = os.path.join(
results, ellipsize_filename(feature["name"])
)
dst_feature_filepath = os.path.join(
basepath, ellipsize_filename(feature["name"])
)
shutil.copytree(
src_feature_filepath, dst_feature_filepath, dirs_exist_ok=True
)
Expand All @@ -133,7 +137,9 @@ def generate(results, basepath, only_failures=False):
CONFIG.restore()

scenario_filepath = os.path.join(
basepath, feature["name"], scenario["name"]
basepath,
ellipsize_filename(feature["name"]),
ellipsize_filename(scenario["name"]),
)

scenario_configpath = os.path.join(
Expand Down
24 changes: 18 additions & 6 deletions src/cucu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,33 @@ def text_in_current_frame(browser: Browser) -> str:


def ellipsize_filename(raw_filename):
max_filename = 255
if len(raw_filename) < max_filename:
return raw_filename
max_filename = 100
new_raw_filename = normalize_filename(raw_filename)
if len(new_raw_filename) < max_filename:
return new_raw_filename

ellipsis = "..."
# save the last chars, as the ending is often important
end_count = 100
end_count = 40
front_count = max_filename - (len(ellipsis) + end_count)
ellipsized_filename = (
raw_filename[:front_count] + ellipsis + raw_filename[-1 * end_count :]
new_raw_filename[:front_count]
+ ellipsis
+ new_raw_filename[-1 * end_count :]
)

return ellipsized_filename


def normalize_filename(raw_filename):
normalized_filename = (
raw_filename.replace('"', "")
.replace("{", "")
.replace("}", "")
.replace("#", "")
)
return normalized_filename


def get_step_image_dir(step_index, step_name):
"""
generate .png image file name that meets these criteria:
Expand Down

0 comments on commit 45f9fff

Please sign in to comment.