Best Python code snippet using SeleniumBase
formula_creation.py
Source:formula_creation.py
...16 btn_submit.grid(row=6, column=4, padx=2, pady=5, columnspan=3)17 # icon buttons (might need to change / to \ to work with different OS)18 # used, constant format, all are similar structure, grabbing icons from path and calling a function to display string19 blank_power = PhotoImage(file=r"gui/icons/blank_power.png")20 btn_blank_power = Button(self, relief=RAISED, image=blank_power, command=lambda: self.update_text(21 "()^()"))22 btn_blank_power.image = blank_power23 btn_blank_power.grid(row=1, column=0, padx=2, pady=5)24 blank_root = PhotoImage(file=r"gui/icons/blank_root.png")25 btn_blank_root = Button(self, relief=RAISED, image=blank_root, command=lambda: self.update_text("()root()"))26 btn_blank_root.image = blank_root27 btn_blank_root.grid(row=1, column=1, padx=2, pady=5)28 natural_log = PhotoImage(file=r"gui\icons\natural_log.png")29 btn_natural_log = Button(self, relief=RAISED, image=natural_log, command=lambda: self.update_text("ln()"))30 btn_natural_log.image = natural_log31 btn_natural_log.grid(row=1, column=2, padx=2, pady=5)32 left_bracket = PhotoImage(file=r"gui/icons/left_bracket.png")33 btn_left_bracket = Button(self, relief=RAISED, image=left_bracket, command=lambda: self.update_text("("))34 btn_left_bracket.image = left_bracket35 btn_left_bracket.grid(row=2, column=1, padx=2, pady=5)36 right_bracket = PhotoImage(file=r"gui/icons/right_bracket.png")37 btn_right_bracket = Button(self, relief=RAISED, image=right_bracket, command=lambda: self.update_text(")"))38 btn_right_bracket.image = right_bracket39 btn_right_bracket.grid(row=2, column=2, padx=2, pady=5)40 multiplication = PhotoImage(file=r"gui/icons/multiplication.png")41 btn_multiplication = Button(self, relief=RAISED, image=multiplication, command=lambda: self.update_text("*"))42 btn_multiplication.image = multiplication43 btn_multiplication.grid(row=3, column=2, padx=2, pady=5)44 sin = PhotoImage(file=r"gui/icons/sin.png")45 btn_sin = Button(self, relief=RAISED, image=sin, command=lambda: self.update_text("sine()"))46 btn_sin.image = sin47 btn_sin.grid(row=4, column=0, padx=2, pady=5)48 cos = PhotoImage(file=r"gui/icons/cos.png")49 btn_cos = Button(self, relief=RAISED, image=cos, command=lambda: self.update_text("cosine()"))50 btn_cos.image = cos51 btn_cos.grid(row=4, column=1, padx=2, pady=5)52 tan = PhotoImage(file=r"gui/icons/tan.png")53 btn_tan = Button(self, relief=RAISED, image=tan, command=lambda: self.update_text("tan(tanget"))54 btn_tan.image = tan55 btn_tan.grid(row=4, column=2, padx=2, pady=5)56 variable_a = PhotoImage(file=r"gui/icons/variable_a.png")57 btn_variable_a = Button(self, relief=RAISED, image=variable_a, command=lambda: self.update_text("A"))58 btn_variable_a.image = variable_a59 btn_variable_a.grid(row=1, column=3, padx=2, pady=5)60 variable_b = PhotoImage(file=r"gui/icons/variable_b.png")61 btn_variable_b = Button(self, relief=RAISED, image=variable_b, command=lambda: self.update_text("B"))62 btn_variable_b.image = variable_b63 btn_variable_b.grid(row=1, column=4, padx=2, pady=5)64 variable_c = PhotoImage(file=r"gui/icons/variable_c.png")65 btn_variable_c = Button(self, relief=RAISED, image=variable_c, command=lambda: self.update_text("C"))66 btn_variable_c.image = variable_c67 btn_variable_c.grid(row=2, column=3, padx=2, pady=5)68 variable_d = PhotoImage(file=r"gui/icons/variable_d.png")69 btn_variable_d = Button(self, relief=RAISED, image=variable_d, command=lambda: self.update_text("D"))70 btn_variable_d.image = variable_d71 btn_variable_d.grid(row=2, column=4, padx=2, pady=5)72 variable_e = PhotoImage(file=r"gui/icons/variable_e.png")73 btn_variable_e = Button(self, relief=RAISED, image=variable_e, command=lambda: self.update_text("E"))74 btn_variable_e.image = variable_e75 btn_variable_e.grid(row=3, column=3, padx=2, pady=5)76 division = PhotoImage(file=r"gui/icons/division.png")77 btn_divison = Button(self, relief=RAISED, image=division, command=lambda: self.update_text("/"))78 btn_divison.image = division79 btn_divison.grid(row=3, column=1, padx=2, pady=5)80 arc_sin = PhotoImage(file=r"gui/icons/arc_sin.png")81 btn_arc_sin = Button(self, relief=RAISED, image=arc_sin, command=lambda: self.update_text("arcsin()"))82 btn_arc_sin.image = arc_sin83 btn_arc_sin.grid(row=5, column=0, padx=2, pady=5)84 arc_cos = PhotoImage(file=r"gui/icons/arc_cos.png")85 btn_arc_cos = Button(self, relief=RAISED, image=arc_cos, command=lambda: self.update_text("arccos()"))86 btn_arc_cos.image = arc_cos87 btn_arc_cos.grid(row=5, column=1, padx=2, pady=5)88 arc_tan = PhotoImage(file=r"gui/icons/arc_tan.png")89 btn_arc_tan = Button(self, relief=RAISED, image=arc_tan, command=lambda: self.update_text("arctan()"))90 btn_arc_tan.image = arc_tan91 btn_arc_tan.grid(row=5, column=2, padx=2, pady=5)92 variable_f = PhotoImage(file=r"gui/icons/variable_f.png")93 btn_variable_f = Button(self, relief=RAISED, image=variable_f, command=lambda: self.update_text("F"))94 btn_variable_f.image = variable_f95 btn_variable_f.grid(row=3, column=4, padx=2, pady=5)96 variable_g = PhotoImage(file=r"gui/icons/variable_g.png")97 btn_variable_g = Button(self, relief=RAISED, image=variable_g, command=lambda: self.update_text("G"))98 btn_variable_g.image = variable_g99 btn_variable_g.grid(row=4, column=3, padx=2, pady=5)100 variable_h = PhotoImage(file=r"gui/icons/variable_h.png")101 btn_variable_h = Button(self, relief=RAISED, image=variable_h, command=lambda: self.update_text("H"))102 btn_variable_h.image = variable_h103 btn_variable_h.grid(row=4, column=4, padx=2, pady=5)104 variable_i = PhotoImage(file=r"gui/icons/variable_i.png")105 btn_variable_i = Button(self, relief=RAISED, image=variable_i, command=lambda: self.update_text("I"))106 btn_variable_i.image = variable_i107 btn_variable_i.grid(row=5, column=3, padx=2, pady=5)108 variable_j = PhotoImage(file=r"gui/icons/variable_j.png")109 btn_variable_j = Button(self, relief=RAISED, image=variable_j, command=lambda: self.update_text("J"))110 btn_variable_j.image = variable_j111 btn_variable_j.grid(row=5, column=4, padx=2, pady=5)112 subtraction = PhotoImage(file=r"gui/icons/subtraction.png")113 btn_subtraction = Button(self, relief=RAISED, image=subtraction, command=lambda: self.update_text("-"))114 btn_subtraction.image = subtraction115 btn_subtraction.grid(row=3, column=0, padx=2, pady=5)116 num0 = PhotoImage(file=r"gui/icons/num0.png")117 btn_num0 = Button(self, relief=RAISED, image=num0, command=lambda: self.update_text("0"))118 btn_num0.image = num0119 btn_num0.grid(row=1, column=5, padx=2, pady=5)120 num1 = PhotoImage(file=r"gui/icons/num1.png")121 btn_num1 = Button(self, relief=RAISED, image=num1, command=lambda: self.update_text("1"))122 btn_num1.image = num1123 btn_num1.grid(row=1, column=6, padx=2, pady=5)124 num2 = PhotoImage(file=r"gui/icons/num2.png")125 btn_num2 = Button(self, relief=RAISED, image=num2, command=lambda: self.update_text("2"))126 btn_num2.image = num2127 btn_num2.grid(row=2, column=5, padx=2, pady=5)128 num3 = PhotoImage(file=r"gui/icons/num3.png")129 btn_num3 = Button(self, relief=RAISED, image=num3, command=lambda: self.update_text("3"))130 btn_num3.image = num3131 btn_num3.grid(row=2, column=6, padx=2, pady=5)132 num4 = PhotoImage(file=r"gui/icons/num4.png")133 btn_num4 = Button(self, relief=RAISED, image=num4, command=lambda: self.update_text("4"))134 btn_num4.image = num4135 btn_num4.grid(row=3, column=5, padx=2, pady=5)136 num5 = PhotoImage(file=r"gui/icons/num5.png")137 btn_num5 = Button(self, relief=RAISED, image=num5, command=lambda: self.update_text("5"))138 btn_num5.image = num5139 btn_num5.grid(row=3, column=6, padx=2, pady=5)140 num6 = PhotoImage(file=r"gui/icons/num6.png")141 btn_num6 = Button(self, relief=RAISED, image=num6, command=lambda: self.update_text("6"))142 btn_num6.image = num6143 btn_num6.grid(row=4, column=6, padx=2, pady=5)144 num7 = PhotoImage(file=r"gui/icons/num7.png")145 btn_num7 = Button(self, relief=RAISED, image=num7, command=lambda: self.update_text("7"))146 btn_num7.image = num7147 btn_num7.grid(row=4, column=5, padx=2, pady=5)148 num8 = PhotoImage(file=r"gui/icons/num8.png")149 btn_num8 = Button(self, relief=RAISED, image=num8, command=lambda: self.update_text("8"))150 btn_num8.image = num8151 btn_num8.grid(row=5, column=5, padx=2, pady=5)152 num9 = PhotoImage(file=r"gui/icons/num9.png")153 btn_num9 = Button(self, relief=RAISED, image=num9, command=lambda: self.update_text("9"))154 btn_num9.image = num9155 btn_num9.grid(row=5, column=6, padx=2, pady=5)156 addition = PhotoImage(file=r"gui/icons/addition.png")157 btn_addition = Button(self, relief=RAISED, image=addition, command=lambda: self.update_text("+"))158 btn_addition.image = addition159 btn_addition.grid(row=2, column=0, padx=2, pady=5)160 ## unused161 # square_root = PhotoImage(file=r"gui/icons/square_root.png")162 # btn_square_root = Button(self, relief=RAISED, image=square_root, command=lambda: self.update_text("sqrt()"))163 # btn_square_root.image = square_root164 # btn_square_root.grid(row=1, column=1, padx=2, pady=5)165 # e_to_the_power = PhotoImage(file=r"gui\icons\e_to_the_power.png")166 # btn_e_to_the_power = Button(self, relief=RAISED, image=e_to_the_power, command=lambda: self.update_text("e^()"))167 # btn_e_to_the_power.image = e_to_the_power168 # btn_e_to_the_power.grid(row=1, column=2, padx=2, pady=5)169 #170 #171 # blank_base_log = PhotoImage(file=r"gui\icons\blank_base_log.png")172 # btn_blank_base_log = Button(self, relief=RAISED, image=blank_base_log, command=lambda: self.update_text("log[]()"))173 # btn_blank_base_log.image = blank_base_log174 # btn_blank_base_log.grid(row=1, column=4, padx=2, pady=5)175 #176 # cube_root = PhotoImage(file=r"gui\icons\cube_root.png")177 # btn_cube_root = Button(self, relief=RAISED, image=cube_root, command=lambda: self.update_text("cube_root()"))178 # btn_cube_root.image = cube_root179 # btn_cube_root.grid(row=1, column=6, padx=2, pady=5)180 #181 # fraction = PhotoImage(file=r"gui\icons\fraction.png")182 # btn_fraction = Button(self, relief=RAISED, image=fraction, command=lambda: self.update_text("()/()"))183 # btn_fraction.image = fraction184 # btn_fraction.grid(row=2, column=3, padx=2, pady=5)185 #186 # array5 = PhotoImage(file=r"gui\icons\array5.png")187 # btn_array5 = Button(self, relief=RAISED, image=array5, command=lambda: self.update_text("sum5()"))188 # btn_array5.image = array5189 # btn_array5.grid(row=2, column=4, padx=2, pady=5)190 #191 # array10 = PhotoImage(file=r"gui\icons\array10.png")192 # btn_array10 = Button(self, relief=RAISED, image=array10, command=lambda: self.update_text("sum10()"))193 # btn_array10.image = array10194 # btn_array10.grid(row=3, column=3, padx=2, pady=5)195 #196 # array15 = PhotoImage(file=r"gui\icons\array15.png")197 # btn_array15 = Button(self, relief=RAISED, image=array15, command=lambda: self.update_text("sum15()"))198 # btn_array15.image = array15199 # btn_array15.grid(row=3, column=4, padx=2, pady=5)200 #201 # squaring = PhotoImage(file=r"gui\icons\squaring.png")202 # btn_squaring = Button(self, relief=RAISED, image=squaring, command=lambda: self.update_text("^2"))203 # btn_squaring.image = squaring204 # btn_squaring.grid(row=1, column=0, padx=2, pady=5)205 def update_text(self, btn_text): # updates formula textbox206 # print(btn_text) # prints the pressed 'key' in the console207 # idx = self.text_item_desc.curselection() # failed attempt at cur selection to make inputs appear where cursor is208 self.text_item_desc.insert(END, btn_text)209 def help_box(self): # focuses on helpbox210 help_box = Toplevel() # parent class211 text_item_desc = Text(help_box, width=85, height=10, bg="grey50") # config212 text_item_desc.insert(END, 'This is a help box: \n' # actual help text213 'Trig functions operate in the format of <cosine(A*B)> \n'214 'The four base operations work on a <X*Y> basis \n'215 'Logarithms operate as taking the natural log <ln> of the variable assigned to it \n'216 'The order of operation is a very sensitive system due to RPN being used to '217 'evaluate \n'218 'Use additional brackets if a formula that should be valid does not work correctly \n'219 'It is advised you keep this on the side as a reminder until you shutdown the '...
deployment.py
Source:deployment.py
...18 updates.config(yscrollcommand=scroll.set)19 updates.insert(tk.END, "Press 'Deploy' button to start the deployment.\n")20 updates.configure(state='disabled')21 # Function22 def update_text(text):23 updates.configure(state='normal')24 updates.insert(tk.END,text+'\n')25 updates.configure(state='disabled')26 self.update()27 def deploy_cluster():28 deploy.config(state='disabled') # Don't allow to press the button again. Would cause problems.29 # Load configuration30 with open('.config/config.json', 'r') as openfile:31 config_json = json.load(openfile)32 if not(config_json['create_cluster']):33 kubeconfig_file = config_json['kubeconfig_path']34 if config_json['context'] != "": # Add context35 kubeconfig_file = kubeconfig_file+f" {config_json['context']}"36 37 38 if config_json['create_cluster']:39 update_text('Starting with the cluster creation...')40 update_text('Initializing terraform...')41 42 if config_json['provider'] == 'azure':43 update_text('Creating cluster on Azure (This can take up to 10 minutes)...')44 os.system(f"sh scripts/terraform_azure.sh {config_json['subscription_id']} {config_json['tenant_id']} {config_json['client_id']} {config_json['client_secret']}")45 kubeconfig_file = 'terraform/azure_terraform/kubeconfig'46 else:47 update_text('Creating cluster on Google Cloud (This can take up to 10 minutes)...')48 os.system(f"sh scripts/terraform_google.sh {config_json['project_id']} {config_json['region']} {config_json['google_key']}")49 kubeconfig_file = 'terraform/google_terraform/kubeconfig'50 51 update_text('The cluster has been created.')52 53 update_text(' ')54 update_text('Starting with the deployment...')55 update_text('Adding configuration files...')56 # Add configuration files57 os.system(f"sh scripts/k8s_config.sh {kubeconfig_file}")58 update_text('Configuration files added.')59 # Deploy database60 if config_json['cluster_db']:61 update_text('Deploying database cluster...')62 os.system(f"sh scripts/k8s_cluster_db.sh {kubeconfig_file}")63 update_text('Database cluster deployed.')64 else:65 update_text('Deploying database...')66 os.system(f"sh scripts/k8s_simple_db.sh {kubeconfig_file}")67 update_text('Database deployed.')68 69 # Deploy core services70 update_text('Deploying core services...')71 os.system(f"sh scripts/k8s_core.sh {kubeconfig_file}")72 update_text('Core services deployed.')73 # Deploy optional services74 services = config_json['services']75 if services[1]==1:76 os.system(f"sh scripts/k8s_optional.sh gateway {kubeconfig_file}")77 elif services[2]==1:78 os.system(f"sh scripts/k8s_optional.sh gatekeeper {kubeconfig_file}")79 elif services[3]==1:80 os.system(f"sh scripts/k8s_optional.sh eventhandler {kubeconfig_file}")81 # Update services replicas82 replicas = config_json['replicas']83 if replicas[0]>1:84 os.system(f"sh scripts/k8s_scale.sh sr-deployment {replicas[0]} {kubeconfig_file}")85 elif replicas[1]>1:86 os.system(f"sh scripts/k8s_scale.sh orch-deployment {replicas[1]} {kubeconfig_file}")87 elif replicas[2]>1:88 os.system(f"sh scripts/k8s_scale.sh auth-deployment {replicas[2]} {kubeconfig_file}")89 elif replicas[4]>1:90 os.system(f"sh scripts/k8s_scale.sh gw-deployment {replicas[4]} {kubeconfig_file}")91 elif replicas[5]>1:92 os.system(f"sh scripts/k8s_scale.sh gk-deployment {replicas[5]} {kubeconfig_file}")93 elif replicas[6]>1:94 os.system(f"sh scripts/k8s_scale.sh eh-deployment {replicas[6]} {kubeconfig_file}")95 # Deploy ambassador96 # Ambassador97 update_text('Configuring network to expose services...')98 os.system(f"sh scripts/k8s_ambassador.sh {kubeconfig_file}")99 if services[1]==1:100 os.system(f"sh scripts/k8s_ambassador_optional.sh gateway {kubeconfig_file}")101 elif services[2]==1:102 os.system(f"sh scripts/k8s_ambassador_optional.sh gatekeeper {kubeconfig_file}")103 elif services[3]==1:104 os.system(f"sh scripts/k8s_ambassador_optional.sh eventhandler {kubeconfig_file}")105 update_text('Network configured.')106 os.system('sleep 1')107 update_text('')108 os.system('sleep 1')109 update_text('Deployment finished.')110 os.system('sleep 1')111 update_text('The ArrowHead Framework has been deployed.')112 113 # Buttons114 deploy = tk.Button(self, text='Deploy', command=deploy_cluster)115 close_app = tk.Button(self, text='Close App', command=lambda: self.master.master.destroy())116 # Arrange objects117 logo.grid(row=0,column=0, padx=(20,0), pady=20)118 subtitle.grid(row=0,column=1, padx=(10,20), pady=(20,20))119 updates.grid(row=1, columnspan=2, padx=(80,0), pady=(20,0))120 scroll.grid(row=1,columnspan=2, padx=(0,450), pady=(20,0), sticky=tk.NS)121 close_app.grid(row=2, column=0, padx=(10,30), pady=(30,10))...
notify_slack.py
Source:notify_slack.py
1#!/usr/bin/env python32# Copyright 2022 Google LLC3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import os15import slack16import logging17from get_firestore_tracked_cases import get_firestore_tracked_cases18logger = logging.getLogger(__name__)19def notify_slack(case, update_type, update_text):20 """21 Sends update messages to Slack.22 Parameters23 ----------24 case : str25 unique id of the case26 update_type : str27 specifies what was changed in the case28 update_text : str29 update relevant content that is injected into the Slack message30 """31 client = slack.WebClient(token=os.environ.get('SLACK_TOKEN'))32 tracked_cases = get_firestore_tracked_cases()33 for t in tracked_cases:34 if t['case'] == case:35 if update_type == 'comment':36 client.chat_postMessage(37 channel=t['channel_id'],38 text="You have an update from your support engineer on case"39 f" {case}: \n{update_text}")40 elif update_type == 'priority':41 client.chat_postMessage(42 channel=t['channel_id'],43 text=f"The priority of case {case} has been changed to {update_text}")44 elif update_type == 'closed':45 client.chat_postMessage(46 channel=t['channel_id'],47 text=f"Case {case} has been closed")48 elif update_type == 'escalated':49 client.chat_postMessage(50 channel=t['channel_id'],51 text=f"Case {case} has been escalated")52 elif update_type == 'de-escalated':53 client.chat_postMessage(54 channel=t['channel_id'],55 text=f"Case {case} has been de-escalated")56if __name__ == "__main__":57 case = os.environ.get('TEST_CASE')58 update_type = "comment"59 update_text = "This is a test comment that doesn't actually appear on the case."60 notify_slack(case, update_type, update_text)61 update_type = "priority"62 update_text = "Priority unchanged"63 notify_slack(case, update_type, update_text)64 update_type = "closed"65 notify_slack(case, update_type, update_text)66 update_type = "escalated"67 notify_slack(case, update_type, update_text)68 update_type = "de-escalated"...
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!!