Skip to content

Commit

Permalink
fixed stats
Browse files Browse the repository at this point in the history
Signed-off-by: René <[email protected]>
  • Loading branch information
Snooz82 committed Jan 28, 2024
1 parent 02f8aaf commit 7df6d98
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
],
python_requires=">=3.6",
install_requires=["robotframework >= 5.0"],
entry_points={"console_scripts": ["SeleniumStats = SeleniumStats.__main__:main"]},
)
4 changes: 2 additions & 2 deletions src/SeleniumLibraryToBrowser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
EMBED = "EMBED"


__version__ = "0.8.0"
__version__ = "1.0.0"


class CookieInformation:
Expand Down Expand Up @@ -235,7 +235,7 @@ class SeleniumLibraryToBrowser(DynamicCore):
= Usage =
The usage of this library needs some consideration.
The usage of this library needs some consideration.
The library is designed to use [https://robotframework-browser.org|Browser] library internally and be mostly compatible to [https://robotframework.org/SeleniumLibrary|SeleniumLibrary]'s keywords.
However some keywords are impossible to be implement with [https://playwright.dev|Playwright], like all Alert handling keywords.
Expand Down
48 changes: 34 additions & 14 deletions src/SeleniumStats/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@

from robot.api import ExecutionResult, ResultVisitor
from robot.model import TestCase, TestSuite
from robot.result import Keyword
from robot.version import get_version, get_full_version

try:
from SeleniumLibraryToBrowser import SeleniumLibraryToBrowser

sl2b = SeleniumLibraryToBrowser()
sl2b_keywords = [
kw.replace(" ", "").replace("_", "").lower() for kw in sl2b.get_keyword_names()
]
except ImportError:
sl2b = None
sl2b_keywords = []

RF_MAJOR_VERSION = int(get_version().split(".")[0])


class KeywordCall:
Expand All @@ -38,20 +46,27 @@ def start_keyword(self, keyword):
# the hashes just allows us to count the different calling parents.
# We even do not store the entire hash, but just 16 bytes.
# it will never be possible to get the names back
if isinstance(keyword.parent, (TestCase, TestSuite)):
parent_hash = hashlib.sha3_512(keyword.parent.longname.encode("UTF-8")).hexdigest()[
16:32
]
parent = self.get_keyword_or_test_parent(keyword)
if isinstance(parent, (TestCase, TestSuite)):
parent_hash = hashlib.sha3_512(parent.longname.encode("UTF-8")).hexdigest()[16:32]
else:
parent_hash = hashlib.sha3_512(
f"{keyword.parent.libname}{keyword.parent.name}".encode()
f"{parent.libname}{parent.name}".encode()
).hexdigest()[16:32]
kw_name = keyword.name[len(keyword.libname) + 1 :]
if RF_MAJOR_VERSION >= 7:
kw_name = keyword.name
else:
kw_name = keyword.name[len(keyword.libname) + 1 :]
if kw_name not in KEYWORD_CALLS:
KEYWORD_CALLS[kw_name] = KeywordCall(parent_hash)
else:
KEYWORD_CALLS[kw_name].add(parent_hash)

def get_keyword_or_test_parent(self, keyword):
if not isinstance(keyword.parent, (Keyword, TestCase, TestSuite)):
return self.get_keyword_or_test_parent(keyword.parent)
return keyword.parent

def end_total_statistics(self, stats):
kw_calls = {}
for key in sorted(KEYWORD_CALLS.keys()):
Expand Down Expand Up @@ -80,19 +95,23 @@ def print_stats(self, kw_calls):
print(f'| {"Keyword".ljust(longest_keyword, " ")} | count | parents | migration status |')
print(f'+-{"".ljust(longest_keyword, "-") }-+-------+---------+------------------+')
for kw_name in kw_calls:
implemented = (
sl2b.keyword_implemented(kw_name.lower().replace(" ", "_")) if sl2b else False
)
if sl2b is not None:
if kw_name.replace(" ", "").lower() not in sl2b_keywords:
continue
implemented = sl2b.keyword_implemented(kw_name.lower().replace(" ", "_"))
msg = f' {str((not implemented) * "missing").ljust(16, " ")} |'
else:
msg = f' {"unknown".ljust(16, " ")} |'
print(
f'| {kw_name.ljust(longest_keyword , " ")} |'
f' {str(kw_calls[kw_name]["call_count"]).ljust(5," ")} |'
f' {str(kw_calls[kw_name]["parent_count"]).ljust(7, " ")} |'
f' {str((not implemented) * "missing").ljust(16, " ")} |'
f"{msg}"
)
print(f'+-{"".ljust(longest_keyword, "-")}-+-------+---------+------------------+')


if __name__ == "__main__":
def main():
if len(sys.argv) > 1:
original_output_xml = sys.argv[1]
if not os.path.isfile(original_output_xml):
Expand All @@ -101,8 +120,9 @@ def print_stats(self, kw_calls):
ExecutionResult(original_output_xml).visit(ResultAnalyzer())
else:
print(
"Use the path to a output.xml as first arguemnt. Example: python -m SeleniumStats ../output.xml"
"Use the path to a output.xml as first argument. Example: python -m SeleniumStats ../output.xml"
)

# normalized_keywords = [
# kw.lower().replace("_", "") for kw in sl2b.get_keyword_names() if "IMPLEMENTED" not in sl2b.get_keyword_tags(kw)]

if __name__ == "__main__":
main()

0 comments on commit 7df6d98

Please sign in to comment.