How to use press_right_arrow method in SeleniumBase

Best Python code snippet using SeleniumBase

sb_mkpres.py

Source:sb_mkpres.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Creates a new SeleniumBase presentation with boilerplate code.4Usage:5 seleniumbase mkpres [FILE.py] [LANG]6 or sbase mkpres [FILE.py] [LANG]7Example:8 sbase mkpres new_presentation.py --en9Language Options:10 --en / --English | --zh / --Chinese11 --nl / --Dutch | --fr / --French12 --it / --Italian | --ja / --Japanese13 --ko / --Korean | --pt / --Portuguese14 --ru / --Russian | --es / --Spanish15Output:16 Creates a new presentation with 3 example slides.17 If the file already exists, an error is raised.18 By default, the slides are written in English,19 and use "serif" theme with "slide" transition.20 The slides can be used as a basic boilerplate.21"""22import codecs23import colorama24import os25import sys26def invalid_run_command(msg=None):27 exp = " ** mkpres **\n\n"28 exp += " Usage:\n"29 exp += " seleniumbase mkpres [FILE.py] [LANG]\n"30 exp += " OR sbase mkpres [FILE.py] [LANG]\n"31 exp += " Example:\n"32 exp += " sbase mkpres new_presentation.py --en\n"33 exp += " Language Options:\n"34 exp += " --en / --English | --zh / --Chinese\n"35 exp += " --nl / --Dutch | --fr / --French\n"36 exp += " --it / --Italian | --ja / --Japanese\n"37 exp += " --ko / --Korean | --pt / --Portuguese\n"38 exp += " --ru / --Russian | --es / --Spanish\n"39 exp += " Output:\n"40 exp += " Creates a new presentation with 3 example slides.\n"41 exp += " If the file already exists, an error is raised.\n"42 exp += " By default, the slides are written in English,\n"43 exp += ' and use "serif" theme with "slide" transition.\n'44 exp += " The slides can be used as a basic boilerplate.\n"45 if not msg:46 raise Exception("INVALID RUN COMMAND!\n\n%s" % exp)47 elif msg == "help":48 print("\n%s" % exp)49 sys.exit()50 else:51 raise Exception("INVALID RUN COMMAND!\n\n%s\n%s\n" % (exp, msg))52def main():53 c1 = ""54 c5 = ""55 c7 = ""56 cr = ""57 if "linux" not in sys.platform:58 colorama.init(autoreset=True)59 c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX60 c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX61 c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA62 cr = colorama.Style.RESET_ALL63 help_me = False64 error_msg = None65 invalid_cmd = None66 language = "English"67 command_args = sys.argv[2:]68 file_name = command_args[0]69 if file_name == "-h" or file_name == "--help":70 invalid_run_command("help")71 elif not file_name.endswith(".py"):72 error_msg = 'File name must end with ".py"!'73 elif "*" in file_name or len(str(file_name)) < 4:74 error_msg = "Invalid file name!"75 elif file_name.startswith("-"):76 error_msg = 'File name cannot start with "-"!'77 elif "/" in str(file_name) or "\\" in str(file_name):78 error_msg = "File must be created in the current directory!"79 elif os.path.exists(os.getcwd() + "/" + file_name):80 error_msg = 'File "%s" already exists in this directory!' % file_name81 if error_msg:82 error_msg = c5 + "ERROR: " + error_msg + cr83 invalid_run_command(error_msg)84 if len(command_args) >= 2:85 options = command_args[1:]86 for option in options:87 option = option.lower()88 if option == "-h" or option == "--help":89 help_me = True90 elif option == "--en" or option == "--english":91 language = "English"92 elif option == "--zh" or option == "--chinese":93 language = "Chinese"94 elif option == "--nl" or option == "--dutch":95 language = "Dutch"96 elif option == "--fr" or option == "--french":97 language = "French"98 elif option == "--it" or option == "--italian":99 language = "Italian"100 elif option == "--ja" or option == "--japanese":101 language = "Japanese"102 elif option == "--ko" or option == "--korean":103 language = "Korean"104 elif option == "--pt" or option == "--portuguese":105 language = "Portuguese"106 elif option == "--ru" or option == "--russian":107 language = "Russian"108 elif option == "--es" or option == "--spanish":109 language = "Spanish"110 else:111 invalid_cmd = "\n===> INVALID OPTION: >> %s <<\n" % option112 invalid_cmd = invalid_cmd.replace(">> ", ">>" + c5 + " ")113 invalid_cmd = invalid_cmd.replace(" <<", " " + cr + "<<")114 invalid_cmd = invalid_cmd.replace(">>", c7 + ">>" + cr)115 invalid_cmd = invalid_cmd.replace("<<", c7 + "<<" + cr)116 help_me = True117 break118 if help_me:119 invalid_run_command(invalid_cmd)120 if language != "English" and sys.version_info[0] == 2:121 print("")122 msg = 'Multi-language support for "sbase mkpres" '123 msg += "is not available on Python 2!"124 msg = "\n" + c5 + msg + cr125 msg += '\nPlease run in "English" mode or upgrade to Python 3!\n'126 raise Exception(msg)127 dir_name = os.getcwd()128 file_path = "%s/%s" % (dir_name, file_name)129 html_name = file_name.replace(".py", ".html")130 hello = "Hello"131 press_right_arrow = "Press Right Arrow"132 add_text = "Add Text"133 goodbye = "Goodbye"134 class_name = "MyTestClass"135 if language == "Chinese":136 hello = "你好"137 press_right_arrow = "按向右箭头"138 add_text = "添加文本"139 goodbye = "再见"140 class_name = "我的测试类"141 elif language == "Dutch":142 hello = "Hallo"143 press_right_arrow = "Druk op pijl rechts"144 add_text = "Tekst Toevoegen"145 goodbye = "Dag"146 class_name = "MijnTestklasse"147 elif language == "French":148 hello = "Bonjour"149 press_right_arrow = "Appuyer sur flèche droite"150 add_text = "Ajouter Texte"151 goodbye = "Au revoir"152 class_name = "MaClasseDeTest"153 elif language == "Italian":154 hello = "Ciao"155 press_right_arrow = "Premere la freccia destra"156 add_text = "Aggiungi Testo"157 goodbye = "Addio"158 class_name = "MiaClasseDiTest"159 elif language == "Japanese":160 hello = "こんにちは"161 press_right_arrow = "右矢印を押します"162 add_text = "テキストを追加"163 goodbye = "さようなら"164 class_name = "私のテストクラス"165 elif language == "Korean":166 hello = "여보세요"167 press_right_arrow = "오른쪽 화살표를 누르십시오"168 add_text = "텍스트를 추가"169 goodbye = "안녕"170 class_name = "테스트_클래스"171 elif language == "Portuguese":172 hello = "Olá"173 press_right_arrow = "Pressione a seta direita"174 add_text = "Adicionar Texto"175 goodbye = "Tchau"176 class_name = "MinhaClasseDeTeste"177 elif language == "Russian":178 hello = "Привет"179 press_right_arrow = "Нажмите стрелку вправо"180 add_text = "Добавить Текст"181 goodbye = "До свидания"182 class_name = "МойТестовыйКласс"183 elif language == "Spanish":184 hello = "Hola"185 press_right_arrow = "Presione la flecha derecha"186 add_text = "Agregar Texto"187 goodbye = "Adiós"188 class_name = "MiClaseDePrueba"189 import_line = "from seleniumbase import BaseCase"190 parent_class = "BaseCase"191 class_line = "class MyTestClass(BaseCase):"192 if language != "English":193 from seleniumbase.translate.master_dict import MD_F194 import_line = MD_F.get_import_line(language)195 parent_class = MD_F.get_lang_parent_class(language)196 class_line = "class %s(%s):" % (class_name, parent_class)197 settings = 'theme="serif", transition="slide"'198 img_src_1 = 'src="https://seleniumbase.io/cdn/gif/chart_pres.gif"'199 img_src_2 = 'src="https://seleniumbase.io/cdn/img/sb_logo_10.png"'200 hello_page = (201 "\n '<h1>%s</h1><hr /><br />'"202 "\n '<p>%s</p>'"203 "" % (hello, press_right_arrow)204 )205 add_text_page = (206 "\n '<h2><b>*</b> %s <b>*</b></h2>'"207 "\n '<img %s>'"208 "" % (add_text, img_src_1)209 )210 goodbye_page = (211 "\n '<h2>%s</h2>'"212 "\n '<img %s>'"213 "" % (goodbye, img_src_2)214 )215 data = []216 data.append("%s" % import_line)217 data.append("")218 data.append("")219 data.append("%s" % class_line)220 data.append(" def test_presentation(self):")221 data.append(" self.create_presentation(%s)" % settings)222 data.append(" self.add_slide(%s)" % hello_page)223 data.append(" self.add_slide(%s)" % add_text_page)224 data.append(" self.add_slide(%s)" % goodbye_page)225 data.append(' self.begin_presentation(filename="%s")' % html_name)226 data.append("")227 new_data = []228 if language == "English":229 new_data = data230 else:231 from seleniumbase.translate.master_dict import MD232 from seleniumbase.translate.master_dict import MD_L_Codes233 md = MD.md234 lang_codes = MD_L_Codes.lang235 nl_code = lang_codes[language]236 dl_code = lang_codes["English"]237 for line in data:238 found_swap = False239 replace_count = line.count("self.") # Total possible replacements240 for key in md.keys():241 original = "self." + md[key][dl_code] + "("242 if original in line:243 replacement = "self." + md[key][nl_code] + "("244 new_line = line.replace(original, replacement)245 found_swap = True246 replace_count -= 1247 if replace_count == 0:248 break # Done making replacements249 else:250 # There might be another method to replace in the line.251 # Example: self.assert_true("Name" in self.get_title())252 line = new_line253 continue254 if found_swap:255 if new_line.endswith(" # noqa"): # Remove flake8 skip256 new_line = new_line[0 : -len(" # noqa")]257 new_data.append(new_line)258 continue259 new_data.append(line)260 data = new_data261 file = codecs.open(file_path, "w+", "utf-8")262 file.writelines("\r\n".join(data))263 file.close()264 if " " not in file_name:265 os.system("sbase print %s -n" % file_name)266 elif '"' not in file_name:267 os.system('sbase print "%s" -n' % file_name)268 else:269 os.system("sbase print '%s' -n" % file_name)270 success = (271 "\n" + c1 + '* Presentation: "' + file_name + '" was created! *'272 "" + cr + "\n"273 )274 print(success)275if __name__ == "__main__":...

Full Screen

Full Screen

script.py

Source:script.py Github

copy

Full Screen

...95 if is_curr_column_bad:96 # Switch columns.97 if curr_column == 0:98 # Go to right immediately.99 self.press_right_arrow()100 elif curr_column == 2:101 # Go left immediately.102 self.press_left_arrow()103 elif curr_column == 1:104 # Check other columns105 is_col0_bad = is_column_bad(all_cols[0])106 if is_col0_bad:107 # go right108 self.press_right_arrow()109 else:110 # go left111 self.press_left_arrow()112 else:113 # If current col is not bad, try to switch to a good col.114 if curr_column == 0:115 # Check mid col for bonus116 is_col1_good = is_column_good(all_cols[1])117 if is_col1_good:118 self.press_right_arrow()119 elif curr_column == 2:120 # Check mid col for bonus121 is_col1_good = is_column_good(all_cols[1])122 if is_col1_good:123 self.press_left_arrow()124 elif curr_column == 1:125 # Check both cols for good stuff, do left one first.126 # Check left.127 is_col0_good = is_column_good(all_cols[0])128 if is_col0_good:129 self.press_left_arrow()130 # Check right.131 is_col2_good = is_column_good(all_cols[2])132 if is_col2_good:133 self.press_right_arrow()134 def press_left_arrow(self):135 """136 Simulate left arrow key press137 Update column state and last move time.138 """139 self.keyboard.press(Key.left)140 self.curr_column = self.curr_column - 1141 self.last_move = time.time()142 print('col:', self.curr_column) # output current col state.143 def press_right_arrow(self):144 """145 Simulate right arrow key press.146 Update column state and last move time.147 """148 self.keyboard.press(Key.right)149 self.curr_column = self.curr_column + 1150 self.last_move = time.time()151 print('col:', self.curr_column) # output current col state.152if __name__ == '__main__':153 bot = Bot()...

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 SeleniumBase 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