Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions behave2cucumber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''


def convert(json_file, remove_background=False, duration_format=False, deduplicate=False):
import base64
screenshots_base_folder= '.\\screenshot\\'
def convert(json_file, remove_background=False, duration_format=False, deduplicate=False, screenshot=False):
# json_nodes are the scopes available in behave/cucumber json: Feature -> elements(Scnerios) -> Steps
json_nodes = ['feature', 'elements', 'steps']
# These fields doesn't exist in cucumber report, there-fore when converting from behave, we need to delete these
Expand All @@ -20,6 +20,8 @@ def format_level(tree, index=0, id_counter=0):
for item in tree:
# Location in behave json translates to uri and line in cucumber json
uri, line_number = item.pop("location").split(":")
# The name of screenshot file is the name of the feature file,plus the line number, like login.feature1.png
screenshot_name=uri+line_number
item["line"] = int(line_number)
for field in fields_not_exist_in_cucumber_json:
if field in item:
Expand All @@ -37,6 +39,10 @@ def format_level(tree, index=0, id_counter=0):
(str(error_msg).replace("\"", "").replace("\\'", ""))[:2000])
if 'duration' in item["result"] and duration_format:
item["result"]["duration"] = int(item["result"]["duration"] * 1000000000)
if screenshot:
with open(screenshots_base_folder +screenshot_name+".png", "rb") as f:
base64_data = base64.b64encode(f.read()) # converted by base64
item["embeddings"]=[{"data":str(base64_data,"utf-8"),"mime_type": "image/png"}]
else:
# In behave, skipped tests doesn't have result object in their json, there-fore when we generating
# Cucumber report for every skipped test we need to generated a new result with status skipped
Expand Down
13 changes: 10 additions & 3 deletions behave2cucumber/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"long": [
"help", "debug=", "infile=", "outfile=", "remove-background",
"format-duration","deduplicate"
,"screenshot"
],
"descriptions": [
"Print help message",
Expand All @@ -37,6 +38,7 @@
"Remove background steps from output",
"Format the duration",
"Remove duplicate scenarios caused by @autoretry"
"screenshot"
]
}

Expand Down Expand Up @@ -87,6 +89,7 @@ def main(argv):
remove_background = False
duration_format = False
deduplicate = False
screenshot=False

for opt, arg in opts:
if opt in ("-i", "--infile"):
Expand All @@ -104,7 +107,10 @@ def main(argv):
if opt in ("-D", "--deduplicate"):
log.info("Deduplicate: Enabled")
deduplicate = True

if opt in ("-s", "--screenshot"):
log.info("screenshot: Enabled")
capture_screenshot = True

if infile is None:
log.critical("No input JSON provided.")
usage()
Expand All @@ -114,7 +120,8 @@ def main(argv):
cucumber_output = convert(json.load(f),
remove_background=remove_background,
duration_format=duration_format,
deduplicate=deduplicate)
deduplicate=deduplicate,
screenshot=screenshot)

if outfile is not None:
with open(outfile, 'w') as f:
Expand All @@ -131,4 +138,4 @@ def main(argv):
except EOFError:
sys.exit(0)
# except:
# sys.exit(0)
# sys.exit(0)