How to use proposed_definitions method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

colored_shell_output.py

Source:colored_shell_output.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# <Lettuce - Behaviour Driven Development for python>3# Copyright (C) <2010-2011> Gabriel Falcão <gabriel@nacaolivre.org>4#5# This program is free software: you can redistribute it and/or modify6# it under the terms of the GNU General Public License as published by7# the Free Software Foundation, either version 3 of the License, or8# (at your option) any later version.9#10# This program is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU General Public License for more details.14#15# You should have received a copy of the GNU General Public License16# along with this program. If not, see <http://www.gnu.org/licenses/>.17import os18import re19import sys20from lettuce import core21from lettuce import strings22from lettuce import terminal23from lettuce.terrain import after24from lettuce.terrain import before25def wrt(what):26 sys.stdout.write(what.encode('utf-8'))27def wrap_file_and_line(string, start, end):28 return re.sub(r'([#] [^:]+[:]\d+)', '%s\g<1>%s' % (start, end), string)29def wp(l):30 if l.startswith("\033[1;32m"):31 l = l.replace(" |", "\033[1;37m |\033[1;32m")32 if l.startswith("\033[1;36m"):33 l = l.replace(" |", "\033[1;37m |\033[1;36m")34 if l.startswith("\033[0;36m"):35 l = l.replace(" |", "\033[1;37m |\033[0;36m")36 if l.startswith("\033[0;31m"):37 l = l.replace(" |", "\033[1;37m |\033[0;31m")38 if l.startswith("\033[1;30m"):39 l = l.replace(" |", "\033[1;37m |\033[1;30m")40 return l41def write_out(what):42 wrt(wp(what))43@before.each_step44def print_step_running(step):45 if not step.defined_at:46 return47 color = '\033[1;30m'48 if step.scenario.outlines:49 color = '\033[0;36m'50 string = step.represent_string(step.original_sentence)51 string = wrap_file_and_line(string, '\033[1;30m', '\033[0m')52 write_out("%s%s" % (color, string))53 if step.hashes and step.defined_at:54 for line in step.represent_hashes().splitlines():55 write_out("\033[1;30m%s\033[0m\n" % line)56@after.each_step57def print_step_ran(step):58 if step.scenario.outlines:59 return60 if step.hashes and step.defined_at:61 write_out("\033[A" * (len(step.hashes) + 1))62 string = step.represent_string(step.original_sentence)63 if not step.failed:64 string = wrap_file_and_line(string, '\033[1;30m', '\033[0m')65 prefix = '\033[A'66 width, height = terminal.get_size()67 lines_up = len(string) / float(width)68 if lines_up < 1:69 lines_up = 170 else:71 lines_up = int(lines_up) + 172 #prefix = prefix * lines_up73 if step.failed:74 color = "\033[0;31m"75 string = wrap_file_and_line(string, '\033[1;41;33m', '\033[0m')76 elif step.passed:77 color = "\033[1;32m"78 elif step.defined_at:79 color = "\033[0;36m"80 else:81 color = "\033[0;33m"82 prefix = ""83 write_out("%s%s%s" % (prefix, color, string))84 if step.hashes:85 for line in step.represent_hashes().splitlines():86 write_out("%s%s\033[0m\n" % (color, line))87 if step.failed:88 wrt("\033[1;31m")89 pspaced = lambda x: wrt("%s%s" % (" " * step.indentation, x))90 lines = step.why.traceback.splitlines()91 for pindex, line in enumerate(lines):92 pspaced(line)93 if pindex + 1 < len(lines):94 wrt("\n")95 wrt("\033[0m\n")96@before.each_scenario97def print_scenario_running(scenario):98 string = scenario.represented()99 string = wrap_file_and_line(string, '\033[1;30m', '\033[0m')100 write_out("\n\033[1;37m%s" % string)101@after.outline102def print_outline(scenario, order, outline, reasons_to_fail):103 table = strings.dicts_to_string(scenario.outlines, scenario.keys)104 lines = table.splitlines()105 head = lines.pop(0)106 wline = lambda x: write_out("\033[0;36m%s%s\033[0m\n" % (" " * scenario.table_indentation, x))107 wline_success = lambda x: write_out("\033[1;32m%s%s\033[0m\n" % (" " * scenario.table_indentation, x))108 wline_red = lambda x: wrt("%s%s" % (" " * scenario.table_indentation, x))109 if order is 0:110 wrt("\n")111 wrt("\033[1;37m%s%s:\033[0m\n" % (" " * scenario.indentation, scenario.language.first_of_examples))112 wline(head)113 line = lines[order]114 wline_success(line)115 if reasons_to_fail:116 elines = reasons_to_fail[0].traceback.splitlines()117 wrt("\033[1;31m")118 for pindex, line in enumerate(elines):119 wline_red(line)120 if pindex + 1 < len(elines):121 wrt("\n")122 wrt("\033[0m\n")123@before.each_feature124def print_feature_running(feature):125 string = feature.represented()126 lines = string.splitlines()127 write_out("\n")128 for line in lines:129 line = wrap_file_and_line(line, '\033[1;30m', '\033[0m')130 write_out("\033[1;37m%s\n" % line)131@after.all132def print_end(total):133 write_out("\n")134 word = total.features_ran > 1 and "features" or "feature"135 color = "\033[1;32m"136 if total.features_passed is 0:137 color = "\033[0;31m"138 write_out("\033[1;37m%d %s (%s%d passed\033[1;37m)\033[0m\n" % (139 total.features_ran,140 word,141 color,142 total.features_passed))143 color = "\033[1;32m"144 if total.scenarios_passed is 0:145 color = "\033[0;31m"146 word = total.scenarios_ran > 1 and "scenarios" or "scenario"147 write_out("\033[1;37m%d %s (%s%d passed\033[1;37m)\033[0m\n" % (148 total.scenarios_ran,149 word,150 color,151 total.scenarios_passed))152 steps_details = []153 kinds_and_colors = {154 'failed': '\033[0;31m',155 'skipped': '\033[0;36m',156 'undefined': '\033[0;33m'157 }158 for kind, color in kinds_and_colors.items():159 attr = 'steps_%s' % kind160 stotal = getattr(total, attr)161 if stotal:162 steps_details.append("%s%d %s" % (color, stotal, kind))163 steps_details.append("\033[1;32m%d passed\033[1;37m" % total.steps_passed)164 word = total.steps > 1 and "steps" or "step"165 content = "\033[1;37m, ".join(steps_details)166 word = total.steps > 1 and "steps" or "step"167 write_out("\033[1;37m%d %s (%s)\033[0m\n" % (168 total.steps,169 word,170 content))171 if total.proposed_definitions:172 wrt("\n\033[0;33mYou can implement step definitions for undefined steps with these snippets:\n\n")173 wrt("# -*- coding: utf-8 -*-\n")174 wrt("from lettuce import step\n\n")175 last = len(total.proposed_definitions) - 1176 for current, step in enumerate(total.proposed_definitions):177 method_name = step.proposed_method_name178 wrt("@step(u'%s')\n" % step.proposed_sentence)179 wrt("def %s:\n" % method_name)180 wrt(" assert False, 'This step must be implemented'")181 if current is last:182 wrt("\033[0m")183 wrt("\n")184def print_no_features_found(where):185 where = core.fs.relpath(where)186 if not where.startswith(os.sep):187 where = '.%s%s' % (os.sep, where)188 write_out('\033[1;31mOops!\033[0m\n')189 write_out(190 '\033[1;37mcould not find features at '...

