Best Python code snippet using Airtest
code_plugin.py
Source:code_plugin.py
...5 page.get_page().SelectAll()6class ExecFile(IDEPlugin):7 name = 'Run File'8 def run(self, app, page, console, workspace, catlog, para):9 console, page = console.get_console(), page.get_page()10 console.write("execfile('%s')\n"%page.code.path.replace('\\','/'))11 console.pc.write("execfile('%s')"%page.code.path.replace('\\','/'))12class Debug(IDEPlugin):13 name = 'Debug'14 def run(self, app, page, console, workspace, catlog, para):15 console, page = console.get_console(), page.get_page()16 console.write("debug('%s')\n"%page.code.path.replace('\\','/'))17 console.pc.write("debug('%s')"%page.code.path.replace('\\','/'))18 console.debug('breakpoint', [])19 page.highlight_line(1)20 workspace.on_fresh(None)21class DebugContinue(IDEPlugin):22 name = 'Continue'23 def run(self, app, page, console, workspace, catlog, para):24 console, page = console.get_console(), page.get_page()25 info, status = console.debug('action', ':c')26 page.highlight_line(info['no'])27 workspace.on_fresh(None)28class DebugNext(IDEPlugin):29 name = 'Next'30 def run(self, app, page, console, workspace, catlog, para):31 console, page = console.get_console(), page.get_page()32 info, status = console.debug('action', ':n')33 page.highlight_line(info['no'])34 workspace.on_fresh(None)35class DebugInto(IDEPlugin):36 name = 'Step Into'37 def run(self, app, page, console, workspace, catlog, para):38 console, page = console.get_console(), page.get_page()39 info, status = console.debug('action', ':s')40 page.highlight_line(info['no'])41 workspace.on_fresh(None)42class DebugOut(IDEPlugin):43 name = 'Step Out'44 def run(self, app, page, console, workspace, catlog, para):45 console, page = console.get_console(), page.get_page()46 info, status = console.debug('action', ':r')47 page.highlight_line(info['no'])48 workspace.on_fresh(None)49class DebugStop(IDEPlugin):50 name = 'Debug Stop'51 def run(self, app, page, console, workspace, catlog, para):52 console, page = console.get_console(), page.get_page()53 info, status = console.debug('action', ':q')54 page.highlight_line(info['no'])55 workspace.on_fresh(None)56'''57 def on_debug(self, event):58 console = self.console.get_console()59 console.write("debug('./debug/test.py')\n")60 console.pc.write("debug('./debug/test.py')")61 console.debug('breakpoint', [('./debug/test.py', 8)])62 self.page.SetSelection(self.page.PositionFromLine(0), self.page.GetLineEndPosition(0))63 self.workspace.on_fresh(None)64 def on_next(self, event):65 info, status = self.console.get_console().debug('action', ':n')66 self.page.SetSelection(self.page.PositionFromLine(info['no']-1), self.page.GetLineEndPosition(info['no']-1))67 self.workspace.on_fresh(None)68 def on_step(self, event):69 info, status = self.console.get_console().debug('action', ':s')70 if status: self.page.SetSelection(71 self.page.PositionFromLine(info['no']-1), self.page.GetLineEndPosition(info['no']-1))72 self.workspace.on_fresh(None)73 def on_return(self, event):74 info, status = self.console.get_console().debug('action', ':r')75 if status: self.page.SetSelection(76 self.page.PositionFromLine(info['no']-1), self.page.GetLineEndPosition(info['no']-1))77 self.workspace.on_fresh(None)78 def on_continue(self, event):79 info, status = self.console.get_console().debug('action', ':c')80 if status: self.page.SetSelection(81 self.page.PositionFromLine(info['no']-1), self.page.GetLineEndPosition(info['no']-1))82 self.workspace.on_fresh(None)83 def on_stop(self, event):84 info, status = self.console.get_console().debug('action', ':q')85 if status: self.page.SetSelection(86 self.page.PositionFromLine(info['no']-1), self.page.GetLineEndPosition(info['no']-1))87 self.workspace.on_fresh(None)...
consoles.py
Source:consoles.py
1import configparser2#from selenium import webdriver3from time import sleep4from webbot import Browser56consoles = {7 "ps5": "https://www.walmart.com/ip/PlayStation-5-Console/363472942",8 "ps5_digital": "https://www.walmart.com/ip/Sony-PlayStation-5-Digital-Edition/493824815",9 "xbox": "https://www.walmart.com/ip/XB1-Xbox-Series-X/443574645"10}1112retailers = {13 "wm_home": "https://www.walmart.com/",14}1516class WMProcess():17 """18 Walmart login credentials/process19 """20 def __init__(self):21 config = configparser.ConfigParser()22 config.read("../configs/credentials.conf")23 #setup login and site information24 self.username = config['creds']['username']25 self.pw = config['creds']['pw']26 self.site = retailers['wm_home']27 self.ps5 = consoles['ps5']28 self.ps5_digital = consoles['ps5_digital']29 self.xbox = consoles['xbox']30 self.web = Browser()3132 def open_browser(self):33 #gc = webdriver.Chrome(r"../configs/drivers/chromedriver_win32/chromedriver.exe")34 #gc.get(self.site)35 self.web.go_to(self.site)36 sleep(2)373839 def login(self):40 self.web.click('Account')41 self.web.click('Sign In')42 self.web.type(self.username, into='email')43 self.web.type(self.pw, into='password')44 self.web.click('Sign In')45 #change this line below for ps5, ps5_base, or xbox46 self.web.go_to(self.ps5)4748 def add_to_cart(self):49 self.web.click('Add to cart')5051 def checkout(self):52 self.web.click('Check out')5354 def delivery(self):55 self.web.click('Continue')56 sleep(1)575859 def confirm_address(self):60 self.web.click('Continue')6162 def select_payment(self):63 self.web.click('Continue')6465 def review_order(self):66 self.web.click('Review your order')6768 def place_order(self):69 self.web.click('Place order')7071 def main(self):72 self.open_browser()737475if __name__ == '__main__':76 get_console = WMProcess()77 get_console.open_browser()78 get_console.login()79 get_console.add_to_cart()80 get_console.checkout()81 get_console.delivery()82 get_console.confirm_address()83 get_console.select_payment()84 get_console.review_order()85 get_console.place_order
...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!