Full Screen

Full Screen

shell_output.py

Source:shell_output.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# <Lettuce - Behaviour Driven Development for python>3# Copyright (C) <2010-2011> Gabriel Falcão <gabriel@nacaolivre.org>4#5# This program is free software: you can redistribute it and/or modify6# it under the terms of the GNU General Public License as published by7# the Free Software Foundation, either version 3 of the License, or8# (at your option) any later version.9#10# This program is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERsteps.pyCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU General Public License for more details.14#15# You should have received a copy of the GNU General Public License16# along with this program. If not, see <http://www.gnu.org/licenses/>.17import os18import sys19from lettuce import core20from lettuce import strings21from lettuce.terrain import after22from lettuce.terrain import before23def wrt(what):24 sys.stdout.write(what.encode('utf-8'))25@after.each_step26def print_step_running(step):27 wrt(step.represent_string(step.original_sentence).rstrip())28 if not step.defined_at:29 wrt(" (undefined)")30 wrt('\n')31 if step.hashes:32 wrt(step.represent_hashes())33 if step.failed:34 print_spaced = lambda x: wrt("%s%s\n" % (" " * step.indentation, x))35 for line in step.why.traceback.splitlines():36 print_spaced(line)37@before.each_scenario38def print_scenario_running(scenario):39 wrt('\n')40 wrt(scenario.represented())41@after.outline42def print_outline(scenario, order, outline, reasons_to_fail):43 table = strings.dicts_to_string(scenario.outlines, scenario.keys)44 lines = table.splitlines()45 head = lines.pop(0)46 wline = lambda x: wrt("%s%s\n" % (" " * scenario.table_indentation, x))47 if order is 0:48 wrt("\n")49 wrt("%s%s:\n" % (" " * scenario.indentation, scenario.language.first_of_examples))50 wline(head)51 line = lines[order]52 wline(line)53 if reasons_to_fail:54 print_spaced = lambda x: wrt("%s%s\n" % (" " * scenario.table_indentation, x))55 elines = reasons_to_fail[0].traceback.splitlines()56 for line in elines:57 print_spaced(line)58@before.each_feature59def print_feature_running(feature):60 wrt("\n")61 wrt(feature.represented())62@after.all63def print_end(total):64 wrt("\n")65 word = total.features_ran > 1 and "features" or "feature"66 wrt("%d %s (%d passed)\n" % (67 total.features_ran,68 word,69 total.features_passed))70 word = total.scenarios_ran > 1 and "scenarios" or "scenario"71 wrt("%d %s (%d passed)\n" % (72 total.scenarios_ran,73 word,74 total.scenarios_passed))75 steps_details = []76 for kind in ("failed","skipped", "undefined"):77 attr = 'steps_%s' % kind78 stotal = getattr(total, attr)79 if stotal:80 steps_details.append("%d %s" % (stotal, kind))81 steps_details.append("%d passed" % total.steps_passed)82 word = total.steps > 1 and "steps" or "step"83 wrt("%d %s (%s)\n" % (84 total.steps,85 word,86 ", ".join(steps_details)))87 if total.proposed_definitions:88 wrt("\nYou can implement step definitions for undefined steps with these snippets:\n\n")89 wrt("# -*- coding: utf-8 -*-\n")90 wrt("from lettuce import step\n\n")91 for step in total.proposed_definitions:92 method_name = step.proposed_method_name93 wrt("@step(u'%s')\n" % step.proposed_sentence)94 wrt("def %s:\n" % method_name)95 wrt(" assert False, 'This step must be implemented'\n")96def print_no_features_found(where):97 where = core.fs.relpath(where)98 if not where.startswith(os.sep):99 where = '.%s%s' % (os.sep, where)100 wrt('Oops!\n')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lettuce_webdriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful